Message Boards Message Boards

Properly export a video?

Posted 7 years ago

Hi all,

I am interested in the capturing the dynamics of a 3d vector like the ones presented here: https://journals.aps.org/prb/supplemental/10.1103/PhysRevB.91.064423

The video is generated using Mathematica in Mac OS. I am using the same code for plotting my graphs. It works perfectly in Mathematica. But when I export it as a .mov/.avi file, it behaves weirdly (My video is attached). I am plotting the dynamics of a vector in 3d space. I found two issues:

Problems: 1. It rotates very quickly. 2. It switches from one position to another and then again comes back to the original place. Both of these problems were not present in Mathematica. Only when I am going to export it any video format, exported video behaves incorrectly. I am using 11.2 version of the software on Windows. In summary, my question is why I am unable to record the exact video that is displayed in Mathematica itself?

I'll greatly appreciate any reply.

Best,

Attachments:
POSTED BY: Abir Shadman
9 Replies

To anyone arriving here at this old post, it is now in 2024 all massively easier with AnimationVideo, which as of in Mathematica (Wolfram) v14.1 is still marked as EXPERIMENTAL. I use it to create very high resolution high quality videos, if only quite short ones. It takes some patience, and one needs to explore all the options carefully, including the RenderingOptions in your Graphics, Graphics3D or Show, but it is possible to get excellent results.

Render time of course depends on your machine and the complexity and nature of your scene. (I also use a Once caching trick for very complex 3D animated scenes with lots of objects, which greatly reduces the render time but impacts memory.)

For long scenes I test them in Animate first with fewer frames and lower render/image size. I have a frame generator function that can be shared by Animate and AnimationVideo. Once I'm happy with it in Animate, I let AnimationVideo crank away on it. Care also has to be taken during the Export to use compatible options.

I also do not use Duration (the estimation of which is AFAICT not always 100% accurate); I use FrameRate and drive in specific parameter steps.

During quick tests I use "3DRenderingMethod" Automatic, but for final render I mostly use "BSPTree", which prevents Z-shadowing artifacts but is much slower. On my M1 Max MacBookPro I find "Metal" faster than "Mesa" for "3DRenderingEngine", with very similar results.

Related: SlideShowVideo, FrameListVideo

POSTED BY: Darren Kelly
Posted 7 years ago

Here is the frame version of video saved as .mov. You can change step size of Table in this case 30. If you want fast movie, increase stepsize.

video = Table[
   Graphics3D[ {{GrayLevel[.7], Line[space[[1 ;; t]]]}, {Red, 
      Arrowheads[.07], Arrow[Tube[{{0, 0, 0}, space[[t]]}, 0.01]]}}, 
    Axes -> True, 
    AxesStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],
     AxesLabel -> {"x", "y", "z"}, BoxRatios -> {1, 1, 1}, 
    ImageSize -> 400, PlotRange -> 1, SphericalRegion -> True, 
    Boxed -> False, ViewPoint -> {0, -2, 1}], {t, 1, Length@data, 30}];

Export["test.mov", video]
Attachments:
POSTED BY: Okkes Dulgerci

In preparing a bug report to WR I exported the video to AVI again and now don't see the rendering artifacts. I know I did earlier, but I can't recall the parameters which produced them anymore.

POSTED BY: Arno Bosse

Hi Abir,

Your attached "My_vdo.mov" has some other issues apart from the animation playback rate. About half a dozen frames in it are not rendered properly which results in a distracting 'flashing' experience. When I export the animation to QuickTime OSX (MMA v11.3) I don't see these problems. But if I export it as an AVI file I see the exact same issues on OSX. That suggests a bug in how MMA creates AVI files on both platforms. The way to work around that is to specify a different video codec:

Export["test.mov", %, "VideoEncoding" -> "MPEG-4 Video"]

As an aside, if you just export the animation to QuickTime on either platform without further parameters, MMA still defaults to using the long deprecated Apple Cinepak codec. By now that's a bug.

Neil mentioned that Export doesn't support the animation duration option. And it's true that if you look for it in the current documentation for Export, it's not listed there (another aside: why doesn't every function document all of its options?). But if you look-up "AnimationDuration" you'll see that it is briefly mentioned as an option for FLV and SWF though not for AVI or QT. Regardless, it is still possible to set this as an option for Export for QT and AVI as well, with values in seconds. You can now use this together with a reduced frame rate as a quick and dirty way to 'stretch out' your animation a little:

Export["test.mov", %, "VideoEncoding" -> "MPEG-4 Video", "AnimationDuration" -> 20, "FrameRate" -> 10]

However, I'm sure Neil's solution will be the better one. George also mentioned exporting the animation as a sequence of image files using "VideoFrames" and then employing an external tool like ffmpeg to turn these into a video again. In theory, this should be possible by exporting it as an animated GIF as well using the "DisplayDurations" option, but in my quick experiments, this didn't affect the overall duration or the perceived playing rate of the animation.

POSTED BY: Arno Bosse

You might like to generate each frame individually, export them as jpeg or tiff, and then import the set into a suitable third-party app. That way, you have total control.

Abir,

I asked this as a question to Tech Support a year ago and they gave me a better explanation of the issue. I found the old email and this may help you:

I understand Export function seems to ignore the duration option in Animate function.  In Mathematica, Animate[expr, {u, umin, umax}] function does not generate frames in Kernel. Instead, the Mathematica frontend will generate the frames but other functions, like Export[], cannot use these frames. When Export takes Animate as input, it will generate frames for 4 seconds and export it. If you need to specify the duration of the exported, please manually generate all the frames, like:

In[62]:= time = 10; fps = 24; da = 0.1; a0 = da;
In[63]:= frames = Table[Plot[Sin[a x], {x, -Pi, Pi}, PlotRange -> {-Pi, Pi}], {a, a0, 0.1*time*fps, da}];
In[64]:= Export["test.mov", frames, "FrameRate" -> fps]
Out[64]= "test.mov"

Meanwhile, I understand it will be better if function Export can read the "Duration" option when the input is Animate and works as you expected. Therefore, I filed a suggestion to the development team, raising this idea to them. Thank you again for bringing this question to us and help us improving Mathematica.

POSTED BY: Neil Singer

Abir,

The easiest way to do this is to get what you want in Mathematica and record the screen with a third party screen capture program. The results are far better than Export. Export is not really controllable for animations as far as I can tell.

Regards,

Neil

POSTED BY: Neil Singer
Posted 7 years ago

Hi Mikayel,

Thanks for replying. I am using the version 11.2 on Windows as I stated earlier. I have attached the video to the previous message also (named as My_vdo). The code is:

alvar = Flatten[ Import["C:\\Users\\Abir\\Documents\\code\\forplot.mat"]];
mx = Take[alvar, {1, Length[alvar]/4}];
my = Take[alvar, {Length[alvar]/4 + 1, Length[alvar]/2}];
mz = Take[alvar, {Length[alvar]/2 + 1, Length[alvar]/4 * 3}];
time = Take[alvar, {Length[alvar]/4* 3 + 1, Length[alvar]}];
mmm = Thread[{mx, my, mz}];
data = Thread[{time, mx, my, mz}];
space = data[[All, 2 ;; 4]];

Manipulate[

 Graphics3D[
  Dynamic@{{GrayLevel[.7], Line[space[[1 ;; t]]]}, {Red, Arrowheads[.07], Arrow[Tube[{{0, 0, 0}, space[[t]]}, 0.01]]}}, 
  Axes -> True, AxesStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"], 
  AxesLabel -> {"x", "y", "z"}, BoxRatios -> {1, 1, 1}, 
  ImageSize -> 400, PlotRange -> 1, SphericalRegion -> True, 
  Boxed -> False, ViewPoint -> {0, -2, 1}],

 Row[{Control[{t, 1, Length[data], 1, Animator, ImageSize -> Small, 
     AnimationRunning -> True, AnimationRepetitions -> 1, 
     AnimationRate -> 500}], Spacer[10], 
   Dynamic["second"       data[[t, 1]]]}]
 ]

Export["test.mov", %]

This code takes a .mat file (forplot.mat) as input. The mat file is also attached. It has data for three axes and time.

I'll look forward to you or any other person's reply in this regard. I'll much appreciate that.

Best,

Abir

Attachments:
POSTED BY: Abir Shadman

Hi Abir,

It will help if you post the code you used for generating the manipulate and the video as well. Also, which version of Mathematica are you using?

Mikayel

POSTED BY: Mikayel Egibyan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract