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
- Upload to twitter. You can thread 4 images x 25 tweets at once, meaning batches of 100 images if done manually.
- Get the URL of every image you just uploaded, and put it in a file.
- Use munge_m3u8.rs to account for ordering errors when uploading.
- You can probably strip this down and avoid having to re-download all the images you just uploaded if you put an index into the cover image, or otherwise made absolutely clear the intended ordering.
- Upload the generated m3u8 from the last step somewhere.
- I uploaded mine to https://kitl.pw/m3u8/bbb_4k_twitter.m3u8
Having a local HTTP server to test things against the client I wanted to make sure would work was handy at every step of the way, which meant I could make sure that the step I was working on worked before I moved to the next step.