Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Adding methods to wrap ffmpeg
  • Loading branch information
phooky committed Feb 13, 2011
1 parent 567703d commit c9a88b2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions raw_extract.py
@@ -0,0 +1,47 @@
#!/usr/bin/python
import os

# I'm lazy: from
# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def which(program):
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None

# find FFMPEG
try:
ffmpeg_name = os.environ['FFMPEG']
except KeyError:
ffmpeg_name = 'ffmpeg'
ffmpeg_path = which(ffmpeg_name)

if not ffmpeg_path:
raise("Could not find ffmpeg. Make sure it's installed, or try setting the FFMPEG environment variable.")

def extract_raw(path):
import subprocess
import tempfile
(handle,outpath) = tempfile.mkstemp(suffix='.raw')
os.close(handle)
args = [ffmpeg_path,'-i',path,'-vcodec','copy','-f','rawvideo','-an','-y',outpath]
retcode = subprocess.call(args)
return outpath

def encode_raw(in_path,out_path):
import subprocess
import tempfile
args = [ffmpeg_path,'-i',in_path,'-vcodec','copy','-y',out_path]
retcode = subprocess.call(args)
return out_path

0 comments on commit c9a88b2

Please sign in to comment.