avconv: distinguish between -ss 0 and -ss not being used
authorAnton Khirnov <anton@khirnov.net>
Sat, 15 Jun 2013 07:35:10 +0000 (09:35 +0200)
committerAnton Khirnov <anton@khirnov.net>
Mon, 5 Aug 2013 08:53:12 +0000 (10:53 +0200)
Using -ss 0 to drop frames with negative timestamps is a perfectly valid
use case.

avconv.c
avconv_filter.c
avconv_opt.c

index 3157c96..adea0ad 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -652,10 +652,11 @@ static int poll_filter(OutputStream *ost)
         return ret;
 
     if (filtered_frame->pts != AV_NOPTS_VALUE) {
+        int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
         filtered_frame->pts = av_rescale_q(filtered_frame->pts,
                                            ost->filter->filter->inputs[0]->time_base,
                                            ost->st->codec->time_base) -
-                              av_rescale_q(of->start_time,
+                              av_rescale_q(start_time,
                                            AV_TIME_BASE_Q,
                                            ost->st->codec->time_base);
     }
@@ -948,7 +949,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
     if (ost->source_index != ist_index)
         return 0;
 
-    if (of->start_time && ist->last_dts < of->start_time)
+    if (of->start_time != AV_NOPTS_VALUE && ist->last_dts < of->start_time)
         return 0;
 
     return 1;
@@ -957,7 +958,8 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
 {
     OutputFile *of = output_files[ost->file_index];
-    int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);
+    int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
+    int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
     AVPacket opkt;
 
     av_init_packet(&opkt);
@@ -967,7 +969,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         return;
 
     if (of->recording_time != INT64_MAX &&
-        ist->last_dts >= of->recording_time + of->start_time) {
+        ist->last_dts >= of->recording_time + start_time) {
         ost->finished = 1;
         return;
     }
index 15c7def..0e27650 100644 (file)
@@ -183,7 +183,7 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa
     char filter_name[128];
     int ret = 0;
 
-    if (of->recording_time == INT64_MAX && !of->start_time)
+    if (of->recording_time == INT64_MAX && of->start_time == AV_NOPTS_VALUE)
         return 0;
 
     trim = avfilter_get_by_name(name);
@@ -203,7 +203,7 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa
         ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
                                 AV_OPT_SEARCH_CHILDREN);
     }
-    if (ret >= 0 && of->start_time) {
+    if (ret >= 0 && of->start_time != AV_NOPTS_VALUE) {
         ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,
                                 AV_OPT_SEARCH_CHILDREN);
     }
index f96fece..c8d9176 100644 (file)
@@ -113,6 +113,7 @@ static void init_options(OptionsContext *o)
     memset(o, 0, sizeof(*o));
 
     o->mux_max_delay  = 0.7;
+    o->start_time     = AV_NOPTS_VALUE;
     o->recording_time = INT64_MAX;
     o->limit_filesize = UINT64_MAX;
     o->chapters_input_file = INT_MAX;
@@ -658,13 +659,13 @@ static int open_input_file(OptionsContext *o, const char *filename)
         exit_program(1);
     }
 
-    timestamp = o->start_time;
+    timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
     /* add the stream start time */
     if (ic->start_time != AV_NOPTS_VALUE)
         timestamp += ic->start_time;
 
     /* if seeking requested, we execute it */
-    if (o->start_time != 0) {
+    if (o->start_time != AV_NOPTS_VALUE) {
         ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
         if (ret < 0) {
             av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
@@ -1212,7 +1213,8 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
 
     for (i = 0; i < is->nb_chapters; i++) {
         AVChapter *in_ch = is->chapters[i], *out_ch;
-        int64_t ts_off   = av_rescale_q(ofile->start_time - ifile->ts_offset,
+        int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
+        int64_t ts_off   = av_rescale_q(start_time - ifile->ts_offset,
                                        AV_TIME_BASE_Q, in_ch->time_base);
         int64_t rt       = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
                            av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);