This is the collection of code I wrote to upload 4k60 video to twitter.
The order of steps was as follows:
- Use ffmpeg to segment and/or re-encode video. The important part is to reduce the segments to under 5MB in size, each.
- I used this command line:
ffmpeg -y -i ..\bbb_sunflower_2160p_60fps_normal.mp4 -codec copy -bsf:v h264_mp4toannexb -map 0 -f segment -segment_time 0.1 -segment_list "bbb_4k.m3u8" -segment_list_type m3u8 "bbb-%d.ts"
- This resulted in 1269 segments for me to handle.
- I used this command line:
- Use generate_file_packing.py to solve the bin packing problem for the set of segments. I set the bin size to 5MiB - 8KiB, knowing I had a 4KiB image for the cover file.
- I used the DVD logo as my cover image, and set the second palette color for each one to hsv(pack_index, 255, 255)
- Use pack_segments.rs to generate png files packed according to the solution file generated by the previous step.
- This resulted in 250 png files for me to upload to twitter