Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Encoding a file as a Youtube video - https://www.youtube.com/watch?v=hyqLv2_zBdA
# Encode inputfile.tar.gz as a series of video frames
# Frames are written to frames/frameNNNN.png
from PIL import Image
with open('inputfile.tar.gz', 'rb') as f:
data = f.read()
WIDTH = 120
HEIGHT = 90
CHUNK_SIZE = int((WIDTH * HEIGHT) / 8)
chunks = []
offset = 0
while offset < len(data):
chunks.append(data[offset:offset+CHUNK_SIZE])
offset += CHUNK_SIZE
for frame_num, chunk in enumerate(chunks):
padded_chunk = chunk + (b'\0' * (CHUNK_SIZE - len(chunk)))
img = Image.frombytes('1', (WIDTH, HEIGHT), padded_chunk)
img.save('frames/frame%04d.png' % (frame_num + 1))
# Encode as video with:
# ffmpeg -i frames/frame%04d.png -vf scale=1440:1080 -sws_flags neighbor -vcodec ffv1 output.mkv
# Decode the resulting downloaded video with:
# ffmpeg -i downloaded.mkv -vf scale=120:-1,eq=contrast=10 -sws_flags neighbor -pix_fmt monob -f rawvideo result.tar.gz
@stefanbosch

This comment has been minimized.

Copy link

@stefanbosch stefanbosch commented Oct 27, 2020

This is fun to play with! 👍 Thanks for sharing

@SasquatchYuja

This comment has been minimized.

Copy link

@SasquatchYuja SasquatchYuja commented Nov 17, 2020

good occasion to mention http://decss.zoy.org

@hazarek

This comment has been minimized.

Copy link

@hazarek hazarek commented Nov 24, 2020

I'm trying to improve this idea;
https://github.com/hazarek/fif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.