mirror of
https://github.com/leminlimez/Nugget.git
synced 2025-04-08 04:23:05 +08:00
fix converting mp4 + disable auto thumbnail gen
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import cv2
|
import cv2
|
||||||
import os
|
import os
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import mkdtemp, NamedTemporaryFile
|
||||||
|
from shutil import rmtree
|
||||||
|
|
||||||
import ffmpeg.stream
|
import ffmpeg.stream
|
||||||
import ffmpeg.video
|
import ffmpeg.video
|
||||||
@@ -9,35 +10,36 @@ import ffmpeg.video
|
|||||||
def convert_to_mov(input_file: str, output_file: str = None):
|
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 there is no output file specified, create a temp file then return contents
|
||||||
if output_file == None:
|
if output_file == None:
|
||||||
with NamedTemporaryFile("rb+", suffix=".mov") as tmp:
|
tmpdir = mkdtemp()
|
||||||
convert_to_mov(input_file, tmp)
|
tmp = os.path.join(tmpdir, "vid.mov")
|
||||||
contents = tmp.read()
|
convert_to_mov(input_file, tmp)
|
||||||
|
with open(tmp, "rb") as tmpfile:
|
||||||
|
contents = tmpfile.read()
|
||||||
|
rmtree(tmpdir)
|
||||||
return contents
|
return contents
|
||||||
(
|
inp = ffmpeg.input(input_file)
|
||||||
ffmpeg
|
out = ffmpeg.output(inp, output_file, f='mov', vcodec='copy', acodec='copy')
|
||||||
.input(input_file)
|
ffmpeg.run(out)
|
||||||
.output(output_file, vcodec='copy', acodec='copy', format='mov')
|
|
||||||
.run()
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_thumbnail_from_mov(input_file: str, output_file: str = None):
|
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 there is no output file specified, create a temp file and then return contents
|
||||||
if output_file == None:
|
if output_file == None:
|
||||||
with NamedTemporaryFile("rb+", suffix=".heic") as tmp:
|
tmpdir = mkdtemp()
|
||||||
get_thumbnail_from_mov(input_file, tmp)
|
tmp = os.path.join(tmpdir, "thumb.png")
|
||||||
contents = tmp.read()
|
get_thumbnail_from_mov(input_file, tmp)
|
||||||
|
with open(tmp, "rb") as tmpfile:
|
||||||
|
contents = tmpfile.read()
|
||||||
|
rmtree(tmpdir)
|
||||||
return contents
|
return contents
|
||||||
(
|
|
||||||
ffmpeg
|
inp = ffmpeg.input(input_file, ss=0)
|
||||||
.input(input_file, ss=0)
|
out = ffmpeg.output(inp, output_file, vframes=1)
|
||||||
.output(output_file, vframes=1, format='heic')
|
ffmpeg.run(out)
|
||||||
.run()
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_thumbnail_from_contents(contents: bytes, output_file: str = None):
|
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)
|
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
|
return contents
|
||||||
|
|
||||||
def create_caml(video_path: str, output_file: str, update_label=lambda x: None):
|
def create_caml(video_path: str, output_file: str, update_label=lambda x: None):
|
||||||
|
|||||||
@@ -4577,7 +4577,7 @@ Warning: This will remove all of your wallpapers and will restrict you from addi
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="chooseVideoBtn">
|
<widget class="QToolButton" name="chooseVideoBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Choose Video (.MOV)</string>
|
<string>Choose Video</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -3811,7 +3811,7 @@ class Ui_Nugget(object):
|
|||||||
self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None))
|
self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None))
|
||||||
self.pbVideoLbl.setText(QCoreApplication.translate("Nugget", u"Current Video: 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.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.clearSuggestedBtn.setText(QCoreApplication.translate("Nugget", u" Clear Suggested Photos", None))
|
||||||
self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None))
|
self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None))
|
||||||
self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None))
|
self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None))
|
||||||
|
|||||||
@@ -3811,7 +3811,7 @@ class Ui_Nugget(object):
|
|||||||
self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None))
|
self.pbVideoThumbLbl.setText(QCoreApplication.translate("Nugget", u"Current Thumbnail: None", None))
|
||||||
self.pbVideoLbl.setText(QCoreApplication.translate("Nugget", u"Current Video: 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.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.clearSuggestedBtn.setText(QCoreApplication.translate("Nugget", u" Clear Suggested Photos", None))
|
||||||
self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None))
|
self.caVideoChk.setText(QCoreApplication.translate("Nugget", u"Loop (use CoreAnimation method)", None))
|
||||||
self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None))
|
self.advancedOptionsLbl.setText(QCoreApplication.translate("Nugget", u"Risky Options", None))
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ class PosterboardTweak(Tweak):
|
|||||||
with open(self.videoThumbnail, "rb") as thumb:
|
with open(self.videoThumbnail, "rb") as thumb:
|
||||||
thumb_contents = thumb.read()
|
thumb_contents = thumb.read()
|
||||||
else:
|
else:
|
||||||
|
raise Exception("No thumbnail heic selected!")
|
||||||
# get the thumbnail from the video
|
# get the thumbnail from the video
|
||||||
thumb_contents = video_handler.get_thumbnail_from_contents(contents=video_contents)
|
thumb_contents = video_handler.get_thumbnail_from_contents(contents=video_contents)
|
||||||
del video_contents
|
del video_contents
|
||||||
|
|||||||
Reference in New Issue
Block a user