def test_add_videos(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") vv = X264Codec.from_format_video("tests/video_file/done_v.mp4") vs = [vh, vv] v1 = vh + vv for _ in range(random.randint(3, 10)): v1 += vs[random.randint(0, 1)] print("") print(v1) print(v1.bitrate) print(v1.duration)
def test_snapshot(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") for _ in range(10): start = random.random() * 100 height = random.randint(240, 480) jpg = vh.snapshot(start, height) print(f"===== start: {start}, height: {height} =====") print(jpg)
def test_x264codec_init(): with pytest.raises(ValueError): X264Codec('no-this-file') video_h = X264Codec('tests/video_file/h.mp4') video_v = X264Codec('tests/video_file/v.mp4') print('============== video_h ===============') print(video_h) print(video_h.bitrate) print(video_h.duration) video_h.move("tests/video_file/done_h.mp4") print(video_h) print('============== video_v ===============') print(video_v) print(video_v.bitrate) print(video_v.duration) video_v.move("tests/video_file/done_v.mp4") print(video_v)
def test_cut_video(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") for _ in range(10): start = random.random() * 100 last = random.random() * 100 vh1 = vh.cut_video(start, last) print(f"===== start: {start}, last: {last} =====") print(vh1) print(vh1.duration) print(vh1.bitrate)
def test_down_bitrate(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") new_bitrate = random.randint(150, 650) print("") print(f"======= bitrate: {new_bitrate} =========") vh1 = vh.down_bitrate(new_bitrate) print(vh1) print(vh1.duration) print(vh1.bitrate)
def test_add_ass(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") vv = X264Codec.from_format_video("tests/video_file/done_v.mp4") assert vh.add_ass('tests/video_file/ffmpeg-logo.png') is None assert vh.add_ass('tests/video_file/no.ass') is None assert vv.add_ass('tests/video_file/ffmpeg-logo.png') is None assert vv.add_ass('tests/video_file/no.ass') is None vh1 = vh.add_ass('tests/video_file/test.ass') vv1 = vv.add_ass('tests/video_file/test.ass') print("") print('============== vh1 ===============') print(vh1) print(vh1.bitrate) print(vh1.duration) print('============== vv1 ===============') print(vv1) print(vv1.bitrate) print(vv1.duration)
def test_slice(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") v1 = vh[179] print("") print(len(vh)) print(v1) print(vh[11:20:10]) print(vh[1:8:-10]) vh2 = vh[::10] print(vh2) print(sum(vh2)) print(vh[1:8:-6])
def test_del_logo(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") delogos = [ vargs.delogo_args(ri(0, vargs.VIDEO_WIDTH), ri(0, vargs.VIDEO_HEIGHT), ri(0, vargs.VIDEO_WIDTH), ri(0, vargs.VIDEO_HEIGHT), ri(0, 90), ri(45, 180)) for _ in range(10) ] print("") vh1 = vh.del_logo(delogos) print(vh1) print(vh1.bitrate) print(vh1.duration)
def test_add_logo(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") vv = X264Codec.from_format_video("tests/video_file/done_v.mp4") assert vh.add_logo('tests/video_file/ffmpeg-logo.png', 2, LogoType.FIXED, 35, 35) is None assert vv.add_logo('tests/video_file/ffmpeg-logo.png', 2, LogoType.FIXED, 65, 65) is None assert vh.add_logo('tests/video_file/ffmpeg-logo.png', 2, LogoType.MOVED, 35, 35) is None assert vv.add_logo('tests/video_file/ffmpeg-logo.png', 2, LogoType.MOVED, 65, 65) is None assert vh.add_logo('tests/video_file/no-logo.png', 0.3, LogoType.FIXED, 35, 35) is None assert vh.add_logo('tests/video_file/no-logo.png', 0.25, LogoType.MOVED, ) is None assert vv.add_logo('tests/video_file/no-logo.png', 0.3, LogoType.FIXED, 65, 65) is None assert vv.add_logo('tests/video_file/no-logo.png', 0.25, LogoType.MOVED, ) is None vh1 = vh.add_logo('tests/video_file/ffmpeg-logo.png', 0.3) vh2 = vh.add_logo('tests/video_file/ffmpeg-logo.png', 0.25, LogoType.MOVED) vv1 = vv.add_logo('tests/video_file/ffmpeg-logo.png', 0.3, LogoType.FIXED, 65, 65) vv2 = vv.add_logo('tests/video_file/ffmpeg-logo.png', 0.25, LogoType.MOVED) print("") print('============== vh1 ===============') print(vh1) print(vh1.bitrate) print(vh1.duration) print('============== vh2 ===============') print(vh2) print(vh2.bitrate) print(vh2.duration) print('============== vv1 ===============') print(vv1) print(vv1.bitrate) print(vv1.duration) print('============== vv2 ===============') print(vv2) print(vv2.bitrate) print(vv2.duration)
def test_hls(): vh = X264Codec.from_format_video("tests/video_file/done_h.mp4") print('') print(vh.hls(True, True)) print(vh.hls(encrypt=True)) print(vh.hls())