FFmpegfs Fuse Multi Media Filesystem 2.16
vcdutils.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 Norbert Schlia (nschlia@oblivion-software.de)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
30#include "ffmpegfs.h"
31#include "vcd/vcdchapter.h"
32#include "vcdutils.h"
33#include "ffmpeg_utils.h"
34
35#include <cstring>
36#include <unistd.h>
37#include <sys/stat.h>
38
39namespace VCDUTILS
40{
41std::string convert_txt2string(const char * txt, int size, bool trimmed)
42{
43 std::unique_ptr<char[]> buffer = std::make_unique<char[]>(static_cast<size_t>(size + 1));
44 std::string ret_value;
45
46 if (buffer != nullptr)
47 {
48 std::memcpy(buffer.get(), txt, static_cast<size_t>(size));
49 *(buffer.get() + size) = '\0';
50
51 ret_value = buffer.get();
52 }
53
54 if (trimmed)
55 {
56 return trim(ret_value);
57 }
58 else
59 {
60 return ret_value;
61 }
62}
63
64bool locate_file(const std::string & path, const std::string & filename, std::string & fullname, bool & is_vcd)
65{
66 is_vcd = false;
67
68 // Try VCD
69 fullname = path + "VCD/" + filename + ".VCD";
70
71 if (!access(fullname.c_str(), F_OK))
72 {
73 return true;
74 }
75
76 // Try SVCD
77 fullname = path + "SVCD/" + filename + ".SVD";
78
79 if (!access(fullname.c_str(), F_OK))
80 {
81 is_vcd = true;
82 return true;
83 }
84
85 return false;
86}
87
88int locate_video(const std::string & path, int track_no, std::string & fullname)
89{
90 std::string buffer;
91
92 // Try VCD
93 strsprintf(&buffer, "MPEGAV/AVSEQ%02i.DAT", track_no - 1);
94 fullname = path + buffer;
95 if (!access(fullname.c_str(), F_OK))
96 {
97 return 0;
98 }
99
100 // Try SVCD
101 strsprintf(&buffer, "MPEG2/AVSEQ%02i.MPG", track_no - 1);
102 fullname = path + buffer;
103 if (!access(fullname.c_str(), F_OK))
104 {
105 return 0;
106 }
107
108 return ENOENT;
109}
110
111std::string get_type_str(VCDTYPE type)
112{
113 switch (type)
114 {
116 {
117 return "VCD 1.0, VCD 1.1, SVCD 1.0, HQVCD";
118 }
119
120 case VCDTYPE::VCD_20:
121 {
122 return "VCD 2.0";
123 }
124
125 default:
126 {
127 return "";
128 }
129 }
130}
131
133{
134 switch (tag)
135 {
137 {
138 return "VCD 1.0, VCD 2.0, SVCD, HQVCD";
139 }
141 {
142 return "VCD 1.1";
143 }
144 default:
145 {
146 return "";
147 }
148 }
149}
150
151void get_directory(const std::string & fullname, std::string *directory)
152{
153 struct stat stbuf;
154
155 stat(fullname.c_str(), &stbuf);
156
157 if (S_ISDIR(stbuf.st_mode))
158 {
159 // Already a directory
160 *directory = fullname;
161 append_sep(directory);
162 }
163
164 else
165 {
166 // Make it a directory
167 *directory = fullname;
168 remove_filename(directory);
169 }
170}
171}
std::string & trim(std::string &s)
trim from both ends
const std::string & remove_filename(std::string *filepath)
Remove filename from path. Handy dirname alternative.
const std::string & append_sep(std::string *path)
Add / to the path if required.
Various FFmpegfs utility functions.
const std::string & strsprintf(std::string *str, const std::string &format, Args ... args)
Format a std::string sprintf-like.
Definition: ffmpeg_utils.h:737
Main include for FFmpegfs project.
Video CD utility functions.
Definition: vcdutils.cc:40
bool locate_file(const std::string &path, const std::string &filename, std::string &fullname, bool &is_vcd)
Check if path is a S/VCD.
Definition: vcdutils.cc:64
int locate_video(const std::string &path, int track_no, std::string &fullname)
Locate AVSEQ*DAT/MPEG video file for track_no.
Definition: vcdutils.cc:88
std::string convert_txt2string(const char *txt, int size, bool trimmed)
Non-zero terminated text is converted to std::string.
Definition: vcdutils.cc:41
void get_directory(const std::string &fullname, std::string *directory)
Check if fullname is a directory. Remove the filename if necessary.
Definition: vcdutils.cc:151
std::string get_type_str(VCDTYPE type)
Return disk type as a human readable string.
Definition: vcdutils.cc:111
std::string get_profile_tag_str(VCDPROFILETAG tag)
Profile as a human readable string.
Definition: vcdutils.cc:132
S/VCD VcdChapter class.
VCDTYPE
Definition: vcdchapter.h:40
@ VCD_10_11_SVCD_10_HQVCD
VCD 1.0, VCD 1.1, SVCD 1.0 und HQVCD.
@ VCD_20
VCD 2.0.
VCDPROFILETAG
Definition: vcdchapter.h:50
@ VCD_10_20_SVCD_HQVCD
VCD 1.0, VCD 2.0, SVCD und HQVCD.
@ VCD_11
VCD 1.1.
S/VCD utility functions.