How could I make a frames file like this to play on my Arduboy?
I used a free image viewer called IrfanView to extract all frames from a video and then used itās batch conversion option to convert all frames to 128x64 1-bit bitmaps. To combine the images into a single data file I used the below python script.
IrfanView
- Open video with IrfanView > Option > Extract all frames > choose a folder > wait
- File > batch conversion > browse to the folder in the upper right > click add all
- Choose output format bitmap
- check use advanced options > click advanced >
- if you want to cut out a 2:1 window of the video frame, check Crop option calculate the x,y position and height and width. Make sure Start is set to Left Top
- Check risize option and enter 128 and 64 pixles
- Check change color depth and select 2 colors
- under miscellanous check overwrite existion files and click OK to return to batch conversion screen
*Select an output folder to save the converter images too. (Click on āuse current look in folderā and add āconvertedā to the path)
*click āStart batchā and wait
Python script
copy and paste the below script into a new text file and save it as frames-to-bin.py then drag and drop one of the frames onto the script and it will create a bin file with all the 1K frames.
import sys
import os
from PIL import Image
filename = os.path.abspath(sys.argv[1])
ext = os.path.splitext(filename)[1]
name = filename[:filename.rfind("_")]
digits = (len(filename)-len(name)-5)
f = open("{}s.bin".format(name),'wb')
frame = 0
while True:
framestr=str(frame)
framefilename = "{}_{}{}{}".format(name, (digits - len(framestr)) * '0', framestr, ext)
if os.path.isfile(framefilename):
sys.stdout.write("saving frame {}\r".format(frame))
sys.stdout.flush()
img = Image.open(framefilename).convert("1")
width, height = img.size
pixels = list(img.getdata())
b = 0
row = bytearray(width)
for y in range (0,64,8):
for x in range (0,width):
for p in range (0,8):
b = b >> 1
if pixels[(y + p) * width + x] > 0:
b |= 0x80
row[x] = b
f.write(row)
frame +=1
else:
break
f.close()
Thank you very much.
I know I did this before, I think @mr.blinky gave me this python file directly. Itās not published is it? I think you didnāt put it in your python tools because you donāt think itās ready?
Just in case someone wants an (open source) command-line based alternative (e.g. for better automation/batching), ffmpeg can also do this.
(Some example frame extraction commands here.)
Yeah I gave you a slightly different version. This version is a bit better. Itās not published (elsewhere). Still needs some form of compression
Interesting, didnāt know about ffmpeg.
@Mr.Blinky I have another problem. In your ābadapple-frames.binā file, some frames might have damaged. Could you fix it at your convenience?
Here is the video showing where the problem is.
Ha! good eye! Thanks for showing where it went wrong. It seems the conversion on white the screens there went wrong.
Iāve updated the badapple-frames.bin file
Thank you.