Discard audio that comes out of FFmpeg files before time 0.
authorCarl Hetherington <cth@carlh.net>
Mon, 28 Sep 2015 13:19:25 +0000 (14:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 28 Sep 2015 13:19:25 +0000 (14:19 +0100)
ChangeLog
src/lib/ffmpeg_decoder.cc

index ac1eb70267f7d88abf0f3b8d6bc079bb677d4bb0..ad1626896c19a0575d02537c2ffb92074b9caeff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-09-28  c.hetherington  <cth@carlh.net>
 
 2015-09-28  c.hetherington  <cth@carlh.net>
 
+       * Fix problems with audio analysis of some combined
+       video/audio files.
+
        * Fix mis-identification of a folder of images
        as a DCP in some cases.
 
        * Fix mis-identification of a folder of images
        as a DCP in some cases.
 
index 475418d3d2be34f9d30a65b7cfcfcce5e3089f69..7923be59bb6c3e696ee372135cc39e512c3c4dbd 100644 (file)
@@ -324,7 +324,7 @@ FFmpegDecoder::decode_audio_packet ()
                }
 
                if (frame_finished) {
                }
 
                if (frame_finished) {
-                       ContentTime const ct = ContentTime::from_seconds (
+                       ContentTime ct = ContentTime::from_seconds (
                                av_frame_get_best_effort_timestamp (_frame) *
                                av_q2d ((*stream)->stream (_format_context)->time_base))
                                + _pts_offset;
                                av_frame_get_best_effort_timestamp (_frame) *
                                av_q2d ((*stream)->stream (_format_context)->time_base))
                                + _pts_offset;
@@ -333,7 +333,19 @@ FFmpegDecoder::decode_audio_packet ()
                                0, (*stream)->stream(_format_context)->codec->channels, _frame->nb_samples, audio_sample_format (*stream), 1
                                );
 
                                0, (*stream)->stream(_format_context)->codec->channels, _frame->nb_samples, audio_sample_format (*stream), 1
                                );
 
-                       audio (*stream, deinterleave_audio (*stream, _frame->data, data_size), ct);
+                       shared_ptr<AudioBuffers> data = deinterleave_audio (*stream, _frame->data, data_size);
+
+                       if (ct < ContentTime ()) {
+                               /* Discard audio data that comes before time 0 */
+                               Frame const remove = min (int64_t (data->frames()), -ct.frames_round ((*stream)->frame_rate ()));
+                               data->move (remove, 0, data->frames() - remove);
+                               data->set_frames (data->frames() - remove);
+                               ct += ContentTime::from_frames (remove, (*stream)->frame_rate ());
+                       }
+
+                       if (data->frames() > 0) {
+                               audio (*stream, data, ct);
+                       }
                }
 
                copy_packet.data += decode_result;
                }
 
                copy_packet.data += decode_result;