Fix quicktime video export not properly supporting animation of audio properties...
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 4 May 2013 13:17:43 +0000 (13:17 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 4 May 2013 13:17:43 +0000 (13:17 +0000)
Patch #35184 by James Yonan, see the report for a detailed explanation of why this failed.

source/blender/quicktime/apple/qtkit_export.m

index c22544d1891530744ef90042a1f1cc4d8cc2b7b8..b23c768545cfcee8e09e483d4253a75c6573680f 100644 (file)
@@ -648,14 +648,24 @@ int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, in
        
        if (qtexport->audioFile) {
                UInt32 audioPacketsConverted;
+
+               // Upper limit on total exported audio frames for this particular video frame
+               const UInt64 exportedAudioFrameLimit = (frame - rd->sfra) * qtexport->audioInputFormat.mSampleRate * rd->frs_sec_base / rd->frs_sec;
+
                /* Append audio */
-               while (qtexport->audioTotalExportedFrames < qtexport->audioLastFrame) {
+               while (qtexport->audioTotalExportedFrames < exportedAudioFrameLimit) {
 
                        qtexport->audioBufferList.mNumberBuffers = 1;
                        qtexport->audioBufferList.mBuffers[0].mNumberChannels = qtexport->audioOutputFormat.mChannelsPerFrame;
                        qtexport->audioBufferList.mBuffers[0].mDataByteSize = AUDIOOUTPUTBUFFERSIZE;
                        qtexport->audioBufferList.mBuffers[0].mData = qtexport->audioOutputBuffer;
-                       audioPacketsConverted = AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize;
+
+                       // Convert one audio packet at a time so that enclosing while loop can
+                       // keep audio processing in sync with video frames.
+                       // Previously, this was set to (AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize),
+                       // however this may cause AudioConverterFillComplexBuffer to convert audio spanning multiple
+                       // video frames, which breaks animation of audio parameters such as volume for fade-in/out.
+                       audioPacketsConverted = 1; 
                        
                        err = AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback,
                                                              NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc);