File size: 1,260 Bytes
561c629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''
    This file is to help us make figure of CRF vs Preset in Video Compression
'''
import os, sys, shutil

def compress(input_folder, codec, crf, preset):
    video_store_name = "compressed.mp4"
    store_dir = input_folder + "_crf" + str(crf) + "_" + preset
    
    if os.path.exists(video_store_name):
        os.remove(video_store_name)
    if os.path.exists(store_dir):
        shutil.rmtree(store_dir)
    os.makedirs(store_dir)


    # Encode 
    os.system("ffmpeg -r 30 -f image2 -i " + input_folder + "/%d.png -vcodec " + codec + " -crf " + str(crf) + " -preset " + preset + " -pix_fmt yuv420p " + video_store_name)

    # Split to frames
    os.system("ffmpeg -i " + video_store_name + " " + store_dir + "/test_%06d.png")



if __name__ == "__main__":
    input_folders = ["ReadySetGo", "Jockey"]
    codec = "libx264"
    crf_ranges = [25 + 5*i for i in range(6)]
    preset_ranges = ["ultrafast", "veryfast", "fast", "medium", "slow", "veryslow", "placebo"]


    for input_folder in input_folders:
        for crf in crf_ranges:
            for preset in preset_ranges:
                print("We are handling {} with crf {} with preset {}".format(input_folder, crf, preset))
                compress(input_folder, codec, crf, preset)