diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-28 14:19:25 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-28 14:19:25 +0100 |
| commit | 4c60c74890ee16333ecf3adb87e69fc49d9a304f (patch) | |
| tree | fe614932d6a2031d95e3d5f0a982e0ff3954efa2 | |
| parent | 84b50d26c24222ad3f936590f5d706e58ac24922 (diff) | |
Discard audio that comes out of FFmpeg files before time 0.
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 16 |
2 files changed, 17 insertions, 2 deletions
@@ -1,5 +1,8 @@ 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. 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<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; |
