Beispiel #1
0
def test_encode_audio_simple():
    """
    Check audio + image encoding
    """
    with ProcessMediaTestManager(TEST2_AUDIO_FILES) as scan:
        scan.scan_media()
        scan.encode_media()
        processed_files = scan.processed_files('test2')

        video_file = processed_files['video'][0].absolute

        image = get_frame_from_video(video_file, 2)
        assert 'AA' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'BB' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 7)
        assert 'BB' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 12)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        for image_num, color in enumerate((COLOR_MAGENTA,)*4):
            assert color_close(color, Image.open(processed_files['image'][image_num].absolute).getpixel(SAMPLE_COORDINATE))
Beispiel #2
0
def test_encode_audio_simple():
    """
    Check audio + image encoding
    """
    with ProcessMediaTestManager(TEST2_AUDIO_FILES) as scan:
        scan.scan_media()
        scan.encode_media()
        processed_files = scan.get('test2').processed_files

        video_file = processed_files['video'].absolute

        image = get_frame_from_video(video_file, 2)
        assert 'AA' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert 'BB' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 7)
        assert 'BB' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        image = get_frame_from_video(video_file, 12)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_CURRENT)
        assert '' == read_subtitle_text(image, COLOR_SUBTITLE_NEXT)

        for image_num, color in enumerate((COLOR_MAGENTA, ) * 4):
            assert color_close(
                color,
                Image.open(processed_files['image{}'.format(
                    image_num + 1)].absolute).getpixel(SAMPLE_COORDINATE))
Beispiel #3
0
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'
Beispiel #4
0
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'