mirror of https://github.com/AlfredoSequeida/fvid
Merge branch 'master' into patch-2
This commit is contained in:
commit
d656ae8ac1
|
@ -102,3 +102,6 @@ venv.bak/
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
|
|
||||||
|
# Ignore output files
|
||||||
|
fvid_frames/
|
||||||
|
|
12
README.md
12
README.md
|
@ -1,9 +1,11 @@
|
||||||
fvid is a project that aims to encode any file as a video using 1-bit color images
|
|
||||||
to survive compression algorithms for data retrieval.
|
|
||||||
|
|
||||||
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)
|
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)
|
||||||
[![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/)
|
[![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)](https://pypi.python.org/pypi/ansicolortags/)
|
||||||
|
|
||||||
|
[Demonstration/Explanation Video](https://youtu.be/yu_ZIr0q5rU)
|
||||||
|
|
||||||
|
fvid is a project that aims to encode any file as a video using 1-bit color images
|
||||||
|
to survive compression algorithms for data retrieval.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://i.imgur.com/LVthky0.png" alt="fvid">
|
<img src="https://i.imgur.com/LVthky0.png" alt="fvid">
|
||||||
</br>
|
</br>
|
||||||
|
@ -13,7 +15,7 @@ to survive compression algorithms for data retrieval.
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
Requires installation of [FFmpeg](https://ffmpeg.org/download.html) first, then install using pip3
|
Requires installation of [FFmpeg](https://ffmpeg.org/download.html) and libmagic first, then install using pip3
|
||||||
|
|
||||||
Linux/macOS
|
Linux/macOS
|
||||||
|
|
||||||
|
@ -69,4 +71,4 @@ py -m fvid -i [input video] -d
|
||||||
3. Write a test which shows that the bug was fixed or that the feature
|
3. Write a test which shows that the bug was fixed or that the feature
|
||||||
works as expected.
|
works as expected.
|
||||||
4. Send a pull request and bug the maintainer until it gets merged and
|
4. Send a pull request and bug the maintainer until it gets merged and
|
||||||
published. :)
|
published. :)
|
||||||
|
|
32
fvid/fvid.py
32
fvid/fvid.py
|
@ -108,7 +108,7 @@ def get_bits_from_video(video_filepath):
|
||||||
return bits
|
return bits
|
||||||
|
|
||||||
|
|
||||||
def save_bits_to_file(filepath, bits):
|
def save_bits_to_file(file_path, bits):
|
||||||
# get file extension
|
# get file extension
|
||||||
|
|
||||||
bitstring = Bits(bin=bits)
|
bitstring = Bits(bin=bits)
|
||||||
|
@ -116,8 +116,15 @@ def save_bits_to_file(filepath, bits):
|
||||||
mime = Magic(mime=True)
|
mime = Magic(mime=True)
|
||||||
mime_type = mime.from_buffer(bitstring.tobytes())
|
mime_type = mime.from_buffer(bitstring.tobytes())
|
||||||
|
|
||||||
|
# If filepath not passed in use defualt
|
||||||
|
# otherwise used passed in filepath
|
||||||
|
if file_path == None:
|
||||||
|
filepath = f"file{mimetypes.guess_extension(type=mime_type)}"
|
||||||
|
else:
|
||||||
|
filepath = file_path
|
||||||
|
|
||||||
with open(
|
with open(
|
||||||
f"{filepath}/file{mimetypes.guess_extension(type=mime_type)}", "wb"
|
filepath, "wb"
|
||||||
) as f:
|
) as f:
|
||||||
bitstring.tofile(f)
|
bitstring.tofile(f)
|
||||||
|
|
||||||
|
@ -159,12 +166,18 @@ def make_image_sequence(bitstring, resolution=(1920, 1080)):
|
||||||
|
|
||||||
def make_video(output_filepath, image_sequence, framerate="1/5"):
|
def make_video(output_filepath, image_sequence, framerate="1/5"):
|
||||||
|
|
||||||
|
if output_filepath == None:
|
||||||
|
outputfile = "file.mp4"
|
||||||
|
else:
|
||||||
|
outputfile = output_filepath
|
||||||
|
|
||||||
|
|
||||||
frames = glob.glob(f"{FRAMES_DIR}encoded_frames*.png")
|
frames = glob.glob(f"{FRAMES_DIR}encoded_frames*.png")
|
||||||
|
|
||||||
# for one frame
|
# for one frame
|
||||||
if len(frames) == 1:
|
if len(frames) == 1:
|
||||||
ffmpeg.input(frames[0], loop=1, t=1).output(
|
ffmpeg.input(frames[0], loop=1, t=1).output(
|
||||||
output_filepath, vcodec="libx264rgb"
|
outputfile, vcodec="libx264rgb"
|
||||||
).run(quiet=True)
|
).run(quiet=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -172,7 +185,8 @@ def make_video(output_filepath, image_sequence, framerate="1/5"):
|
||||||
f"{FRAMES_DIR}encoded_frames*.png",
|
f"{FRAMES_DIR}encoded_frames*.png",
|
||||||
pattern_type="glob",
|
pattern_type="glob",
|
||||||
framerate=framerate,
|
framerate=framerate,
|
||||||
).output(output_filepath, vcodec="libx264rgb").run(quiet=True)
|
).output(outputfile, vcodec="libx264rgb").run(quiet=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cleanup():
|
def cleanup():
|
||||||
|
@ -209,14 +223,12 @@ def main():
|
||||||
if args.decode:
|
if args.decode:
|
||||||
bits = get_bits_from_video(args.input)
|
bits = get_bits_from_video(args.input)
|
||||||
|
|
||||||
file_path = ""
|
file_path = None
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
file_path = args.output
|
file_path = args.output
|
||||||
else:
|
|
||||||
file_path = "./"
|
|
||||||
|
|
||||||
save_bits_to_file("./", bits)
|
save_bits_to_file(file_path, bits)
|
||||||
|
|
||||||
elif args.encode:
|
elif args.encode:
|
||||||
# isdigit has the benefit of being True and raising an error if the user passes a negative string
|
# isdigit has the benefit of being True and raising an error if the user passes a negative string
|
||||||
|
@ -235,12 +247,10 @@ def main():
|
||||||
f"{FRAMES_DIR}encoded_frames_{index}.png"
|
f"{FRAMES_DIR}encoded_frames_{index}.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
video_file_path = ""
|
video_file_path = None
|
||||||
|
|
||||||
if args.output:
|
if args.output:
|
||||||
video_file_path = args.output
|
video_file_path = args.output
|
||||||
else:
|
|
||||||
video_file_path = "./file.mp4"
|
|
||||||
|
|
||||||
make_video(video_file_path, image_sequence, args.framerate)
|
make_video(video_file_path, image_sequence, args.framerate)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue