Esempio n. 1
0
def duration(file):
    import subprocess
    from power_hour_creator.resources import ffmpeg_exe

    cmd = [ffmpeg_exe(), '-i', file, '-f', 'null', '-']

    output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    return DisplayTime(get_duration(output)).as_decimal()
Esempio n. 2
0
    def _shorten_to_one_minute(self, media_file):
        cmd = [
            ffmpeg_exe(), '-y', '-ss',
            str(media_file.track_start_time), '-t',
            '{}'.format(config.track_length), '-i', media_file.download_path,
            '-codec', 'copy', media_file.output_path
        ]

        self._logger.debug('Shortening {} to 1 minute with cmd: {}'.format(
            media_file.track_title, ' '.join(cmd)))
        subprocess.check_call(cmd,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              stdin=subprocess.PIPE)
Esempio n. 3
0
    def __init__(self, path, args):
        self.args          = args
        self.acodec        = self.args['--acodec']
        self.write_to_dir  = self.args['--dir']
        self.dry_run       = self.args['--dry-run']
        self.extra_options = self.args['--extra-options']
        self.force         = self.args['--force']
        self.format        = self.args['--format']
        self.max           = self.args['--max']
        self.ebu           = self.args['--ebu']
        self.merge         = self.args['--merge']
        self.no_prefix     = self.args['--no-prefix']
        self.prefix        = self.args['--prefix']
        self.target_level  = float(self.args['--level'])
        self.threshold     = float(self.args['--threshold'])

        # Find ffmpeg command in PATH
        self.ffmpeg_cmd = ffmpeg_exe()  # which('ffmpeg')
        if not self.ffmpeg_cmd:
            if which('avconv'):
                logger.error("avconv is not supported anymore. Please install ffmpeg from http://ffmpeg.org instead.")
                raise SystemExit("No ffmpeg installed")
            else:
                raise SystemExit("Could not find ffmpeg in your $PATH")

        if self.max and self.ebu:
            raise SystemExit("Either --max or --ebu have to be specified.")

        if self.ebu and ((self.target_level > -5.0) or (self.target_level < -70.0)):
            raise SystemExit("Target levels for EBU R128 must lie between -70 and -5")

        self.skip = False # whether the file should be skipped

        self.mean_volume = None
        self.max_volume  = None
        self.adjustment  = None

        self.input_file = path
        self.dir, self.filename = os.path.split(self.input_file)
        self.basename = os.path.splitext(self.filename)[0]

        # by default, the output path is the same as the input file's one
        self.output_file     = None
        self.output_filename = None
        self.output_dir     = self.dir

        self.set_output_filename()
Esempio n. 4
0
    def _convert_video_to_correct_attributes(self, media_file):
        cmd = [
            ffmpeg_exe(), '-i', media_file.download_path, '-y', '-acodec',
            'aac', '-vcodec', 'libx264', '-vf',
            'scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2',
            '-r', '30', '-preset', 'faster', '-nostdin', media_file.output_path
        ]

        self._logger.debug(
            'Resizing and correcting video {} with command: {}'.format(
                media_file.track_title, ' '.join(cmd)))
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             stdin=subprocess.PIPE)

        self._log_process_output(p)

        self._logger.debug('Done')
Esempio n. 5
0
    def merge_files_into_power_hour(self, output_files, power_hour_path):
        concat_directive_path = os.path.join(self._download_dir,
                                             "concat_input.txt")
        self._write_output_track_list_to_file(output_files,
                                              concat_directive_path)

        cmd = [
            ffmpeg_exe(), '-y', '-f', 'concat', '-safe', '0', '-i',
            concat_directive_path, '-c', 'copy', '-nostdin', power_hour_path
        ]

        self._logger.info('Merging into power hour with command: {}'.format(
            " ".join(cmd)))

        if platform.system() == 'Windows':
            process = delegator.run(cmd)
        else:
            subprocess.check_call(cmd,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  stdin=subprocess.PIPE)
Esempio n. 6
0
    def merge_files_into_power_hour(self, output_files, power_hour_path):
        scale_string = 'scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1:1'
        filter_strings = []

        for index in range(len(output_files)):
            filter_strings.append('[{}:v]{}[v{}];'.format(
                index, scale_string, index))

        for index in range(len(output_files)):
            filter_strings.append('[v{}][{}:a:0]'.format(index, index))

        filter_complex = '{} concat=n={}:v=1:a=1 [v] [a]'.format(
            ' '.join(filter_strings), len(output_files))

        input_directives = []
        for file in output_files:
            input_directives.append('-i')
            input_directives.append(file)

        cmd = [
            ffmpeg_exe(), *input_directives, '-filter_complex', filter_complex,
            '-map', '[v]', '-map', '[a]', '-y', '-acodec', 'aac', '-vcodec',
            'libx264', '-s', '1280x720', '-r', '30', '-preset', 'faster',
            '-crf', '17', '-nostdin', power_hour_path
        ]

        self._logger.debug(
            'Combining videos into power hour with cmd: {}'.format(
                ' '.join(cmd)))
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             stdin=subprocess.PIPE)

        self._log_process_output(p)

        self._logger.debug('Done')