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
|
# Hardcoded settlingEffect.mov header
|
||||||
header2 = bytearray.fromhex("4141303129005459503146504154501200736574746C696E674566666563742E6D6F7644415441F4B8")
|
header2 = bytearray.fromhex("4141303129005459503146504154501200736574746C696E674566666563742E6D6F7644415441F4B8")
|
||||||
|
|
||||||
with open(input_mov, 'rb') as f:
|
if isinstance(input_mov, bytes):
|
||||||
file_data2 = f.read()
|
file_data2 = input_mov
|
||||||
|
else:
|
||||||
|
with open(input_mov, 'rb') as f:
|
||||||
|
file_data2 = f.read()
|
||||||
|
|
||||||
file_size2 = len(file_data2)
|
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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pymobiledevice3
|
pymobiledevice3
|
||||||
PySide6-Essentials
|
PySide6-Essentials
|
||||||
PyInstaller
|
PyInstaller
|
||||||
|
ffmpeg-python
|
||||||
@@ -10,6 +10,7 @@ from .tweak_classes import Tweak
|
|||||||
from Sparserestore.restore import FileToRestore
|
from Sparserestore.restore import FileToRestore
|
||||||
from controllers.plist_handler import set_plist_value
|
from controllers.plist_handler import set_plist_value
|
||||||
from controllers.files_handler import get_bundle_files
|
from controllers.files_handler import get_bundle_files
|
||||||
|
from controllers import video_handler
|
||||||
from controllers.aar.aar import wrap_in_aar
|
from controllers.aar.aar import wrap_in_aar
|
||||||
from qt.ui_mainwindow import Ui_Nugget
|
from qt.ui_mainwindow import Ui_Nugget
|
||||||
|
|
||||||
@@ -165,27 +166,42 @@ class PosterboardTweak(Tweak):
|
|||||||
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), isAdding=False)
|
self.recursive_add(files_to_restore, os.path.join(curr_path, folder), isAdding=False)
|
||||||
|
|
||||||
def create_live_photo_files(self, output_dir: str):
|
def create_live_photo_files(self, output_dir: str):
|
||||||
if self.videoThumbnail != None and self.videoFile != None:
|
if self.videoFile != None:
|
||||||
source_dir = get_bundle_files("files/posterboard/1F20C883-EA98-4CCE-9923-0C9A01359721")
|
source_dir = get_bundle_files("files/posterboard/1F20C883-EA98-4CCE-9923-0C9A01359721")
|
||||||
video_output_dir = os.path.join(output_dir, "video-descriptor/1F20C883-EA98-4CCE-9923-0C9A01359721")
|
video_output_dir = os.path.join(output_dir, "video-descriptor/1F20C883-EA98-4CCE-9923-0C9A01359721")
|
||||||
copytree(source_dir, video_output_dir, dirs_exist_ok=True)
|
copytree(source_dir, video_output_dir, dirs_exist_ok=True)
|
||||||
contents_path = os.path.join(video_output_dir, "versions/0/contents/0EFB6A0F-7052-4D24-8859-AB22BADF2E93")
|
contents_path = os.path.join(video_output_dir, "versions/0/contents/0EFB6A0F-7052-4D24-8859-AB22BADF2E93")
|
||||||
# replace the heic files first
|
|
||||||
with open(self.videoThumbnail, "rb") as thumb:
|
# convert the video first
|
||||||
contents = thumb.read()
|
video_contents = None
|
||||||
to_override = ["input.segmentation/asset.resource/Adjusted.HEIC", "input.segmentation/asset.resource/proxy.heic", "output.layerStack/portrait-layer_background.HEIC"]
|
if self.videoFile.endswith('.mov'):
|
||||||
for file in to_override:
|
# no need to convert
|
||||||
with open(os.path.join(contents_path, file), "wb") as overriding:
|
with open(self.videoFile, "rb") as vid:
|
||||||
overriding.write(contents)
|
video_contents = vid.read()
|
||||||
del contents
|
else:
|
||||||
|
# convert to mov
|
||||||
|
video_contents = video_handler.convert_to_mov(input_file=self.videoFile)
|
||||||
# now replace video
|
# now replace video
|
||||||
with open(self.videoFile, "rb") as vid:
|
with open(os.path.join(contents_path, "output.layerStack/portrait-layer_settling-video.MOV"), "wb") as overriding:
|
||||||
contents = vid.read()
|
overriding.write(video_contents)
|
||||||
with open(os.path.join(contents_path, "output.layerStack/portrait-layer_settling-video.MOV"), "wb") as overriding:
|
|
||||||
overriding.write(contents)
|
|
||||||
del contents
|
|
||||||
aar_path = os.path.join(contents_path, "input.segmentation/segmentation.data.aar")
|
aar_path = os.path.join(contents_path, "input.segmentation/segmentation.data.aar")
|
||||||
wrap_in_aar(get_bundle_files("files/posterboard/contents.plist"), self.videoFile, aar_path)
|
wrap_in_aar(get_bundle_files("files/posterboard/contents.plist"), video_contents, aar_path)
|
||||||
|
|
||||||
|
# replace the heic files
|
||||||
|
if self.videoThumbnail != None:
|
||||||
|
del video_contents
|
||||||
|
with open(self.videoThumbnail, "rb") as thumb:
|
||||||
|
thumb_contents = thumb.read()
|
||||||
|
else:
|
||||||
|
# get the thumbnail from the video
|
||||||
|
thumb_contents = video_handler.get_thumbnail_from_contents(contents=video_contents)
|
||||||
|
del video_contents
|
||||||
|
to_override = ["input.segmentation/asset.resource/Adjusted.HEIC", "input.segmentation/asset.resource/proxy.heic", "output.layerStack/portrait-layer_background.HEIC"]
|
||||||
|
for file in to_override:
|
||||||
|
with open(os.path.join(contents_path, file), "wb") as overriding:
|
||||||
|
overriding.write(thumb_contents)
|
||||||
|
del thumb_contents
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def apply_tweak(self, files_to_restore: list[FileToRestore], output_dir: str):
|
def apply_tweak(self, files_to_restore: list[FileToRestore], output_dir: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user