Skip to content

Commit 08d538a

Browse files
Remove FFMPEG wrappers
1 parent bbd681e commit 08d538a

File tree

1 file changed

+0
-97
lines changed

1 file changed

+0
-97
lines changed

surfer/utils.py

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from os import path as op
66
import inspect
77
from functools import wraps
8-
import subprocess
98

109
import numpy as np
1110
import nibabel as nib
@@ -626,99 +625,3 @@ def has_fsaverage(subjects_dir=None):
626625

627626
requires_fsaverage = np.testing.dec.skipif(not has_fsaverage(),
628627
'Requires fsaverage subject data')
629-
630-
631-
def has_ffmpeg():
632-
"""Test whether the FFmpeg is available in a subprocess
633-
634-
Returns
635-
-------
636-
ffmpeg_exists : bool
637-
True if FFmpeg can be successfully called, False otherwise.
638-
"""
639-
try:
640-
subprocess.call(["ffmpeg"], stdout=subprocess.PIPE,
641-
stderr=subprocess.PIPE)
642-
return True
643-
except OSError:
644-
return False
645-
646-
647-
def assert_ffmpeg_is_available():
648-
"Raise a RuntimeError if FFmpeg is not in the PATH"
649-
if not has_ffmpeg():
650-
err = ("FFmpeg is not in the path and is needed for saving "
651-
"movies. Install FFmpeg and try again. It can be "
652-
"downlaoded from http://ffmpeg.org/download.html.")
653-
raise RuntimeError(err)
654-
655-
requires_ffmpeg = np.testing.dec.skipif(not has_ffmpeg(), 'Requires FFmpeg')
656-
657-
658-
def ffmpeg(dst, frame_path, framerate=24, codec='mpeg4', bitrate='1M'):
659-
"""Run FFmpeg in a subprocess to convert an image sequence into a movie
660-
661-
Parameters
662-
----------
663-
dst : str
664-
Destination path. If the extension is not ".mov" or ".avi", ".mov" is
665-
added. If the file already exists it is overwritten.
666-
frame_path : str
667-
Path to the source frames (with a frame number field like '%04d').
668-
framerate : float
669-
Framerate of the movie (frames per second, default 24).
670-
codec : str | None
671-
Codec to use (default 'mpeg4'). If None, the codec argument is not
672-
forwarded to ffmpeg, which preserves compatibility with very old
673-
versions of ffmpeg
674-
bitrate : str | float
675-
Bitrate to use to encode movie. Can be specified as number (e.g.
676-
64000) or string (e.g. '64k'). Default value is 1M
677-
678-
Notes
679-
-----
680-
Requires FFmpeg to be in the path. FFmpeg can be downlaoded from `here
681-
<http://ffmpeg.org/download.html>`_. Stdout and stderr are written to the
682-
logger. If the movie file is not created, a RuntimeError is raised.
683-
"""
684-
assert_ffmpeg_is_available()
685-
686-
# find target path
687-
dst = os.path.expanduser(dst)
688-
dst = os.path.abspath(dst)
689-
root, ext = os.path.splitext(dst)
690-
dirname = os.path.dirname(dst)
691-
if ext not in ['.mov', '.avi']:
692-
dst += '.mov'
693-
694-
if os.path.exists(dst):
695-
os.remove(dst)
696-
elif not os.path.exists(dirname):
697-
os.mkdir(dirname)
698-
699-
frame_dir, frame_fmt = os.path.split(frame_path)
700-
701-
# make the movie
702-
cmd = ['ffmpeg', '-i', frame_fmt, '-r', str(framerate),
703-
'-b:v', str(bitrate)]
704-
if codec is not None:
705-
cmd += ['-c', codec]
706-
cmd += [dst]
707-
logger.info("Running FFmpeg with command: %s", ' '.join(cmd))
708-
sp = subprocess.Popen(cmd, cwd=frame_dir, stdout=subprocess.PIPE,
709-
stderr=subprocess.PIPE)
710-
711-
# log stdout and stderr
712-
stdout, stderr = sp.communicate()
713-
std_info = os.linesep.join(("FFmpeg stdout", '=' * 25, stdout))
714-
logger.info(std_info)
715-
if stderr.strip():
716-
err_info = os.linesep.join(("FFmpeg stderr", '=' * 27, stderr))
717-
# FFmpeg prints to stderr in the absence of an error
718-
logger.info(err_info)
719-
720-
# check that movie file is created
721-
if not os.path.exists(dst):
722-
err = ("FFmpeg failed, no file created; see log for more more "
723-
"information.")
724-
raise RuntimeError(err)

0 commit comments

Comments
 (0)