Example #1
0
    def make_thumbnail(self, options=None):
        if not options:
            options = {}
        width = options.get('width', 0)

        self.video_opts += [
            ('-frames:v', 1),
        ]

        if width:
            # ffmpeg will figure out the height by itself to keep the ratio
            self.video_filter_chain += [
                ('scale', 'scale=%s:-1' % width),
            ]

        frames_batch = 200  # frames to be analized
        avinfo = self._get_input_avinfo()
        if 'duration' in avinfo.video_streams[0]:
            frame_count = int(avinfo.video_fps*float(avinfo.video_streams[0]['duration']))
            if frame_count < frames_batch:
                # For very short videos
                frames_batch = frame_count

        # The thumbnail filter extracts an image from the first frames
        # Available since ffmpeg 2.0 (better to use a named parameter)
        if is_option_available('ffmpeg', 'n .* set the frames batch size', regex=True):
            self.video_filter_chain += [('thumbnail', 'thumbnail=n=%d' % frames_batch)]
        else:
            self.video_filter_chain += [('thumbnail', 'thumbnail=%d' % frames_batch)]
Example #2
0
    def make_thumbnail(self, options=None):
        if not options:
            options = {}
        width = options.get("width", 0)

        self.video_opts += [
            ("-frames:v", 1),
        ]

        if width:
            # ffmpeg will figure out the height by itself to keep the ratio
            self.video_filter_chain += [
                ("scale", "scale=%s:-1" % width),
            ]

        frames_batch = 200  # frames to be analized
        avinfo = self._get_input_avinfo()
        if "duration" in avinfo.video_streams[0]:
            frame_count = int(avinfo.video_fps *
                              float(avinfo.video_streams[0]["duration"]))
            if frame_count < frames_batch:
                # For very short videos
                frames_batch = frame_count

        # The thumbnail filter extracts an image from the first frames
        # Available since ffmpeg 2.0 (better to use a named parameter)
        if is_option_available("ffmpeg",
                               "n .* set the frames batch size",
                               regex=True):
            self.video_filter_chain += [("thumbnail",
                                         "thumbnail=n=%d" % frames_batch)]
        else:
            self.video_filter_chain += [("thumbnail",
                                         "thumbnail=%d" % frames_batch)]
Example #3
0
    def transcode_aac(self, options=None):
        if not options:
            options = {}
        bitrate = options.get("bitrate", 0)
        if bitrate == 0:
            bitrate = 192

        # libfaac is no longer available since ffmpeg 3.2
        if is_option_available("ffmpeg", "faac", regex=True):
            aac_codec = "libfaac"
        else:
            aac_codec = "aac"
        self.audio_opts = [("-acodec", aac_codec), ("-b:a", "%sk" % bitrate)]
Example #4
0
    def transcode_aac(self, options=None):
        if not options:
            options = {}
        bitrate = options.get('bitrate', 0)
        if bitrate == 0:
            bitrate = 192

        # libfaac is no longer available since ffmpeg 3.2
        if is_option_available('ffmpeg', 'faac', regex=True):
            aac_codec = 'libfaac'
        else:
            aac_codec = 'aac'
        self.audio_opts = [('-acodec', aac_codec), ('-b:a', '%sk' % bitrate)]
Example #5
0
    def transcode_aac(self, options=None):
        if not options:
            options = {}
        bitrate = options.get('bitrate', 0)
        if bitrate == 0:
            bitrate = 192

        # libfaac is no longer available since ffmpeg 3.2
        if is_option_available('ffmpeg', 'faac', regex=True):
            aac_codec = 'libfaac'
        else:
            aac_codec = 'aac'
        self.audio_opts = [
            ('-acodec', aac_codec),
            ('-b:a', '%sk' % bitrate)
        ]
Example #6
0
    def transcode_imx(self, options=None):
        if not options:
            options = {}
        bitrate = options.get('bitrate', 50000)
        enable_fourcc_tagging = options.get('enable_fourcc_tagging', False)
        avinfo = self._get_input_avinfo()

        codec_tag = None
        bufsize = 0

        if not (avinfo.video_is_SD_PAL() or avinfo.video_is_SD_NTSC()):
            raise FFmpegWorkerException('IMX codec only supports PAL and NTSC frame rates')

        if bitrate not in [30000, 50000]:
            raise FFmpegWorkerException('IMX codec does not support bitrate at %sk' % bitrate)

        self.video_opts = []
        self.video_opts += [
            ('-g', 0),
            ('-flags', '+ildct+low_delay'),
            ('-dc', 10),
            ('-intra_vlc', 1),
            ('-non_linear_quant', 1),
            ('-qscale', 1),
            ('-vcodec', 'mpeg2video'),
            ('-ps', 1),
            ('-qmin', 1),
            ('-qmax', 12),
            ('-lmin', '1*QP2LAMBDA'),
            ('-rc_max_vbv_use', 1),
            ('-pix_fmt', 'yuv422p'),
            ('-top', 1),
        ]

        # Available since ffmpeg n2.3
        if is_option_available('ffmpeg','d10_channelcount'):
            self.video_opts += [
                ('-d10_channelcount', 8),
            ]

        if avinfo.video_is_SD_PAL() and bitrate == 30000:
            codec_tag = 'mx3p'
            bufsize = 1200000
        elif avinfo.video_is_SD_NTSC() and bitrate == 30000:
            codec_tag = 'mx3n'
            bufsize = 1001000
        elif avinfo.video_is_SD_PAL() and bitrate == 50000:
            codec_tag = 'mx5p'
            bufsize = 2000000
        elif avinfo.video_is_SD_NTSC() and bitrate == 50000:
            codec_tag = 'mx5n'
            bufsize = 1668334

        self.video_opts += [
            ('-minrate', '%sk' % bitrate),
            ('-maxrate', '%sk' % bitrate),
            ('-b:v', '%sk' % bitrate),
            ('-bufsize', bufsize),
            ('-rc_init_occupancy', bufsize),
        ]

        if enable_fourcc_tagging:
            self.video_opts += [
                ('-vtag', codec_tag)
            ]

        self.video_filter_chain = []
        if avinfo.video_is_SD_NTSC():
            self.video_filter_chain.append(('fieldorder', 'fieldorder=tff'))

        if not avinfo.video_has_vbi:
            if avinfo.video_is_SD_PAL():
                self.video_filter_chain.append(('add_vbi', 'pad=720:608:00:32'))
            elif avinfo.video_is_SD_NTSC():
                self.video_filter_chain.append(('add_vbi', 'pad=720:512:00:32'))

        self.keep_vbi_lines = True
        self.mov_imx_header = True
Example #7
0
    def transcode_imx(self, options=None):
        if not options:
            options = {}
        bitrate = options.get("bitrate", 50000)
        enable_fourcc_tagging = options.get("enable_fourcc_tagging", False)
        avinfo = self._get_input_avinfo()

        codec_tag = None
        bufsize = 0

        if not (avinfo.video_is_SD_PAL() or avinfo.video_is_SD_NTSC()):
            raise FFmpegWorkerException(
                "IMX codec only supports PAL and NTSC frame rates")

        if bitrate not in [30000, 50000]:
            raise FFmpegWorkerException(
                "IMX codec does not support bitrate at %sk" % bitrate)

        self.video_opts = []
        self.video_opts += [
            ("-g", 0),
            ("-flags", "+ildct+low_delay"),
            ("-dc", 10),
            ("-intra_vlc", 1),
            ("-non_linear_quant", 1),
            ("-qscale", 1),
            ("-vcodec", "mpeg2video"),
            ("-ps", 1),
            ("-qmin", 1),
            ("-qmax", 12),
            ("-lmin", "1*QP2LAMBDA"),
            ("-rc_max_vbv_use", 1),
            ("-pix_fmt", "yuv422p"),
            ("-top", 1),
        ]

        # Available since ffmpeg n2.3
        if is_option_available("ffmpeg", "d10_channelcount"):
            self.video_opts += [
                ("-d10_channelcount", 8),
            ]

        if avinfo.video_is_SD_PAL() and bitrate == 30000:
            codec_tag = "mx3p"
            bufsize = 1200000
        elif avinfo.video_is_SD_NTSC() and bitrate == 30000:
            codec_tag = "mx3n"
            bufsize = 1001000
        elif avinfo.video_is_SD_PAL() and bitrate == 50000:
            codec_tag = "mx5p"
            bufsize = 2000000
        elif avinfo.video_is_SD_NTSC() and bitrate == 50000:
            codec_tag = "mx5n"
            bufsize = 1668334

        self.video_opts += [
            ("-minrate", "%sk" % bitrate),
            ("-maxrate", "%sk" % bitrate),
            ("-b:v", "%sk" % bitrate),
            ("-bufsize", bufsize),
            ("-rc_init_occupancy", bufsize),
        ]

        if enable_fourcc_tagging:
            self.video_opts += [("-vtag", codec_tag)]

        self.video_filter_chain = []
        if avinfo.video_is_SD_NTSC():
            self.video_filter_chain.append(("fieldorder", "fieldorder=tff"))

        if not avinfo.video_has_vbi:
            if avinfo.video_is_SD_PAL():
                self.video_filter_chain.append(
                    ("add_vbi", "pad=720:608:00:32"))
            elif avinfo.video_is_SD_NTSC():
                self.video_filter_chain.append(
                    ("add_vbi", "pad=720:512:00:32"))

        self.keep_vbi_lines = True
        self.mov_imx_header = True
Example #8
0
    def transcode_imx(self, options=None):
        if not options:
            options = {}
        bitrate = options.get('bitrate', 50000)
        enable_fourcc_tagging = options.get('enable_fourcc_tagging', False)
        avinfo = self._get_input_avinfo()

        codec_tag = None
        bufsize = 0

        if not (avinfo.video_is_SD_PAL() or avinfo.video_is_SD_NTSC()):
            raise FFmpegWorkerException(
                'IMX codec only supports PAL and NTSC frame rates')

        if bitrate not in [30000, 50000]:
            raise FFmpegWorkerException(
                'IMX codec does not support bitrate at %sk' % bitrate)

        self.video_opts = []
        self.video_opts += [
            ('-g', 0),
            ('-flags', '+ildct+low_delay'),
            ('-dc', 10),
            ('-intra_vlc', 1),
            ('-non_linear_quant', 1),
            ('-qscale', 1),
            ('-vcodec', 'mpeg2video'),
            ('-ps', 1),
            ('-qmin', 1),
            ('-qmax', 12),
            ('-lmin', '1*QP2LAMBDA'),
            ('-rc_max_vbv_use', 1),
            ('-pix_fmt', 'yuv422p'),
            ('-top', 1),
        ]

        # Available since ffmpeg n2.3
        if is_option_available('ffmpeg', 'd10_channelcount'):
            self.video_opts += [
                ('-d10_channelcount', 8),
            ]

        if avinfo.video_is_SD_PAL() and bitrate == 30000:
            codec_tag = 'mx3p'
            bufsize = 1200000
        elif avinfo.video_is_SD_NTSC() and bitrate == 30000:
            codec_tag = 'mx3n'
            bufsize = 1001000
        elif avinfo.video_is_SD_PAL() and bitrate == 50000:
            codec_tag = 'mx5p'
            bufsize = 2000000
        elif avinfo.video_is_SD_NTSC() and bitrate == 50000:
            codec_tag = 'mx5n'
            bufsize = 1668334

        self.video_opts += [
            ('-minrate', '%sk' % bitrate),
            ('-maxrate', '%sk' % bitrate),
            ('-b:v', '%sk' % bitrate),
            ('-bufsize', bufsize),
            ('-rc_init_occupancy', bufsize),
        ]

        if enable_fourcc_tagging:
            self.video_opts += [('-vtag', codec_tag)]

        self.video_filter_chain = []
        if avinfo.video_is_SD_NTSC():
            self.video_filter_chain.append(('fieldorder', 'fieldorder=tff'))

        if not avinfo.video_has_vbi:
            if avinfo.video_is_SD_PAL():
                self.video_filter_chain.append(
                    ('add_vbi', 'pad=720:608:00:32'))
            elif avinfo.video_is_SD_NTSC():
                self.video_filter_chain.append(
                    ('add_vbi', 'pad=720:512:00:32'))

        self.keep_vbi_lines = True
        self.mov_imx_header = True