mirror of https://github.com/AlfredoSequeida/fvid
rename variables, more comments, misc other stuff
This commit is contained in:
parent
b36143c09a
commit
701b78ddac
|
@ -113,4 +113,5 @@ fvid/*.txt
|
||||||
fvid/*.jpg
|
fvid/*.jpg
|
||||||
fvid/*.png
|
fvid/*.png
|
||||||
fvid/*.lprof
|
fvid/*.lprof
|
||||||
|
fvid/fvid_cython.html
|
||||||
|
|
||||||
|
|
34
fvid/fvid.py
34
fvid/fvid.py
|
@ -12,6 +12,7 @@ import gzip
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
import decimal
|
import decimal
|
||||||
|
import random
|
||||||
|
|
||||||
from zfec import easyfec as ef
|
from zfec import easyfec as ef
|
||||||
|
|
||||||
|
@ -37,9 +38,12 @@ NOTDEBUG = True
|
||||||
TEMPVIDEO = "_temp.mp4"
|
TEMPVIDEO = "_temp.mp4"
|
||||||
FRAMERATE = "1"
|
FRAMERATE = "1"
|
||||||
|
|
||||||
# DO NOT CHANGE
|
# DO NOT CHANGE: (2, 3) WORKS SOMETIMES
|
||||||
|
# BUT SOMEHOW THIS IS THE ONLY COMBO THAT ALWAYS WORKS
|
||||||
KVAL = 4
|
KVAL = 4
|
||||||
MVAL = 5
|
MVAL = 5
|
||||||
|
# THIS CAN BE ANY POWER OF 2 BUT MUST STAY SAME BETWEEN ENCODING/DECODING
|
||||||
|
# RECOMMENDED 8-64
|
||||||
BLOCK = 16
|
BLOCK = 16
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,8 +165,7 @@ def get_bits_from_image(image: Image) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if use_cython:
|
if use_cython:
|
||||||
bits = cy_gbfi(image)
|
return cy_gbfi(image)
|
||||||
return bits
|
|
||||||
|
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
|
||||||
|
@ -235,9 +238,6 @@ def get_bits_from_video(video_filepath: str) -> str:
|
||||||
def decode_zfec(data_bytes: bytes) -> bytes:
|
def decode_zfec(data_bytes: bytes) -> bytes:
|
||||||
global KVAL, MVAL, BLOCK
|
global KVAL, MVAL, BLOCK
|
||||||
|
|
||||||
KVAL = 4
|
|
||||||
MVAL = 5
|
|
||||||
|
|
||||||
byte_list = split_string_by_n(data_bytes, int(BLOCK*(MVAL/KVAL)))
|
byte_list = split_string_by_n(data_bytes, int(BLOCK*(MVAL/KVAL)))
|
||||||
|
|
||||||
# appending to a single bytes object is very slow so we make 50-51 and combine at the end
|
# appending to a single bytes object is very slow so we make 50-51 and combine at the end
|
||||||
|
@ -249,26 +249,26 @@ def decode_zfec(data_bytes: bytes) -> bytes:
|
||||||
i = 0
|
i = 0
|
||||||
for b in tqdm(byte_list):
|
for b in tqdm(byte_list):
|
||||||
base = split_string_by_n(b, len(b) // MVAL)
|
base = split_string_by_n(b, len(b) // MVAL)
|
||||||
idk = decoder.decode(base[:KVAL], list(range(KVAL)), 0)
|
decoded_str_1 = decoder.decode(base[:KVAL], list(range(KVAL)), 0)
|
||||||
idk2 = decoder.decode(base[1:KVAL+1], list(range(KVAL+1))[1:], 0)
|
decoded_str_2 = decoder.decode(base[1:KVAL+1], list(range(KVAL+1))[1:], 0)
|
||||||
if idk == idk2:
|
if decoded_str_1 == decoded_str_2:
|
||||||
decoded_bytes[i//50] += idk
|
decoded_bytes[i//50] += decoded_str_1
|
||||||
else: # its corrupted here
|
else: # its corrupted here
|
||||||
j = 10
|
j = 10
|
||||||
while j > 0 and idk != idk2:
|
while j > 0 and decoded_str_1 != decoded_str_2:
|
||||||
random.shuffle(base)
|
random.shuffle(base)
|
||||||
idk = decoder.decode(base[:KVAL], list(range(KVAL)), 0)
|
decoded_str_1 = decoder.decode(base[:KVAL], list(range(KVAL)), 0)
|
||||||
idk2 = decoder.decode(base[1:KVAL+1], list(range(KVAL+1))[1:], 0)
|
decoded_str_2 = decoder.decode(base[1:KVAL+1], list(range(KVAL+1))[1:], 0)
|
||||||
j -= 1
|
j -= 1
|
||||||
decoded_bytes[i//50] += idk # it should be correct by now
|
decoded_bytes[i//50] += decoded_str_1 # it should be correct by now
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
decoded_bytes2 = bytes()
|
decoded_bytestring = bytes()
|
||||||
|
|
||||||
for bytestring in tqdm(decoded_bytes):
|
for bytestring in tqdm(decoded_bytes):
|
||||||
decoded_bytes2 += bytestring
|
decoded_bytestring += bytestring
|
||||||
|
|
||||||
return decoded_bytes2
|
return decoded_bytestring
|
||||||
|
|
||||||
|
|
||||||
def save_bits_to_file(
|
def save_bits_to_file(
|
||||||
|
|
3125
fvid/fvid_cython.c
3125
fvid/fvid_cython.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue