From: Carl Hetherington Date: Mon, 28 Sep 2015 13:19:25 +0000 (+0100) Subject: Discard audio that comes out of FFmpeg files before time 0. X-Git-Tag: v2.3.8~1 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=4c60c74890ee16333ecf3adb87e69fc49d9a304f Discard audio that comes out of FFmpeg files before time 0. --- diff --git a/ChangeLog b/ChangeLog index ac1eb7026..ad1626896 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2015-09-28 c.hetherington + * 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. diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 475418d3d..7923be59b 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -324,7 +324,7 @@ FFmpegDecoder::decode_audio_packet () } 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; @@ -333,7 +333,19 @@ FFmpegDecoder::decode_audio_packet () 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 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;