Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
true-drivePublic archive

About

The core of True Drive, responsible for encoding and decoding files

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Latest commit

 

History

49 Commits

Folders and files

Repository files navigation

True Drive logo

True Drive Core

True Drive stores files as noise videos, so that any platform that hosts video can double as file storage. A file goes in, a video of black and white pixels comes out, and that video can later be turned back into the original file.

This repository holds the conversion step as a small C library: one public header and its implementation. Command-line tools, uploading, and downloading are built on top of it, in separate projects.

Warning

Videos are not encrypted. Anyone with the video and this library can recover the file, so encrypt anything sensitive before encoding it.

How it works

Encoding

  1. A 16-byte header is placed before the file's contents, holding a marker, the file's size, and a CRC-32 checksum.
  2. Each bit becomes one pixel, black for 0 and white for 1, on 2048×2048 frames. Each frame holds 512 KiB of data.
  3. FFmpeg assembles the 1-bit frames into a lossless video of PNG images at 30 fps, saved as .mkv.

Decoding reverses this: FFmpeg extracts the frames, and the file is only accepted if the frames are still 1-bit and the header, frame count, and checksum all match. A video that is incomplete, altered, or re-compressed is rejected.

A video is about the size of its input. A 2 MiB file of random data produces a video of about 2.1 MB, files that compress well produce smaller videos than the original, and the smallest videos are a little over 1 KB.

Requirements

  • gcc and CMake 3.21 or newer to build (MSYS2 is one way to get them on Windows)
  • FFmpeg 5.1 or newer on your PATH at run time

The library targets Windows (MSYS2 UCRT64) and Linux. macOS is untested.

Build

cmake -B build
cmake --build build

This produces build/libtruedrive.a. Delete the build folder to remove the build output.

Tests

ctest --test-dir build --output-on-failure

The tests need FFmpeg. To also check for memory errors, use a toolchain that includes the address and undefined-behavior sanitizers:

cmake -B build/sanitize -DTRUEDRIVE_SANITIZE=ON
cmake --build build/sanitize
ctest --test-dir build/sanitize --output-on-failure

Using a container

This opens a shell in an Alpine container that has the compiler, CMake, and FFmpeg installed, with the repository mounted at /app:

docker build -f .devcontainer/Containerfile.dev -t truedrive-core-dev .devcontainer
docker run -it --rm -v "$PWD":/app truedrive-core-dev

If you use Podman, replace docker with podman. In Git Bash on Windows, put MSYS_NO_PATHCONV=1 before docker run.

Using VS Code

The repository includes a dev container with the same tools, plus gdb, git, and the C/C++ extension.

  1. Install the Dev Containers extension.
  2. If you use Podman, set dev.containers.dockerPath to podman in your VS Code user settings.
  3. Run Dev Containers: Reopen in Container from the Command Palette.

Then use the VS Code terminal to run the build and test commands above.

Usage

The whole API is in include/truedrive.h:

TdStatus tdEncode(const char *inputPath, const char *outputPath, const char *workDir);
TdStatus tdDecode(const char *inputPath, const char *outputPath, const char *workDir);
const char *tdStatusMessage(TdStatus status);

For example, to encode a file:

#include <stdio.h>
#include "truedrive.h"

int main(void)
{
  // "frames" must already exist and be empty
  TdStatus status = tdEncode("input.txt", "video.mkv", "frames");
  if (status != TD_OK)
  {
    fprintf(stderr, "%s\n", tdStatusMessage(status));
    return 1;
  }

  return 0;
}

In a CMake project, add this repository as a subdirectory and link its target:

add_subdirectory(core)
target_link_libraries(app PRIVATE truedrive::truedrive)

Or compile against the header and link the archive directly:

gcc app.c -I<core>/include <core>/build/libtruedrive.a -o app

The video only stores the file's contents, not its name, so pass the full file name you want to tdDecode, including the extension.

Working directory

Each call writes the video's frames into workDir, which must be an existing, empty directory. The library leaves the frames there, even when a call fails, so delete the directory when you are done with it. Encoding a 2 MiB file leaves about 2.6 MB behind.

Library guarantees

The library reports every failure through TdStatus. It never exits the process, prints to the terminal, or keeps global state, so concurrent calls are safe as long as each one has its own workDir.

Known limitations

  • Input files must be smaller than 64 MiB.
  • Only .mkv videos can be decoded.
  • On Windows, paths can't contain " or %.
  • There is no error correction, so decoding needs every pixel to be intact. Platforms such as YouTube re-compress uploads, which makes decoding fail with TD_ERR_INVALID_INPUT.
  • Videos are stored as PNG images inside Matroska, which many media players and upload sites don't support.
  • Videos made by earlier versions, which ended in red pixels, can't be decoded.

License

Apache License 2.0

About

The core of True Drive, responsible for encoding and decoding files

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages