mirror of
https://github.com/leminlimez/Nugget.git
synced 2025-04-08 04:23:05 +08:00
converting videos to mov + auto get thumbnail
This commit is contained in:
@@ -31,8 +31,11 @@ def wrap_in_aar(input_file, input_mov, output_file):
|
||||
# Hardcoded settlingEffect.mov header
|
||||
header2 = bytearray.fromhex("4141303129005459503146504154501200736574746C696E674566666563742E6D6F7644415441F4B8")
|
||||
|
||||
with open(input_mov, 'rb') as f:
|
||||
file_data2 = f.read()
|
||||
if isinstance(input_mov, bytes):
|
||||
file_data2 = input_mov
|
||||
else:
|
||||
with open(input_mov, 'rb') as f:
|
||||
file_data2 = f.read()
|
||||
|
||||
file_size2 = len(file_data2)
|
||||
|
||||
|
||||
39
controllers/video_handler.py
Normal file
39
controllers/video_handler.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import ffmpeg
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import ffmpeg.stream
|
||||
import ffmpeg.video
|
||||
|
||||
def convert_to_mov(input_file: str, output_file: str = None):
|
||||
# if there is no output file specified, create a temp file then return contents
|
||||
if output_file == None:
|
||||
with NamedTemporaryFile("rb+", suffix=".mov") as tmp:
|
||||
convert_to_mov(input_file, tmp)
|
||||
contents = tmp.read()
|
||||
return contents
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_file)
|
||||
.output(output_file, vcodec='copy', acodec='copy', format='mov')
|
||||
.run()
|
||||
)
|
||||
|
||||
def get_thumbnail_from_mov(input_file: str, output_file: str = None):
|
||||
# if there is no output file specified, create a temp file and then return contents
|
||||
if output_file == None:
|
||||
with NamedTemporaryFile("rb+", suffix=".heic") as tmp:
|
||||
get_thumbnail_from_mov(input_file, tmp)
|
||||
contents = tmp.read()
|
||||
return contents
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_file, ss=0)
|
||||
.output(output_file, vframes=1, format='heic')
|
||||
.run()
|
||||
)
|
||||
|
||||
def get_thumbnail_from_contents(contents: bytes, output_file: str = None):
|
||||
with NamedTemporaryFile("rb+", suffix=".heic") as inp_file:
|
||||
inp_file.write(contents)
|
||||
contents = get_thumbnail_from_mov(inp_file, output_file)
|
||||
return contents
|
||||
Reference in New Issue
Block a user