Skip to content

Instantly share code, notes, and snippets.

@330k
Last active January 4, 2016 13:50
Show Gist options
  • Save 330k/8434fc8ac542fdd87902 to your computer and use it in GitHub Desktop.
Save 330k/8434fc8ac542fdd87902 to your computer and use it in GitHub Desktop.
Mathematica Function for Movie Creation with ffmpeg/avconv
(*
Mathematica Function for Movie Creation with ffmpeg/avconv
This function enables Mathematica make a long movie file
with less memory usage.
Copyright (c) 2015 330k
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*)
Options[ExportMovie] = {
"FrameRate" -> 25,
"VideoCodecOption" -> "-vcodec rawvideo",
"ExportOptions" -> {}
};
ExportMovie[outputfilepath_String,
expr_, {i_Symbol, imin_: 1, imax_, di_: 1}, OptionsPattern[]] :=
Module[{stream},
stream = OpenWrite[
ToString[
StringForm[
"!avconv -y -vcodec ppm -f image2pipe -i - -r `` `` ``"
, OptionValue["FrameRate"]
, OptionValue["VideoCodecOption"]
, outputfilepath
]
]
, BinaryFormat -> True];
Do[
BinaryWrite[stream,
ExportString[expr, "PPM", OptionValue["ExportOptions"]]]
, {i, imin, imax, di}
];
Close[stream]
];
Attributes[ExportMovie] = {HoldAll};
SyntaxInformation[ExportMovie] = {
"ArgumentsPattern" -> {_, _, {_, _, _., _.}, OptionsPattern[]}
, "LocalVariables" -> {"Table", {3, 3}}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment