1 /*
2 * Copyright (c) 2012 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
27
33
34 typedef struct {
43
45 {
46 return memcmp(probe->
buf,
"ffconcat version 1.0", 20) ?
48 }
49
51 {
54 if (**cursor) {
55 *((*cursor)++) = 0;
57 }
59 }
60
62 {
63 const char *
start = f;
64
65 for (; *f; f++) {
66 /* A-Za-z0-9_- */
67 if (!((unsigned)((*f | 32) - 'a') < 26 ||
68 (unsigned)(*f - '0') < 10 || *f == '_' || *f == '-')) {
69 if (f == start)
70 return 0;
71 else if (*f == '/')
72 start = f + 1;
73 else if (*f != '.')
74 return 0;
75 }
76 }
77 return 1;
78 }
79
80 #define FAIL(retcode) do { ret = (retcode); goto fail; } while(0)
81
83 unsigned *nb_files_alloc)
84 {
87 char *url = NULL;
88 size_t url_len;
90
94 }
95 url_len = strlen(avf->
filename) + strlen(filename) + 16;
100
101 if (cat->
nb_files >= *nb_files_alloc) {
102 size_t n =
FFMAX(*nb_files_alloc * 2, 16);
104 if (n <= cat->nb_files || n > SIZE_MAX /
sizeof(*cat->
files) ||
107 cat->
files = new_files;
109 }
110
112 memset(file, 0, sizeof(*file));
113 *rfile = file;
114
118
119 return 0;
120
121 fail:
125 }
126
128 {
132
139 }
145 return 0;
146 }
147
149 {
151 unsigned i;
152
158 return 0;
159 }
160
162 {
167 unsigned nb_files_alloc = 0;
170 int64_t time = 0;
171
172 while (1) {
174 break;
175 line++;
178 if (!*keyword || *keyword == '#')
179 continue;
180
181 if (!strcmp(keyword, "file")) {
183 if (!filename) {
186 }
187 if ((ret =
add_file(avf, filename, &file, &nb_files_alloc)) < 0)
189 } else if (!strcmp(keyword, "duration")) {
191 int64_t dur;
192 if (!file) {
194 line);
196 }
199 line, dur_str);
201 }
203 } else if (!strcmp(keyword, "ffconcat")) {
206 if (strcmp(ver_kw, "version") || strcmp(ver_val, "1.0")) {
209 }
212 } else {
214 line, keyword);
216 }
217 }
218 if (ret < 0)
222
223 for (i = 0; i < cat->
nb_files; i++) {
226 else
229 break;
231 }
235 }
236
249 }
250
251 return 0;
252
253 fail:
256 }
257
259 {
262
265
269 }
270
272 {
276
277 while (1) {
280 break;
281 }
290 }
291
293 int64_t *min_ts, int64_t *ts, int64_t *max_ts)
294 {
300 }
301
303 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
304 {
307
309 min_ts = min_ts == INT64_MIN ? INT64_MIN : min_ts -
t0;
310 max_ts = max_ts == INT64_MAX ? INT64_MAX : max_ts -
t0;
311 if (stream >= 0) {
315 &min_ts, &ts, &max_ts);
316 }
318 }
319
321 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
322 {
324 int ret, left, right;
325
326 if (stream >= 0) {
330 &min_ts, &ts, &max_ts);
331 }
332
333 left = 0;
335 while (right - left > 1) {
336 int mid = (left + right) / 2;
338 right = mid;
339 else
340 left = mid;
341 }
342
344 return ret;
345
346 ret =
try_seek(avf, stream, min_ts, ts, max_ts, flags);
347 if (ret < 0 &&
348 left < cat->nb_files - 1 &&
350 if ((ret =
open_file(avf, left + 1)) < 0)
352 ret =
try_seek(avf, stream, min_ts, ts, max_ts, flags);
353 }
355 }
356
358 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
359 {
364
366 return AVERROR(ESPIPE);
/* XXX: can we use it? */
370 if ((ret =
real_seek(avf, stream, min_ts, ts, max_ts, flags)) < 0) {
373 cat->
avf = cur_avf_saved;
375 } else {
377 }
379 }
380
381 #define OFFSET(x) offsetof(ConcatContext, x)
382 #define DEC AV_OPT_FLAG_DECODING_PARAM
383
385 { "safe", "enable safe mode",
387 { NULL }
388 };
389
395 };
396
397
407 .priv_class = &concat_class,
408 };