Skip to content

Instantly share code, notes, and snippets.

@djds23
Last active August 29, 2015 14:02
Show Gist options
  • Save djds23/e9469f3762068192416f to your computer and use it in GitHub Desktop.
Save djds23/e9469f3762068192416f to your computer and use it in GitHub Desktop.
Sift through MPEG transport footage from prosumer cameras and convert to 1/10th the size for playback
import os
from subprocess import call
root = "."
def crawl_folder(root):
'''crawl filesystem and apply encoding function'''
root = os.walk(root) #walk filesystem, return tuples
for root, dirs, files in root: #for each tuple, check for streamers dict, create dict and encode
for filename in files:
if '.MTS' in filename:
os.mkdir(root + '/streamers')
os.chdir(root)
map(encode, files) #map encode over each dict of files
break
def encode(contents):
if '.mts' in contents.lower(): #check to see if MPEG transit stream
new_name = contents[:-4]+'_streamer.mp4'
command = "ffmpeg -v verbose -i "+ contents +" -acodec copy -vf 'field, scale=iw/2:ih, setsar=1' -vcodec libx264 -g 60 -crf 30 -threads 8 -preset slow -y streamers/" + new_name
call(command, shell=True) #calll ffmpeg and place new file in new dict
#Beware files only play in VLC
if __name__=='__main__':
crawl_folder(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment