[FFmpeg-cvslog] avconv: distinguish between -ss 0 and -ss not being used

Anton Khirnov git at videolan.org
Tue Aug 6 10:43:40 CEST 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Jun 15 09:35:10 2013 +0200| [56ee3f9de7b9f6090d599a27d33a392890a2f7b8] | committer: Anton Khirnov

avconv: distinguish between -ss 0 and -ss not being used

Using -ss 0 to drop frames with negative timestamps is a perfectly valid
use case.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=56ee3f9de7b9f6090d599a27d33a392890a2f7b8
---

 avconv.c        |   10 ++++++----
 avconv_filter.c |    4 ++--
 avconv_opt.c    |    8 +++++---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/avconv.c b/avconv.c
index 3157c96..adea0ad 100644
--- 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;
     }
diff --git a/avconv_filter.c b/avconv_filter.c
index 15c7def..0e27650 100644
--- a/avconv_filter.c
+++ b/avconv_filter.c
@@ -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);
     }
diff --git a/avconv_opt.c b/avconv_opt.c
index f96fece..c8d9176 100644
--- a/avconv_opt.c
+++ b/avconv_opt.c
@@ -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);



More information about the ffmpeg-cvslog mailing list