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
POSTED BY: Arno Bosse

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

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