|
49 | 49 | file_name_bytes = FILE_NAME.encode()
|
50 | 50 |
|
51 | 51 | raw_data = len(file_name_bytes).to_bytes(4) + file_name_bytes + len(file_data).to_bytes(8) + file_data
|
52 |
| -n_bytes = len(raw_data) # we use bytes as each pixel (r/g/b) is 1 byte (0-255) |
53 | 52 |
|
54 |
| -frame_count = math.ceil(n_bytes / CHOSEN_SIZE.frame_pixels) |
55 |
| -pad_val = frame_count * CHOSEN_SIZE.frame_pixels - n_bytes # how much to pad with black pixels (zeros) |
56 | 53 |
|
57 | 54 | # create the image data
|
58 | 55 | img_io = io.BytesIO()
|
59 | 56 |
|
60 | 57 | parsed_data = np.frombuffer(raw_data, dtype=np.uint8)
|
61 |
| -padded_data = np.pad(parsed_data, (0, pad_val)) # pad only at the end |
62 |
| -img_data = np.reshape(padded_data, (frame_count, CHOSEN_SIZE.dimension.height // 8, CHOSEN_SIZE.dimension.width // 8, 3)) |
63 | 58 |
|
| 59 | +ls = parsed_data >> 4 # shift right by 2 bits |
| 60 | +rs = parsed_data << 4 >> 4 |
| 61 | + |
| 62 | +final_data = np.insert(rs, np.arange(len(ls)), ls) * 16 |
| 63 | + |
| 64 | +n_bytes = len(final_data) # we use bytes as each pixel (r/g/b) is 1 byte (0-255) |
| 65 | +frame_count = math.ceil(n_bytes / CHOSEN_SIZE.frame_pixels) |
| 66 | +pad_val = frame_count * CHOSEN_SIZE.frame_pixels - n_bytes # how much to pad with black pixels (zeros) |
| 67 | + |
| 68 | +padded_data = np.pad(final_data, (0, pad_val)) # pad only at the end |
| 69 | +img_data = np.reshape(padded_data, (frame_count, CHOSEN_SIZE.dimension.height // 8, CHOSEN_SIZE.dimension.width // 8, 3)) |
64 | 70 | # save images to buffer
|
65 | 71 | print(f'Video duration: {frame_count} frame(s) {frame_count / FPS} second(s)')
|
66 | 72 | print('Processing frames')
|
|
79 | 85 | else:
|
80 | 86 | debug_args = '-v warning'
|
81 | 87 | process = subprocess.run(
|
82 |
| - # libaom-av1 |
83 |
| - f'ffmpeg -y -hide_banner {debug_args} -stats -f image2pipe -r {FPS} -i pipe: -c:v libaom-av1 -cpu-used 8 -row-mt true -threads 8 -tile-columns 1 -tile-rows 0 -b:v {CHOSEN_SIZE.bitrate}M -pix_fmt gbrp -crf 0 "output/{new_fn}.mp4"', |
| 88 | + # libaom-av1, libsvtav1 |
| 89 | + f'ffmpeg -y -hide_banner {debug_args} -stats -f image2pipe -r {FPS} -i pipe: -c:v libaom-av1 -preset 3 -svtav1-params tune=0:enable-overlays=1:scd=1:scm=0:crf=1:qp=1 -cpu-used 8 -row-mt true -threads 8 -tile-columns 1 -tile-rows 0 -b:v {CHOSEN_SIZE.bitrate}M -pix_fmt gbrp -crf 0 "output/{new_fn}.mp4"', |
84 | 90 | shell=True, input=img_io.getvalue(), check=True
|
85 | 91 | )
|
86 | 92 |
|
|
0 commit comments