File size: 2,064 Bytes
a103028
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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