diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 1ac9ac8a..068fb705 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -652,9 +652,6 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int // Allocate audio buffer int16_t *audio_buf = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; - // create a new array (to hold the re-sampled audio) - int16_t *converted_audio = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; - int packet_samples = 0; while (my_packet->size > 0) { // re-initialize buffer size (it gets changed in the avcodec_decode_audio2 method call) @@ -684,10 +681,17 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int - #pragma omp task firstprivate(requested_frame, target_frame, my_cache, starting_sample, audio_buf, converted_audio) + #pragma omp task firstprivate(requested_frame, target_frame, my_cache, starting_sample, audio_buf) { + + // create a new array (to hold the re-sampled audio) + int16_t *converted_audio = NULL; + // Re-sample audio samples (if needed) if(aCodecCtx->sample_fmt != AV_SAMPLE_FMT_S16) { + // Init resample buffer + converted_audio = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; + // Audio needs to be converted // Create an audio resample context object (used to convert audio samples) ReSampleContext *resampleCtx = av_audio_resample_init( @@ -709,6 +713,10 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int // Copy audio samples over original samples memcpy(audio_buf, converted_audio, packet_samples * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)); + // Deallocate resample buffer + delete[] converted_audio; + converted_audio = NULL; + // Close context audio_resample_close(resampleCtx); } @@ -805,8 +813,6 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int // Clean up some arrays delete[] audio_buf; audio_buf = NULL; - delete[] converted_audio; - converted_audio = NULL; // Add video frame to list of processing video frames #pragma omp critical (processing_list) diff --git a/src/Main.cpp b/src/Main.cpp index 726a87b4..ab3e0ebc 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -21,10 +21,10 @@ int main() // openshot::FFmpegReader r("/home/jonathan/Videos/big-buck-bunny_trailer.webm"); // openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); - openshot::FFmpegReader r("/home/jonathan/Videos/OpenShot_Now_In_3d.mp4"); + // openshot::FFmpegReader r("/home/jonathan/Videos/OpenShot_Now_In_3d.mp4"); // openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/piano.wav"); - // openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3"); + openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3"); // openshot::FFmpegReader r("/home/jonathan/Documents/OpenShot Art/test.jpeg"); // openshot::FFmpegReader r("/home/jonathan/Videos/60fps.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/asdf.wdf");