Browse code

avconv: make output -ss insert trim/atrim filters.

This makes output -ss sample-accurate for audio and will allow further
simplication in the future.

Anton Khirnov authored on 2013/04/10 22:02:01
Showing 3 changed files
... ...
@@ -14,7 +14,8 @@ version 10:
14 14
 - JPEG 2000 decoder
15 15
 - new asetpts filter (same as setpts, but for audio)
16 16
 - new trim and atrim filters
17
-- avconv -t option is now sample-accurate when transcoding audio
17
+- avconv -t and -ss (output-only) options are now sample-accurate when
18
+  transcoding audio
18 19
 
19 20
 
20 21
 version 9:
... ...
@@ -681,11 +681,6 @@ static int poll_filter(OutputStream *ost)
681 681
                               av_rescale_q(of->start_time,
682 682
                                            AV_TIME_BASE_Q,
683 683
                                            ost->st->codec->time_base);
684
-
685
-        if (of->start_time && filtered_frame->pts < 0) {
686
-            av_frame_unref(filtered_frame);
687
-            return 0;
688
-        }
689 684
     }
690 685
 
691 686
     switch (ost->filter->filter->inputs[0]->type) {
... ...
@@ -183,7 +183,7 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa
183 183
     char filter_name[128];
184 184
     int ret = 0;
185 185
 
186
-    if (of->recording_time == INT64_MAX)
186
+    if (of->recording_time == INT64_MAX && !of->start_time)
187 187
         return 0;
188 188
 
189 189
     trim = avfilter_get_by_name(name);
... ...
@@ -199,8 +199,14 @@ static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pa
199 199
     if (!ctx)
200 200
         return AVERROR(ENOMEM);
201 201
 
202
-    ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
203
-                            AV_OPT_SEARCH_CHILDREN);
202
+    if (of->recording_time != INT64_MAX) {
203
+        ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
204
+                                AV_OPT_SEARCH_CHILDREN);
205
+    }
206
+    if (ret >= 0 && of->start_time) {
207
+        ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,
208
+                                AV_OPT_SEARCH_CHILDREN);
209
+    }
204 210
     if (ret < 0) {
205 211
         av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);
206 212
         return ret;