Last active
March 6, 2017 01:11
-
-
Save i-namekawa/a24709d92f890b541bb4 to your computer and use it in GitHub Desktop.
multiprocessing ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing, os, Queue, subprocess, sys | |
from time import sleep | |
class Worker(multiprocessing.Process): | |
'''http://jeetworks.org/node/81 modified example in the comments''' | |
def __init__(self, work_queue): | |
# base class initialization | |
multiprocessing.Process.__init__(self) | |
# job management stuff | |
self.work_queue = work_queue | |
self.kill_received = False | |
def run(self): | |
while not self.kill_received: | |
# fetching a new task | |
try: | |
n_job, fp = self.work_queue.get_nowait() | |
except Queue.Empty: | |
break | |
# the actual processing | |
print("Starting " + str(n_job) + " ... " + fp) | |
cmd = ( | |
r"C:\hg\cam_iface\ffmpeg.exe", # path to your ffmpeg here | |
'-an', # ignore audio | |
'-analyzeduration', '0', # skip auto codec analysis | |
'-y', # overwrite output file if exists | |
'-i', fp, | |
'-vf', 'setpts=PTS/3.0', # speed up fps x3 | |
'-r', '30', # i want video rate | |
'-qscale', '5', # video quality rather high | |
fp[:-4] + '_30fps.avi' | |
) | |
p = subprocess.Popen(cmd) | |
stdoutdata, stderrdata = p.communicate() # this makes the process wait till done | |
print 'done!' | |
if __name__ == "__main__": | |
' drop files to this .py file to transcode them' | |
work_queue = multiprocessing.Queue() | |
for n, fp in enumerate(sys.argv[1:]): | |
work_queue.put( (n, fp) ) | |
for i in range( multiprocessing.cpu_count() ): | |
worker = Worker(work_queue) | |
worker.start() | |
sleep(10) # handy to have this here for debugging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment