@@ -648,11 +648,19 @@ def has_ffmpeg():
648
648
ffmpeg_exists = rcode == 0
649
649
return ffmpeg_exists
650
650
651
+
652
+ def assert_ffmpeg_is_available ():
653
+ "Raise a RuntimeError if FFmpeg is not in the PATH"
654
+ if not has_ffmpeg ():
655
+ err = ("FFmpeg is not in the path and is needed for saving "
656
+ "movies. Install FFmpeg and try again. It can be "
657
+ "downlaoded from http://ffmpeg.org/download.html." )
658
+ raise RuntimeError (err )
659
+
651
660
requires_ffmpeg = np .testing .dec .skipif (not has_ffmpeg (), 'Requires FFmpeg' )
652
661
653
662
654
- def ffmpeg (dst , frame_path , framerate = 10 , codec = 'mpeg4' , opt = "" , inopt = "" ,
655
- outopt = "" ):
663
+ def ffmpeg (dst , frame_path , framerate = 25 , codec = 'mpeg4' ):
656
664
"""Run FFmpeg in a subprocess to convert an image sequence into a movie
657
665
658
666
Parameters
@@ -663,25 +671,17 @@ def ffmpeg(dst, frame_path, framerate=10, codec='mpeg4', opt="", inopt="",
663
671
frame_path : str
664
672
Path to the source frames (with a frame number field like '%04d').
665
673
framerate : float
666
- Framerate of the movie (frames per second).
674
+ Framerate of the movie (frames per second, default 25 ).
667
675
codec : str
668
676
Codec to use (default 'mpeg4').
669
- opt, inopt, outopt : str
670
- FFmpeg options, infile options and outfile options (e.g., "-o1 value
671
- -o2 value", see FFmpeg help for possible options).
672
677
673
678
Notes
674
679
-----
675
680
Requires FFmpeg to be in the path. FFmpeg can be downlaoded from `here
676
681
<http://ffmpeg.org/download.html>`_. Stdout and stderr are written to the
677
682
logger. If the movie file is not created, a RuntimeError is raised.
678
683
"""
679
- # make sure FFmpeg is available
680
- if not has_ffmpeg ():
681
- err = ("FFmpeg is not in the path and is needed for saving "
682
- "movies. Install FFmpeg and try again. It can be "
683
- "downlaoded from http://ffmpeg.org/download.html." )
684
- raise RuntimeError (err )
684
+ assert_ffmpeg_is_available ()
685
685
686
686
# find target path
687
687
dst = os .path .expanduser (dst )
@@ -699,20 +699,7 @@ def ffmpeg(dst, frame_path, framerate=10, codec='mpeg4', opt="", inopt="",
699
699
frame_dir , frame_fmt = os .path .split (frame_path )
700
700
701
701
# make the movie
702
- cmd = ['ffmpeg' ]
703
- if opt :
704
- cmd .extend (opt .split ())
705
- if inopt :
706
- cmd .extend (inopt .split ())
707
- cmd .extend (('-i' , frame_fmt ))
708
- if outopt :
709
- cmd .extend (outopt .split ())
710
- if '-r ' not in outopt :
711
- cmd .extend (('-r' , str (framerate )))
712
- if not ('-c' in cmd or '-codec' in cmd ):
713
- cmd .extend (('-c' , codec ))
714
- cmd .append (dst )
715
-
702
+ cmd = ['ffmpeg' , '-i' , frame_fmt , '-r' , str (framerate ), '-c' , codec , dst ]
716
703
logger .info ("Running FFmpeg with command: %s" , ' ' .join (cmd ))
717
704
sp = subprocess .Popen (cmd , cwd = frame_dir , stdout = subprocess .PIPE ,
718
705
stderr = subprocess .PIPE )
0 commit comments