3
$\begingroup$

In the Documentation of Video (under Scope, 4th example) a Manipulation is combined with audio and exported as a file.mp4 video:

m=Manipulate[Plot[Sin[x],{x,0,2Pi},PlotStyle->Hue[h],ImageSize->Medium],{h,0,1},ControlType->None,Paneled->False];
a=ExampleData[{"Audio","Bird"}];
Duration[a]
Export["file.mp4",{"Animation"->m,"Audio"->a},"Rules"];
Video[%]

This example works as advertised. Clicking on the Video icon opens the file.mp4 and plays the video. (The file resides in the home directory.)

However, if one looks closely, one sees that the manipulate is played twice: first forwards, next backwards. While the audio is only played in the forwards section. The audio part is about 1.9 seconds; the video lasts about 4 seconds.

All my attempts to create a video with an audio track which lasts longer than say 2 seconds were defied: the Export crashes. For example, replace ExampleData[{"Audio","Bird"}] by ExampleData[{"Audio","Apollo11SmallStep"}] in the above example.

My aim is to synchronize an animation with audio and export the two as a video file. My question differs (in part) from this one, because I want to add audio.

Any suggestions? Thanks!

(I am using Version 12.1.1, under macOSX Mojave 10.14.6)

$\endgroup$
2
$\begingroup$

Export will work correctly when you use a different audio encoder:

Export["file.mp4", {"Animation" -> m, "Audio" -> a}, "Rules", AudioEncoding -> "AAC-HE-AVF"]

We will try to fix this issue in the next release, but I strongly encourage everyone to install a full version of FFmpeg: https://reference.wolfram.com/language/tutorial/ImportingAndExportingVideo.html#1156435029

You can check if system FFmpeg is used by calling:

In[1]:= Needs["FFmpegTools`"]

In[2]:= FFmpegTools`$SystemFFmpegQ

Out[2]= True
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank for your answer. However, I wanted to test my above Apollo11SmallStep example again, using a fresh start of MMA and without your AudioEncoding, and it did not crash anymore. Very strange, because I have had this problem for a long time. I had not installed FFmpegTools. Adding the AudioEncoding specification works too. $\endgroup$ – Romke Bontekoe Jun 27 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.