4 Classes derived from BaseTranscoder and BaseThumbExtractor for transcoding of
5 videos and thumbnail extraction from videos using FFmpeg CLI program.
13 class FFmpegTranscoder(base.BaseTranscoder):
15 FFmpeg CLI API for video transcoding.
20 log_file = 'log/ffmpeg.log'
36 "theora": "libtheora",
40 def _transcode(self, container, a_codec=None, v_codec=None,
41 a_bitrate=None, a_samplingrate=None, a_channels=None,
42 v_bitrate=None, v_framerate=None, v_resolution=None, v_dar=None):
44 args = self.prog_bin + ' -i "' + self.input_file + '" -f ' + container
48 args += ' -acodec ' + a_codec
50 args += ' -ab ' + str(a_bitrate)
51 if a_samplingrate != None:
52 args += ' -ar ' + str(a_samplingrate)
53 if a_channels != None:
54 args += ' -ac ' + str(a_channels)
58 args += ' -vcodec ' + v_codec
59 # Video codec specific options.
60 if v_codec == 'libx264':
61 args += ' -vpre normal'
63 args += ' -b ' + str(v_bitrate)
64 if v_framerate != None:
65 args += ' -r ' + str(v_framerate)
66 if v_resolution != None:
67 args += ' -s ' + v_resolution
69 args += ' -aspect ' + v_dar
72 args += ' "' + self.output_file + '"'
74 os.unlink(self.output_file)
78 # READ handler for process's output.
79 p = subprocess.Popen(args, shell=True,
80 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
83 # WRITE handler for logging.
84 log = open(self.log_file, 'w')
87 line = pipe.readline()
93 raise cis_exceptions.TranscodingException