mirror of https://github.com/AlfredoSequeida/fvid
Update docs; Add WIP testing; Speed up Cython
This commit is contained in:
parent
6a80201c18
commit
03946ac188
|
@ -7,11 +7,13 @@ Welcome to Fvid's documentation!
|
|||
================================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:maxdepth: 4
|
||||
:caption: Contents:
|
||||
|
||||
history
|
||||
howto
|
||||
examples
|
||||
errors
|
||||
|
||||
Download & Install
|
||||
==================
|
||||
|
@ -47,4 +49,6 @@ Pages
|
|||
=====
|
||||
* :doc:`/index`
|
||||
* :doc:`/history`
|
||||
* :doc:`/howto`
|
||||
* :doc:`/howto`
|
||||
* :doc:`/examples`
|
||||
* :doc:`/errors`
|
|
@ -1,6 +1,7 @@
|
|||
#cython: language_level = 3
|
||||
#cython: language_level=3
|
||||
# distutils: include_dirs = /root/fvid, /rood/fvid/tests
|
||||
from distutils.core import Extension, setup
|
||||
from Cython.Build import cythonize
|
||||
|
||||
ext = Extension(name="fvid_cython", sources=["fvid_cython.pyx"])
|
||||
ext = Extension(name="fvid_cython", sources=["fvid_cython.pyx"], include_dirs=['/root/fvid', '/root/fvid/tests'])
|
||||
setup(ext_modules=cythonize(ext, compiler_directives={'language_level': 3, 'infer_types': True}))
|
||||
|
|
57
fvid/fvid.py
57
fvid/fvid.py
|
@ -215,26 +215,34 @@ def get_bits_from_video(video_filepath: str, use_h265: bool) -> str:
|
|||
|
||||
image_sequence = []
|
||||
if use_h265:
|
||||
os.system(
|
||||
cmd = (
|
||||
"ffmpeg -i '"
|
||||
+ video_filepath
|
||||
+ "' -c:v libx265 -filter:v fps=fps="
|
||||
+ FRAMERATE
|
||||
+ " -x265-params lossless=1 -tune grain "
|
||||
+ TEMPVIDEO
|
||||
)
|
||||
+ " -x265-params lossless=1 -tune grain ")
|
||||
if NOTDEBUG:
|
||||
cmd += "-loglevel fatal " + TEMPVIDEO
|
||||
else:
|
||||
cmd += TEMPVIDEO
|
||||
os.system(cmd)
|
||||
else:
|
||||
os.system(
|
||||
cmd = (
|
||||
"ffmpeg -i '"
|
||||
+ video_filepath
|
||||
+ "' -c:v libx264rgb -filter:v fps=fps="
|
||||
+ FRAMERATE
|
||||
+ " "
|
||||
+ TEMPVIDEO
|
||||
)
|
||||
os.system(
|
||||
"ffmpeg -i " + TEMPVIDEO + " ./fvid_frames/decoded_frames_%d.png"
|
||||
)
|
||||
+ " ")
|
||||
if NOTDEBUG:
|
||||
cmd += "-loglevel fatal " + TEMPVIDEO
|
||||
else:
|
||||
cmd += TEMPVIDEO
|
||||
os.system(cmd)
|
||||
|
||||
cmd = "ffmpeg -i " + TEMPVIDEO + " ./fvid_frames/decoded_frames_%d.png"
|
||||
if NOTDEBUG:
|
||||
cmd += " -loglevel fatal"
|
||||
os.system(cmd)
|
||||
os.remove(TEMPVIDEO)
|
||||
|
||||
for filename in sorted(
|
||||
|
@ -310,8 +318,9 @@ def save_bits_to_file(
|
|||
in_ = io.BytesIO()
|
||||
in_.write(bitstring.bytes)
|
||||
in_.seek(0)
|
||||
# DOES NOT WORK IF WE DONT CHECK BUFFER, UNSURE WHY
|
||||
# always fails without this but sometimes work with this, unsure why
|
||||
filetype = magic.from_buffer(in_.read())
|
||||
print(filetype)
|
||||
in_.seek(0)
|
||||
with gzip.GzipFile(fileobj=in_, mode="rb") as fo:
|
||||
bitstring = fo.read()
|
||||
|
@ -418,27 +427,33 @@ def make_video(output_filepath: str, framerate: int = FRAMERATE, use_h265: bool
|
|||
output_filepath -- the output file path where to store the video
|
||||
framerate -- the framerate for the vidoe (default 1)
|
||||
"""
|
||||
|
||||
|
||||
if output_filepath == None:
|
||||
outputfile = "file.mp4"
|
||||
else:
|
||||
outputfile = output_filepath
|
||||
|
||||
if use_h265:
|
||||
os.system(
|
||||
cmd = (
|
||||
"ffmpeg -r "
|
||||
+ framerate
|
||||
+ " -i ./fvid_frames/encoded_frames_%d.png -c:v libx265 "
|
||||
+ " -x265-params lossless=1 -tune grain "
|
||||
+ outputfile
|
||||
)
|
||||
+ " -x265-params lossless=1 -tune grain ")
|
||||
if NOTDEBUG:
|
||||
cmd += "-loglevel fatal " + outputfile
|
||||
else:
|
||||
cmd += outputfile
|
||||
os.system(cmd)
|
||||
else:
|
||||
os.system(
|
||||
cmd = (
|
||||
"ffmpeg -r "
|
||||
+ framerate
|
||||
+ " -i ./fvid_frames/encoded_frames_%d.png -c:v libx264rgb "
|
||||
+ outputfile
|
||||
)
|
||||
+ " -i ./fvid_frames/encoded_frames_%d.png -c:v libx264rgb ")
|
||||
if NOTDEBUG:
|
||||
cmd += "-loglevel fatal " + outputfile
|
||||
else:
|
||||
cmd += outputfile
|
||||
os.system(cmd)
|
||||
|
||||
def cleanup():
|
||||
"""
|
||||
|
|
6221
fvid/fvid_cython.c
6221
fvid/fvid_cython.c
File diff suppressed because it is too large
Load Diff
|
@ -1,45 +1,40 @@
|
|||
# distutils: language=c
|
||||
# distutils: language=c++
|
||||
# cython: boundscheck=False
|
||||
# cython: cdivision=True
|
||||
# cython: wraparound=False
|
||||
# cython: c_string_type=unicode, c_string_encoding=ascii
|
||||
|
||||
from libcpp.string cimport string
|
||||
|
||||
cpdef str cy_gbfi(image):
|
||||
cdef int width, height, x, y
|
||||
cdef str pixel_bin_rep, bits
|
||||
cdef string bits = b''
|
||||
cdef (int, int, int) pixel
|
||||
|
||||
width, height = image.size
|
||||
|
||||
px = image.load()
|
||||
bits = ""
|
||||
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
pixel = px[x, y]
|
||||
|
||||
pixel_bin_rep = <str>"0"
|
||||
|
||||
# if the white difference is smaller (comparison part 1), that means the pixel is closer
|
||||
# to white, otherwise, the pixel must be black
|
||||
if abs(pixel[0] - 255) < abs(pixel[0] - 0) and abs(pixel[1] - 255) < abs(pixel[1] - 0) and abs(pixel[2] - 255) < abs(pixel[2] - 0):
|
||||
pixel_bin_rep = <str>"1"
|
||||
|
||||
# adding bits
|
||||
bits += pixel_bin_rep
|
||||
bits.append(b'1' if abs(pixel[0] - 255) < abs(pixel[0] - 0) and abs(pixel[1] - 255) < abs(pixel[1] - 0) and abs(pixel[2] - 255) < abs(pixel[2] - 0) else b'0')
|
||||
|
||||
return bits
|
||||
|
||||
cpdef str cy_gbfi_h265(image):
|
||||
cdef int width, height, x, y
|
||||
cdef str bits
|
||||
cdef string bits = b''
|
||||
|
||||
width, height = image.size
|
||||
|
||||
px = image.load()
|
||||
bits = ""
|
||||
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
bits += "1" if px[x, y] == 255 else "0"
|
||||
bits.append(b'1' if px[x, y] == 255 else b'0')
|
||||
|
||||
return bits
|
|
@ -1,5 +1,5 @@
|
|||
Pillow
|
||||
Pillow>=7.0.0
|
||||
tqdm>=4.25.0
|
||||
bitstring
|
||||
tqdm
|
||||
pycryptography
|
||||
zfec
|
Loading…
Reference in New Issue