Giter Club home page Giter Club logo

bin2video's Introduction

bin2video

A C program for encoding anything as a video file. Inspired by Infinite-Storage-Glitch. Supports Windows, macOS and Linux.

Demo

Demo

(Scene from Big Buck Bunny, Copyright 2008, Blender Foundation / https://www.bigbuckbunny.org)

This GIF file can be decoded with bin2video to extract the peppers test image.

Comparison

bin2video Infinite-Storage-Glitch Infinity-Drive
Encode¹ ⚡️ 253s² 595s 572s
Decode¹ ⚡️ 34s 531s 702s
Custom encoding options
Custom resolution
Custom bits-per-pixel ✅ All values from 1 bit to 24 bits Only 1 bit or 24 bits
Embeddable³ ✅ with embed.sh
Pipe support

¹ Tests were done with a randomly generated 32MB test file on an M1 MacBook Air.
² Depends on FFmpeg options. Goes down to 106 seconds with -- -c:v png.
³ File data can be embedded into a real video. See demo.

Building

Windows: bin2video can be compiled with w64devkit.
macOS: Make sure command line tools are installed with xcode-select --install.
Linux: Make sure build-essential or equivalent is installed.

cc src/*.c -lm -O3 -o bin2video

Dependencies

You must have ffmpeg and ffprobe in your PATH to use this program.

Usage

USAGE:
  ./bin2video [options] -e -i data.bin -o video.mp4
  ./bin2video [options] -d -i video.mp4 -o data.bin

OPTIONS:
  -e          Encode mode. Takes an input binary file and produces
              a video file.
  -d          Decode mode. Takes an input video file and produces
              the original binary file.
  -i          Input file. Defaults to stdin.
  -o          Output file. Defaults to stdout.
  -t          Allows writing output to a tty.
  -f <rate>   Framerate. Defaults to 10. Set to -1 to let FFmpeg
              decide.
  -c <n>      Write every frame n times. Defaults to 1. Cannot be
              used with -I.
  -b <bits>   Bits per pixel. Defaults to 1 (black and white).
  -w <width>  Video width. Defaults to 1280.
  -h <height> Video height. Defaults to 720.
  -H <height> Data height. Set this to a value less than the video
              height to limit the data blocks to a region on top of
              the video. The bottom of the region will be black.
              A value of -1 disables the data height. Defaults to -1.
              Cannot be used with -I.
  -s <size>   Size of each block. Defaults to 5.
  -I          Infinite-Storage-Glitch compatibility mode.
  -E          End the output with a black frame. Cannot be used with
              -I.

ADVANCED OPTIONS:
  -S <size>   Sets the size of each block for the initial frame.
              Defaults to 10. Do not change this unless you have
              a good reason to do so. If you specify this flag
              while encoding, you will also need to do it while
              decoding. When -I is used, this value defaults to 5
              and cannot be changed.
  --          Options following -- will be treated as arguments for
              FFmpeg. Defaults to "-c:v libx264 -pix_fmt yuv420p".
              Has no effect in decode mode.

Usage Examples

# Encode archive.zip as a video
./bin2video -e -i archive.zip -o archive.zip.mp4

# Encode archive.zip as a video, storing 3 bits in each pixel
./bin2video -e -b 3 -i archive.zip -o archive.zip.mp4

# Encode archive.zip as a video at 1920x1080 resolution
./bin2video -e -h 1920 -w 1080 -i archive.zip -o archive.zip.mp4

# Extract archive.zip from the video
./bin2video -d -i archive.zip.mp4 -o archive.zip

# Decode video encoded with Infinite-Storage-Glitch
# (Example video taken from Infinite-Storage-Glitch README.md)
yt-dlp -f 247 -o isg-video.webm 'https://www.youtube.com/watch?v=8I4fd_Sap-g'
./bin2video -I -d -i isg-video.webm -o archive.zip

# Encode file.bin and merge it with video.mp4 to generate
# video-out.mp4
./embed.sh file.bin video.mp4 video-out.mp4

bin2video's People

Contributors

pixelomer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bin2video's Issues

Add docker

Please consider dockerizing the application, since adding docker could help run the program more easily.

bin2video and Infinite-Storage-Glitch output different data with compressed/corrupted video files

The corruption rate is low enough that sometimes the issue is not noticeable unless the file is compared to the original. However, other times it is immediately obvious since the resulting file becomes unusable. For example, an mp4 file might lose its video stream and act like an audio file or a zip file might throw out CRC errors while extracting.

(This issue is not reproducible with the example in the README.md file.)

Decoded files contain trailling null bytes in Infinite-Storage-Glitch compatibility mode

Infinite-Storage-Glitch includes the total file size in the first frame unlike bin2video which normally includes the number of valid pixels every frame. This makes it possible to pipe input from other programs into bin2video but it also makes it incompatible with Infinite-Storage-Glitch. A separate way of detecting EOF should be implemented for Infinite-Storage-Glitch that relies on the file size included in the first frame.

Decoded files contain a trailing null byte if bits_per_pixel is divisible by 8

Reproduction steps:

# Create a file containing random data (shell expansion used for cross-platform compatibility)
dd if=/dev/urandom bs=$((1024 * 1024)) count=2 of=data.bin

# Encode with 8 bits per pixel
./bin2video -b 8 -s 8 -w 1920 -h 1080 -e -i data.bin -o data.bin.mp4

# Decode
./bin2video -d -i data.bin.mp4 -o data-out.bin

data-out.bin will be exactly 1 byte larger than data.bin and the extra byte will be a null byte.

Can we make this program more efficient (Enhancement)

Memory Improvement

I tried to compile some medium sized zip and rar files it works fine with that but if we are to encode a large file about 1gb its very slow maybe ram consumption can be set so the process should be fast as for now encoding at kb's speed would take a whole day for a large file. I have seen in dvorakDwarf repo that if we compile large files the program gets interrupted due to poor ram usage. Can u tell us if this has any loopholes like (isg)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.