Okay, i wash my hands. I get all fun from this idea. Maybe I come back to it someday. So now it's your turn - do what you want, but do not forget to share your beautiful results
With good fine-tuning this method can allow you to have a nice cutscene in your game, played at full 25fps with resolution around 800x480. Most important here - size of images with video frames. Looks like what they should be not bigger than 800x800. So, just experiment. Maybe your choice will be one frame per image, or two.
Also remember what you can use
anamorphic widescreen image.
Take a look at mjpeg_player_2hq.love demo. I think it is very cool to have such video just in 8mb of data.
Another idea what can be added to this code - "adaptive bitrate". Your code can switch to lowres version if there is not enough CPU power. Add 3mb of data and you have three versions of your cutscene - HQ, normal and low. Adding automatic switch of quality depending on available CPU should be an easy task.
Or, you can make your video very low quality and low res (180x100 for example) and enhance it with some artistic shader. Take a look at mjpeg_player_shader.love. Only 1.5mb of data, but with specially created animation it can be very cool and be a part of atmosphere of your game. 7 minutes of cutscenes just in 10mb! I think its nice option.
About the idea itself:
In simple words this is just a big SpriteBatch what streams it's frames from disk (frames are loaded just before they get to the screen and almost instantly get lost).
Here are not much difference with josefnpat code. I just used jpg instead of png (this saves a lot of space) and added helper thread what loads images for me (so there is no locking, one thread loads frames, another shows animation).
Now i describe process of video preparation:
You wil need folloeing tools:
Python,
ffmpeg and
ImageMagik. this links are for WinUsers. If you with Linux, you should know what to do. (Sorty thous ones from the Mac Side, i do not know how to help you with this. Besides, you has cookies)
Now, with installed utils perform following steps:
1) Convert video to standalone frames:
Code: Select all
ffmpeg.exe -i Big_Buck_Bunny_Trailer_400p.ogg -s 640x480 -f image2 ffmpeg_temp/%05d.png
2) Combine individual frames (if you need this) With following Python script which uses montage utility from ImageMagik:
Code: Select all
#!/usr/bin/python2
import os
import math
total_frames = 813
cols = 1 # number of frames in each row
rows = 2 # number of frames in each column
frame_num = cols * rows
cmd_prefix = "montage -format jpg -quality 35 -geometry +0+0 -tile"
# Use this variant, if you want to restrict montage with only two frames in a row. do you see -tile parameter?
# cmd_prefix = "montage -format jpg -quality 35 -geometry +0+0 -tile 2x "
for j in range(0,1 + int(math.ceil(total_frames / frame_num))):
cmd = cmd_prefix
for i in range(1, frame_num + 1):
k=j * frame_num + i
if k > total_frames:
k = total_frames
cmd = cmd + str(k).zfill(5) + ".png "
cmd = cmd + "v_" + str(j + 1).zfill(5) + ".jpg"
os.system(cmd)
print (cmd)
3) Extract audio from source file:
Code: Select all
ffmpeg.exe -i big_buck_bunny_480p_stereo.ogg -vn -acodec copy audio.ogg
This is for case when source audio already in Ogg Vorbis format. If this is not true, google for proper solution.
4) Now put all this in your Love project folder. take a look at my examples, its pretty clear how this should be done.
Then, modify settings. In my main.lua they looks this way:
Code: Select all
local frame_width, frame_height = 180, 100 -- this is size of individual frame
local scale_factor = 4 -- scaling factor. In this case, resulting video will be 720x400
local frames_in_row, rows_num = 5, 5 -- How many frames in your images?
local video_fps, video_spf = 25, 1/25 -- Frames per second and seconds per frame
Now, you can play your video.
Happy hacking and don't forget to have fun!