示例#1
0
 def test_ensure_throws_exception_for_absent_video_codec_args(self):
     with pytest.raises(ImportError) as excinfo:
         # Fetch a list of args from the unffmpeg video codec handler
         video_codec_handle = unffmpeg.VideoCodecHandle(
             mkv_ffprobe.mkv_multiple_subtitles_ffprobe)
         # Set the video codec to something that does not exist
         video_codec_handle.set_video_codec('non_existent_codec')
示例#2
0
 def test_ensure_we_can_generate_video_codec_args(self):
     # Fetch a list of args from the unffmpeg video codec handler
     video_codec_handle = unffmpeg.VideoCodecHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe)
     video_codec_args = video_codec_handle.args()
     # Assert the streams to map array is not empty
     assert video_codec_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert video_codec_args['streams_to_encode']
示例#3
0
 def test_ensure_we_can_generate_hevc_video_codec_args(self):
     # Fetch a list of args from the unffmpeg video codec handler
     video_codec_handle = unffmpeg.VideoCodecHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe)
     # Set the video codec to HEVC
     video_codec_handle.set_video_codec('hevc')
     video_codec_args = video_codec_handle.args()
     # Assert the streams to map array is not empty
     assert video_codec_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert video_codec_args['streams_to_encode']
     # Assert the streams to encode array is set to libx265
     assert video_codec_args['streams_to_encode'][1] == 'libx265'
示例#4
0
 def test_ensure_we_can_generate_copy_current_video_codec_args(self):
     # Fetch a list of args from the unffmpeg video codec handler
     video_codec_handle = unffmpeg.VideoCodecHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe)
     # Just copy the current codec (do not re-encode)
     video_codec_handle.disable_video_encoding = True
     video_codec_args = video_codec_handle.args()
     # Assert the streams to map array is not empty
     assert video_codec_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert video_codec_args['streams_to_encode']
     # Assert the streams to encode array is set to copy
     assert video_codec_args['streams_to_encode'][1] == 'copy'
示例#5
0
 def test_ensure_args_of_video_stream_is_copied_if_src_codec_matches_dest_codec(
         self):
     # Fetch a list of args from the unffmpeg video codec handler
     video_codec_handle = unffmpeg.VideoCodecHandle(
         mkv_ffprobe.mkv_multiple_subtitles_ffprobe)
     # Set the video codec to H264 the same as the current source video codec
     video_codec_handle.set_video_codec('h264')
     video_codec_args = video_codec_handle.args()
     # Assert the streams to map array is not empty
     assert video_codec_args['streams_to_map']
     # Assert the streams to encode array is not empty
     assert video_codec_args['streams_to_encode']
     # Assert the streams to encode array is set to copy
     assert video_codec_args['streams_to_encode'][1] == 'copy'
示例#6
0
文件: ffmpeg.py 项目: mjonkus/unmanic
    def generate_ffmpeg_args(self,):
        # ffmpeg -i /library/XXXXX.mkv \
        #     -c:v libx265 \
        #     -map 0:0 -map 0:1 -map 0:1 \
        #     -c:a:0 copy \
        #     -c:a:1 libmp3lame -b:a:0 192k -ac 2 \
        #     -y /cache/XXXXX.mkv
        # 

        # Read video information for the input file
        file_probe = self.file_in['file_probe']
        if not file_probe:
            return False

        # current_container = unffmpeg.containers.grab_module(self.settings.OUT_CONTAINER)
        destination_container = unffmpeg.containers.grab_module(self.settings.OUT_CONTAINER)

        # Suppress printing banner. (-hide_banner)
        # Set loglevel to info ("-loglevel", "info")
        # Allow experimental encoder config ("-strict", "-2")
        # 
        command = ["-hide_banner", "-loglevel", "info", "-strict", "-2", "-max_muxing_queue_size", "512"]

        # Read stream data
        streams_to_map = []
        streams_to_encode = []

        # Set video encoding args
        video_codec_handle = unffmpeg.VideoCodecHandle(file_probe)
        if not self.settings.ENABLE_VIDEO_ENCODING:
            video_codec_handle.disable_video_encoding = True
        video_codec_handle.set_video_codec(self.settings.VIDEO_CODEC)
        video_codec_args = video_codec_handle.args()
        streams_to_map = streams_to_map + video_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + video_codec_args['streams_to_encode']

        # Set audio encoding args
        audio_codec_handle = unffmpeg.AudioCodecHandle(file_probe)
        if not self.settings.ENABLE_AUDIO_ENCODING:
            audio_codec_handle.disable_audio_encoding = True
        # Are we transcoding audio streams to a configured codec?
        audio_codec_handle.enable_audio_stream_transcoding = self.settings.ENABLE_AUDIO_STREAM_TRANSCODING
        audio_codec_handle.audio_codec_transcoding = self.settings.AUDIO_CODEC
        audio_codec_handle.audio_encoder_transcoding = self.settings.AUDIO_STREAM_ENCODER
        # Are we cloning audio streams to stereo streams?
        audio_codec_handle.enable_audio_stream_stereo_cloning = self.settings.ENABLE_AUDIO_STREAM_STEREO_CLONING
        audio_codec_handle.set_audio_codec_with_default_encoder_cloning(self.settings.AUDIO_CODEC_CLONING)
        audio_codec_handle.audio_stereo_stream_bitrate = self.settings.AUDIO_STEREO_STREAM_BITRATE
        # Fetch args
        audio_codec_args = audio_codec_handle.args()
        streams_to_map = streams_to_map + audio_codec_args['streams_to_map']
        streams_to_encode = streams_to_encode + audio_codec_args['streams_to_encode']

        # Set subtitle encoding args
        subtitle_handle = unffmpeg.SubtitleHandle(file_probe, destination_container)
        if self.settings.REMOVE_SUBTITLE_STREAMS:
            subtitle_handle.remove_subtitle_streams = True
        subtitle_args = subtitle_handle.args()
        streams_to_map = streams_to_map + subtitle_args['streams_to_map']
        streams_to_encode = streams_to_encode + subtitle_args['streams_to_encode']

        # Map streams
        command = command + streams_to_map

        # Add arguments for creating streams
        command = command + streams_to_encode

        self._log(" ".join(command), level='debug')

        return command