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.
Encoding
- A 16-byte header is placed before the file's contents, holding a marker, the file's size, and a CRC-32 checksum.
- Each bit becomes one pixel, black for
0and white for1, on 2048×2048 frames. Each frame holds 512 KiB of data. - 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.
gccand CMake 3.21 or newer to build (MSYS2 is one way to get them on Windows)- FFmpeg 5.1 or newer on your
PATHat run time
The library targets Windows (MSYS2 UCRT64) and Linux. macOS is untested.
cmake -B build
cmake --build buildThis produces build/libtruedrive.a. Delete the build folder to remove the build output.
ctest --test-dir build --output-on-failureThe 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-failureThis 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-devIf you use Podman, replace docker with podman. In Git Bash on Windows, put MSYS_NO_PATHCONV=1 before docker run.
The repository includes a dev container with the same tools, plus gdb, git, and the C/C++ extension.
- Install the Dev Containers extension.
- If you use Podman, set
dev.containers.dockerPathtopodmanin your VS Code user settings. - Run Dev Containers: Reopen in Container from the Command Palette.
Then use the VS Code terminal to run the build and test commands above.
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 appThe video only stores the file's contents, not its name, so pass the full file name you want to tdDecode, including the extension.
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.
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.
- Input files must be smaller than 64 MiB.
- Only
.mkvvideos 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.