コード例 #1
0
ファイル: encode_media.py プロジェクト: richlanc/KaraKara
 def _update_source_details(self, m, source_files=None):
     source_files = source_files or self._get_source_files(m)
     source_details = {}
     source_details.update({k:v for k, v in external_tools.probe_media(source_files['image'].get('absolute')).items() if k in ('width', 'height')})
     source_details.update({k:v for k, v in external_tools.probe_media(source_files['audio'].get('absolute')).items() if k in ('duration',)})
     source_details.update(external_tools.probe_media(source_files['video'].get('absolute')))
     m.source_details.update(source_details)
コード例 #2
0
    def _update_source_details(self, m):
        source_details = {}

        # Probe Image
        source_image = m.source_files['image'].get('absolute')
        if source_image:
            source_details.update({
                k: v
                for k, v in external_tools.probe_media(source_image).items()
                if k in ('width', 'height')
            })

        # Probe Audio
        source_audio = m.source_files['audio'].get('absolute')
        if source_audio:
            source_details.update({
                k: v
                for k, v in external_tools.probe_media(source_audio).items()
                if k in ('duration', )
            })

        # Probe Video
        source_video = m.source_files['video'].get('absolute')
        if source_video:
            source_details.update(external_tools.probe_media(source_video))

        m.source_details.update(source_details)
コード例 #3
0
ファイル: test_encode.py プロジェクト: vanthaiunghoa/KaraKara
def test_encode_video_simple():
    """
    Test normal video + subtitles encode flow
    Thubnail images and preview videos should be generated
    """
    with ProcessMediaTestManager(TEST1_VIDEO_FILES) as scan:
        scan.scan_media()
        scan.encode_media()
        processed_files = scan.get('test1').processed_files

        # Main Video - use OCR to read subtiles and check them
        video_file = processed_files['video'].absolute

        image = get_frame_from_video(video_file, 5)
        assert color_close(COLOR_RED, image.getpixel(SAMPLE_COORDINATE))
        assert 'Red' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'Green' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 15)
        assert color_close(COLOR_GREEN, image.getpixel(SAMPLE_COORDINATE))
        assert 'Green' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'Blue' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 25)
        assert color_close(COLOR_BLUE, image.getpixel(SAMPLE_COORDINATE))
        assert 'Blue' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert not read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        # Preview Video (can't check subtitles as the res is too small)
        preview_file = processed_files['preview'].absolute

        image = get_frame_from_video(preview_file, 5)
        assert color_close(COLOR_RED, image.getpixel(SAMPLE_COORDINATE))

        image = get_frame_from_video(preview_file, 15)
        assert color_close(COLOR_GREEN, image.getpixel(SAMPLE_COORDINATE))

        image = get_frame_from_video(preview_file, 25)
        assert color_close(COLOR_BLUE, image.getpixel(SAMPLE_COORDINATE))

        # Assert Thumbnail images
        # We sample at '20% 40% 60% %80' - in out 30 second video that is 'RED, GREEN, GREEN, BLUE'
        for image_num, color in enumerate(
            (COLOR_RED, COLOR_GREEN, COLOR_GREEN, COLOR_BLUE)):
            assert color_close(
                color,
                Image.open(processed_files['image{}'.format(
                    image_num + 1)].absolute).getpixel(SAMPLE_COORDINATE))

        video_details = probe_media(video_file)
        preview_details = probe_media(preview_file)
        assert abs(
            video_details['duration'] - preview_details['duration']
        ) < 0.5, 'Main video and Preview video should be the same duration'
        assert preview_details['width'] == ENCODE_CONFIG[
            'preview_width'], 'Preview video should match expected output size'
        assert video_details['width'] > ENCODE_CONFIG[
            'preview_width'], 'Main video should be greater than preview video size'
コード例 #4
0
ファイル: test_encode.py プロジェクト: richlanc/KaraKara
def test_encode_video_simple():
    """
    Test normal video + subtitles encode flow
    Thubnail images and preview videos should be generated
    """
    with ProcessMediaTestManager(TEST1_VIDEO_FILES) as scan:
        scan.scan_media()
        scan.encode_media()
        processed_files = scan.processed_files('test1')

        # Main Video - use OCR to read subtiles and check them
        video_file = processed_files['video'][0].absolute

        image = get_frame_from_video(video_file, 5)
        assert color_close(COLOR_RED, image.getpixel(SAMPLE_COORDINATE))
        assert 'Red' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'Green' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 15)
        assert color_close(COLOR_GREEN, image.getpixel(SAMPLE_COORDINATE))
        assert 'Green' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'Blue' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 25)
        assert color_close(COLOR_BLUE, image.getpixel(SAMPLE_COORDINATE))
        assert 'Blue' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert not read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        # Preview Video (can't check subtitles as the res is too small)
        preview_file = processed_files['preview'][0].absolute

        image = get_frame_from_video(preview_file, 5)
        assert color_close(COLOR_RED, image.getpixel(SAMPLE_COORDINATE))

        image = get_frame_from_video(preview_file, 15)
        assert color_close(COLOR_GREEN, image.getpixel(SAMPLE_COORDINATE))

        image = get_frame_from_video(preview_file, 25)
        assert color_close(COLOR_BLUE, image.getpixel(SAMPLE_COORDINATE))

        # Assert Thumbnail images
        # We sample at '20% 40% 60% %80' - in out 30 second video that is 'RED, GREEN, GREEN, BLUE'
        for image_num, color in enumerate((COLOR_RED, COLOR_GREEN, COLOR_GREEN, COLOR_BLUE)):
            assert color_close(color, Image.open(processed_files['image'][image_num].absolute).getpixel(SAMPLE_COORDINATE))

        video_details = probe_media(video_file)
        preview_details = probe_media(preview_file)
        assert abs(video_details['duration'] - preview_details['duration']) < 0.5, 'Main video and Preview video should be the same duration'
        assert preview_details['width'] == ENCODE_CONFIG['preview_width'], 'Preview video should match expected output size'
        assert video_details['width'] > ENCODE_CONFIG['preview_width'], 'Main video should be greater than preview video size'
コード例 #5
0
ファイル: encode_media.py プロジェクト: calaldees/KaraKara
    def _update_source_details(self, m):
        source_details = {}

        # Probe Image
        source_image = m.source_files["image"].get("absolute")
        if source_image:
            source_details.update(
                {k: v for k, v in external_tools.probe_media(source_image).items() if k in ("width", "height")}
            )

        # Probe Audio
        source_audio = m.source_files["audio"].get("absolute")
        if source_audio:
            source_details.update(
                {k: v for k, v in external_tools.probe_media(source_audio).items() if k in ("duration",)}
            )

        # Probe Video
        source_video = m.source_files["video"].get("absolute")
        if source_video:
            source_details.update(external_tools.probe_media(source_video))

        m.source_details.update(source_details)