TaqiRaza512's picture
Initial commit
a103028
from ..common.Common import *
from ..common.Execute import *
class Ffmpeg:
def add_input(self, input_files, start_time_code = "", end_time_code = "", duration_time_code = ""):
if start_time_code != "":
self.command += " -ss " + start_time_code
if duration_time_code != "":
self.command += " -t " + duration_time_code
if end_time_code != "":
self.command += " -to " + end_time_code
if len(input_files) == 1:
input_file = input_files[0]
AssertFileExists(input_file)
self.command += " -i " + input_file
else:
self.command += " -f concat -safe 0"
echo_command = ""
for input_file in input_files:
AssertFileExists(input_file)
echo_command = echo_command + " echo file '" + input_file + "'; "
self.command += " -i " + "<(" + echo_command + ")"
def set_output(self, output_file, audio_channels, audio_sample_rate, output_format = ""):
if audio_channels > 0:
self.command += " -ac " + str(audio_channels)
if audio_sample_rate > 0:
self.command += " -ar " + str(audio_sample_rate)
if output_format != "":
self.command += " -f " + output_format
self.command += " " + output_file
self.output_file = output_file
def set_audio_filter(self, audio_filter):
if audio_filter != "":
self.command += " -filter_complex " + audio_filter
def __init__(self, log_level = "info"):
self.command = "ffmpeg -y -hide_banner -loglevel level+info"
if log_level != "":
self.command += " -loglevel level+" + log_level
self.command_output = ""
def Command(self):
return self.command
def Execute(self):
_, self.command_output, _ = ExecuteCommand(self.command)
if self.output_file != "/dev/null":
AssertFileExists(self.output_file)
return self.command_output