diff --git a/controllers/video_handler.py b/controllers/video_handler.py index 7b334c7..ff909c0 100644 --- a/controllers/video_handler.py +++ b/controllers/video_handler.py @@ -1,7 +1,8 @@ import cv2 import os import ffmpeg -from tempfile import NamedTemporaryFile +from tempfile import mkdtemp, NamedTemporaryFile +from shutil import rmtree import ffmpeg.stream import ffmpeg.video @@ -9,35 +10,36 @@ 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() + tmpdir = mkdtemp() + tmp = os.path.join(tmpdir, "vid.mov") + convert_to_mov(input_file, tmp) + with open(tmp, "rb") as tmpfile: + contents = tmpfile.read() + rmtree(tmpdir) return contents - ( - ffmpeg - .input(input_file) - .output(output_file, vcodec='copy', acodec='copy', format='mov') - .run() - ) + inp = ffmpeg.input(input_file) + out = ffmpeg.output(inp, output_file, f='mov', vcodec='copy', acodec='copy') + ffmpeg.run(out) 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() + tmpdir = mkdtemp() + tmp = os.path.join(tmpdir, "thumb.png") + get_thumbnail_from_mov(input_file, tmp) + with open(tmp, "rb") as tmpfile: + contents = tmpfile.read() + rmtree(tmpdir) return contents - ( - ffmpeg - .input(input_file, ss=0) - .output(output_file, vframes=1, format='heic') - .run() - ) + + inp = ffmpeg.input(input_file, ss=0) + out = ffmpeg.output(inp, output_file, vframes=1) + ffmpeg.run(out) def get_thumbnail_from_contents(contents: bytes, output_file: str = None): - with NamedTemporaryFile("rb+", suffix=".heic") as inp_file: + with NamedTemporaryFile("rb+", suffix=".mov") as inp_file: inp_file.write(contents) - contents = get_thumbnail_from_mov(inp_file, output_file) + contents = get_thumbnail_from_mov(inp_file.name, output_file) return contents def create_caml(video_path: str, output_file: str, update_label=lambda x: None): diff --git a/qt/mainwindow.ui b/qt/mainwindow.ui index 4db3808..baa9685 100644 --- a/qt/mainwindow.ui +++ b/qt/mainwindow.ui @@ -4577,7 +4577,7 @@ Warning: This will remove all of your wallpapers and will restrict you from addi - Choose Video (.MOV) + Choose Video diff --git a/qt/mainwindow_ui.py b/qt/mainwindow_ui.py index 747eb6c..fca2e61 100644 --- a/qt/mainwindow_ui.py +++ b/qt/mainwindow_ui.py @@ -3811,7 +3811,7 @@ class Ui_Nugget(object): self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None)) self.pbVideoLbl.setText(QCoreApplication.translate("Nugget", u"Current Video: None", None)) self.chooseThumbBtn.setText(QCoreApplication.translate("Nugget", u"Choose Thumbnail (.HEIC)", None)) - self.chooseVideoBtn.setText(QCoreApplication.translate("Nugget", u"Choose Video (.MOV)", None)) + self.chooseVideoBtn.setText(QCoreApplication.translate("Nugget", u"Choose Video", None)) self.clearSuggestedBtn.setText(QCoreApplication.translate("Nugget", u" Clear Suggested Photos", None)) self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None)) self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None)) diff --git a/qt/ui_mainwindow.py b/qt/ui_mainwindow.py index fca72ae..bd8897c 100644 --- a/qt/ui_mainwindow.py +++ b/qt/ui_mainwindow.py @@ -3811,7 +3811,7 @@ class Ui_Nugget(object): self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None)) self.pbVideoLbl.setText(QCoreApplication.translate("Nugget", u"Current Video: None", None)) self.chooseThumbBtn.setText(QCoreApplication.translate("Nugget", u"Choose Thumbnail (.HEIC)", None)) - self.chooseVideoBtn.setText(QCoreApplication.translate("Nugget", u"Choose Video (.MOV)", None)) + self.chooseVideoBtn.setText(QCoreApplication.translate("Nugget", u"Choose Video", None)) self.clearSuggestedBtn.setText(QCoreApplication.translate("Nugget", u" Clear Suggested Photos", None)) self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None)) self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None)) diff --git a/tweaks/posterboard_tweak.py b/tweaks/posterboard_tweak.py index 9bb7a1a..db16783 100644 --- a/tweaks/posterboard_tweak.py +++ b/tweaks/posterboard_tweak.py @@ -194,6 +194,7 @@ class PosterboardTweak(Tweak): with open(self.videoThumbnail, "rb") as thumb: thumb_contents = thumb.read() else: + raise Exception("No thumbnail heic selected!") # get the thumbnail from the video thumb_contents = video_handler.get_thumbnail_from_contents(contents=video_contents) del video_contents