* commit '56ee3f9de7b9f6090d599a27d33a392890a2f7b8':
avconv: distinguish between -ss 0 and -ss not being used
Conflicts:
ffmpeg.c
ffmpeg_opt.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -751,7 +751,9 @@ static void do_subtitle_out(AVFormatContext *s, |
751 | 751 |
nb = 1; |
752 | 752 |
|
753 | 753 |
/* shift timestamp to honor -ss and make check_recording_time() work with -t */ |
754 |
- pts = sub->pts - output_files[ost->file_index]->start_time; |
|
754 |
+ pts = sub->pts; |
|
755 |
+ if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE) |
|
756 |
+ pts -= output_files[ost->file_index]->start_time; |
|
755 | 757 |
for (i = 0; i < nb; i++) { |
756 | 758 |
ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base); |
757 | 759 |
if (!check_recording_time(ost)) |
... | ... |
@@ -1070,10 +1072,11 @@ static int reap_filters(void) |
1070 | 1070 |
} |
1071 | 1071 |
frame_pts = AV_NOPTS_VALUE; |
1072 | 1072 |
if (filtered_frame->pts != AV_NOPTS_VALUE) { |
1073 |
+ int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; |
|
1073 | 1074 |
filtered_frame->pts = frame_pts = av_rescale_q(filtered_frame->pts, |
1074 | 1075 |
ost->filter->filter->inputs[0]->time_base, |
1075 | 1076 |
ost->st->codec->time_base) - |
1076 |
- av_rescale_q(of->start_time, |
|
1077 |
+ av_rescale_q(start_time, |
|
1077 | 1078 |
AV_TIME_BASE_Q, |
1078 | 1079 |
ost->st->codec->time_base); |
1079 | 1080 |
} |
... | ... |
@@ -1377,7 +1380,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) |
1377 | 1377 |
if (ost->source_index != ist_index) |
1378 | 1378 |
return 0; |
1379 | 1379 |
|
1380 |
- if (of->start_time && ist->pts < of->start_time) |
|
1380 |
+ if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time) |
|
1381 | 1381 |
return 0; |
1382 | 1382 |
|
1383 | 1383 |
return 1; |
... | ... |
@@ -1386,8 +1389,9 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) |
1386 | 1386 |
static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) |
1387 | 1387 |
{ |
1388 | 1388 |
OutputFile *of = output_files[ost->file_index]; |
1389 |
- int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base); |
|
1390 |
- int64_t ist_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ist->st->time_base); |
|
1389 |
+ int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; |
|
1390 |
+ int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base); |
|
1391 |
+ int64_t ist_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base); |
|
1391 | 1392 |
AVPicture pict; |
1392 | 1393 |
AVPacket opkt; |
1393 | 1394 |
|
... | ... |
@@ -1398,7 +1402,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p |
1398 | 1398 |
return; |
1399 | 1399 |
|
1400 | 1400 |
if (pkt->pts == AV_NOPTS_VALUE) { |
1401 |
- if (!ost->frame_number && ist->pts < of->start_time && |
|
1401 |
+ if (!ost->frame_number && ist->pts < start_time && |
|
1402 | 1402 |
!ost->copy_prior_start) |
1403 | 1403 |
return; |
1404 | 1404 |
} else { |
... | ... |
@@ -1408,7 +1412,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p |
1408 | 1408 |
} |
1409 | 1409 |
|
1410 | 1410 |
if (of->recording_time != INT64_MAX && |
1411 |
- ist->pts >= of->recording_time + of->start_time) { |
|
1411 |
+ ist->pts >= of->recording_time + start_time) { |
|
1412 | 1412 |
close_output_stream(ost); |
1413 | 1413 |
return; |
1414 | 1414 |
} |
... | ... |
@@ -286,11 +286,11 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa |
286 | 286 |
char filter_name[128]; |
287 | 287 |
int ret = 0; |
288 | 288 |
|
289 |
- if (of->recording_time == INT64_MAX && !of->start_time) |
|
289 |
+ if (of->recording_time == INT64_MAX && of->start_time == AV_NOPTS_VALUE) |
|
290 | 290 |
return 0; |
291 | 291 |
|
292 | 292 |
// Use with duration and without output starttime is buggy with trim filters |
293 |
- if (!of->start_time) |
|
293 |
+ if (of->start_time == AV_NOPTS_VALUE) |
|
294 | 294 |
return 0; |
295 | 295 |
|
296 | 296 |
trim = avfilter_get_by_name(name); |
... | ... |
@@ -310,7 +310,7 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa |
310 | 310 |
ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6, |
311 | 311 |
AV_OPT_SEARCH_CHILDREN); |
312 | 312 |
} |
313 |
- if (ret >= 0 && of->start_time) { |
|
313 |
+ if (ret >= 0 && of->start_time != AV_NOPTS_VALUE) { |
|
314 | 314 |
ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6, |
315 | 315 |
AV_OPT_SEARCH_CHILDREN); |
316 | 316 |
} |
... | ... |
@@ -147,6 +147,7 @@ static void init_options(OptionsContext *o, int is_input) |
147 | 147 |
o->recording_time = INT64_MAX; |
148 | 148 |
o->stop_time = INT64_MAX; |
149 | 149 |
o->mux_max_delay = 0.7; |
150 |
+ o->start_time = AV_NOPTS_VALUE; |
|
150 | 151 |
o->limit_filesize = UINT64_MAX; |
151 | 152 |
o->chapters_input_file = INT_MAX; |
152 | 153 |
} |
... | ... |
@@ -824,13 +825,13 @@ static int open_input_file(OptionsContext *o, const char *filename) |
824 | 824 |
exit_program(1); |
825 | 825 |
} |
826 | 826 |
|
827 |
- timestamp = o->start_time; |
|
827 |
+ timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time; |
|
828 | 828 |
/* add the stream start time */ |
829 | 829 |
if (ic->start_time != AV_NOPTS_VALUE) |
830 | 830 |
timestamp += ic->start_time; |
831 | 831 |
|
832 | 832 |
/* if seeking requested, we execute it */ |
833 |
- if (o->start_time != 0) { |
|
833 |
+ if (o->start_time != AV_NOPTS_VALUE) { |
|
834 | 834 |
ret = avformat_seek_file(ic, -1, INT64_MIN, timestamp, timestamp, 0); |
835 | 835 |
if (ret < 0) { |
836 | 836 |
av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n", |
... | ... |
@@ -1451,7 +1452,8 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) |
1451 | 1451 |
|
1452 | 1452 |
for (i = 0; i < is->nb_chapters; i++) { |
1453 | 1453 |
AVChapter *in_ch = is->chapters[i], *out_ch; |
1454 |
- int64_t ts_off = av_rescale_q(ofile->start_time - ifile->ts_offset, |
|
1454 |
+ int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time; |
|
1455 |
+ int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset, |
|
1455 | 1456 |
AV_TIME_BASE_Q, in_ch->time_base); |
1456 | 1457 |
int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX : |
1457 | 1458 |
av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base); |
... | ... |
@@ -1586,11 +1588,12 @@ static int open_output_file(OptionsContext *o, const char *filename) |
1586 | 1586 |
} |
1587 | 1587 |
|
1588 | 1588 |
if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { |
1589 |
- if (o->stop_time <= o->start_time) { |
|
1589 |
+ int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; |
|
1590 |
+ if (o->stop_time <= start_time) { |
|
1590 | 1591 |
av_log(NULL, AV_LOG_WARNING, "-to value smaller than -ss; ignoring -to.\n"); |
1591 | 1592 |
o->stop_time = INT64_MAX; |
1592 | 1593 |
} else { |
1593 |
- o->recording_time = o->stop_time - o->start_time; |
|
1594 |
+ o->recording_time = o->stop_time - start_time; |
|
1594 | 1595 |
} |
1595 | 1596 |
} |
1596 | 1597 |
|