示例#1
0
    def run(self, info):
        self.logger = create_logger(__name__)
        filename = info['filepath']
        temp_filename = prepend_extension(filename, 'sanetemp')
        remux = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0']
        args = [remux]
        if info.get('audio_codec') is not None:
            encode_audio = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0', '-c:1:a:0', info.get('audio_codec')]
            args.append(encode_audio)
        if info.get('video_codec') is not None:
            encode_video = ['-c', 'copy', '-c:0:v:0', info.get('video_codec'), '-map', '0:v:0', '-map', '1:a:0',
                            '-c:1:a:0']
            args.append(encode_video)
        if info.get('video_codec') is not None and info.get('audio_codec') is not None:
            encode_both = ['-c', 'copy', '-c:0:v:0', info.get('video_codec'), '-map', '0:v:0', '-map', '1:a:0',
                           '-c:1:a:0', info.get('audio_codec')]
            args.append(encode_both)

        if info.get('no_remux') is not None:
            args.pop(0)

        self.logger.info('[ffmpeg] Merging formats into "%s"' % filename)
        self.attempt_ffmpeg(info, temp_filename, args)

        os.rename(encodeFilename(temp_filename), encodeFilename(filename))
        return info['__files_to_merge'], info
示例#2
0
    def run(self, info):
        metadata = self._extract_metadata(info)

        if not metadata:
            self._downloader.to_screen(
                '[ffmpeg] There isn\'t any metadata to add')
            return [], info

        filename = info['filepath']
        temp_filename = prepend_extension(filename, 'temp')

        if info['ext'] == 'm4a':
            options = ['-vn', '-acodec', 'copy']
        else:
            options = ['-c', 'copy']

        for (name, value) in metadata.items():
            options.extend(['-metadata', '%s=%s' % (name, value)])

        self._downloader.to_screen('[ffmpeg] Adding metadata to \'%s\'' %
                                   filename)
        self.run_ffmpeg(filename, temp_filename, options)
        os.remove(encodeFilename(filename))
        os.rename(encodeFilename(temp_filename), encodeFilename(filename))
        return [], info
示例#3
0
    def run(self, information):
        if information['ext'] not in ('mp4', 'webm', 'mkv'):
            self._downloader.to_screen('[ffmpeg] Subtitles can only be embedded in mp4, webm or mkv files')
            return [], information
        subtitles = information.get('requested_subtitles')
        if not subtitles:
            self._downloader.to_screen('[ffmpeg] There aren\'t any subtitles to embed')
            return [], information

        filename = information['filepath']

        ext = information['ext']
        sub_langs = []
        sub_filenames = []
        webm_vtt_warn = False

        for lang, sub_info in subtitles.items():
            sub_ext = sub_info['ext']
            if ext != 'webm' or ext == 'webm' and sub_ext == 'vtt':
                sub_langs.append(lang)
                sub_filenames.append(subtitles_filename(filename, lang, sub_ext))
            else:
                if not webm_vtt_warn and ext == 'webm' and sub_ext != 'vtt':
                    webm_vtt_warn = True
                    self._downloader.to_screen('[ffmpeg] Only WebVTT subtitles can be embedded in webm files')

        if not sub_langs:
            return [], information

        input_files = [filename] + sub_filenames

        opts = [
            '-map', '0',
            '-c', 'copy',
            # Don't copy the existing subtitles, we may be running the
            # postprocessor a second time
            '-map', '-0:s',
        ]
        if information['ext'] == 'mp4':
            opts += ['-c:s', 'mov_text']
        for (i, lang) in enumerate(sub_langs):
            opts.extend(['-map', '%d:0' % (i + 1)])
            lang_code = ISO639Utils.short2long(lang)
            if lang_code is not None:
                opts.extend(['-metadata:s:s:%d' % i, 'language=%s' % lang_code])

        temp_filename = prepend_extension(filename, 'temp')
        self._downloader.to_screen('[ffmpeg] Embedding subtitles in \'%s\'' % filename)
        self.run_ffmpeg_multiple_files(input_files, temp_filename, opts)
        os.remove(encodeFilename(filename))
        os.rename(encodeFilename(temp_filename), encodeFilename(filename))

        return sub_filenames, information
示例#4
0
 def test_prepend_extension(self):
     self.assertEqual(prepend_extension('abc.ext', 'temp'), 'abc.temp.ext')
     self.assertEqual(prepend_extension('abc.ext', 'temp', 'ext'), 'abc.temp.ext')
     self.assertEqual(prepend_extension('abc.unexpected_ext', 'temp', 'ext'), 'abc.unexpected_ext.temp')
     self.assertEqual(prepend_extension('abc', 'temp'), 'abc.temp')
     self.assertEqual(prepend_extension('.abc', 'temp'), '.abc.temp')
     self.assertEqual(prepend_extension('.abc.ext', 'temp'), '.abc.temp.ext')
示例#5
0
 def test_prepend_extension(self):
     self.assertEqual(prepend_extension("abc.ext", "temp"), "abc.temp.ext")
     self.assertEqual(prepend_extension("abc.ext", "temp", "ext"), "abc.temp.ext")
     self.assertEqual(prepend_extension("abc.unexpected_ext", "temp", "ext"), "abc.unexpected_ext.temp")
     self.assertEqual(prepend_extension("abc", "temp"), "abc.temp")
     self.assertEqual(prepend_extension(".abc", "temp"), ".abc.temp")
     self.assertEqual(prepend_extension(".abc.ext", "temp"), ".abc.temp.ext")
示例#6
0
    def run(self, info):
        stretched_ratio = info.get('stretched_ratio')
        if stretched_ratio is None or stretched_ratio == 1:
            return [], info

        filename = info['filepath']
        temp_filename = prepend_extension(filename, 'temp')

        options = ['-c', 'copy', '-aspect', '%f' % stretched_ratio]
        self._downloader.to_screen('[ffmpeg] Fixing aspect ratio in "%s"' % filename)
        self.run_ffmpeg(filename, temp_filename, options)

        os.remove(encodeFilename(filename))
        os.rename(encodeFilename(temp_filename), encodeFilename(filename))

        return [], info
示例#7
0
    def run(self, info):
        metadata = self._extract_metadata(info)

        if not metadata:
            self._downloader.to_screen('[ffmpeg] There isn\'t any metadata to add')
            return [], info

        filename = info['filepath']
        temp_filename = prepend_extension(filename, 'temp')

        if info['ext'] == 'm4a':
            options = ['-vn', '-acodec', 'copy']
        else:
            options = ['-c', 'copy']

        for (name, value) in metadata.items():
            options.extend(['-metadata', '%s=%s' % (name, value)])

        self._downloader.to_screen('[ffmpeg] Adding metadata to \'%s\'' % filename)
        self.run_ffmpeg(filename, temp_filename, options)
        os.remove(encodeFilename(filename))
        os.rename(encodeFilename(temp_filename), encodeFilename(filename))
        return [], info