2023-01-29 06:10:09 +00:00
|
|
|
# Python imports
|
2021-10-10 06:45:55 +00:00
|
|
|
import subprocess
|
|
|
|
|
2023-01-29 06:10:09 +00:00
|
|
|
# Lib imports
|
2021-10-10 06:45:55 +00:00
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
2023-01-29 06:10:09 +00:00
|
|
|
|
|
|
|
|
2021-10-10 06:45:55 +00:00
|
|
|
class VideoIconMixin:
|
2023-01-29 06:10:09 +00:00
|
|
|
def generate_video_thumbnail(self, full_path, hash_img_path, scrub_percent = "65%"):
|
2021-10-10 06:45:55 +00:00
|
|
|
try:
|
2023-01-29 06:10:09 +00:00
|
|
|
proc = subprocess.Popen([self.FFMPG_THUMBNLR, "-t", scrub_percent, "-s", "300", "-c", "jpg", "-i", full_path, "-o", hash_img_path])
|
2021-10-10 06:45:55 +00:00
|
|
|
proc.wait()
|
|
|
|
except Exception as e:
|
2024-06-30 02:37:44 +00:00
|
|
|
logger.info(repr(e))
|
2023-01-29 06:10:09 +00:00
|
|
|
self.ffprobe_generate_video_thumbnail(full_path, hash_img_path)
|
2021-10-10 06:45:55 +00:00
|
|
|
|
|
|
|
|
2023-01-29 06:10:09 +00:00
|
|
|
def ffprobe_generate_video_thumbnail(self, full_path, hash_img_path):
|
2021-10-10 06:45:55 +00:00
|
|
|
proc = None
|
|
|
|
try:
|
|
|
|
# Stream duration
|
|
|
|
command = ["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=duration", "-of", "default=noprint_wrappers=1:nokey=1", full_path]
|
|
|
|
data = subprocess.run(command, stdout=subprocess.PIPE)
|
|
|
|
duration = data.stdout.decode('utf-8')
|
|
|
|
|
|
|
|
# Format (container) duration
|
|
|
|
if "N/A" in duration:
|
|
|
|
command = ["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", full_path]
|
|
|
|
data = subprocess.run(command , stdout=subprocess.PIPE)
|
|
|
|
duration = data.stdout.decode('utf-8')
|
|
|
|
|
|
|
|
# Stream duration type: image2
|
|
|
|
if "N/A" in duration:
|
|
|
|
command = ["ffprobe", "-v", "error", "-select_streams", "v:0", "-f", "image2", "-show_entries", "stream=duration", "-of", "default=noprint_wrappers=1:nokey=1", full_path]
|
|
|
|
data = subprocess.run(command, stdout=subprocess.PIPE)
|
|
|
|
duration = data.stdout.decode('utf-8')
|
|
|
|
|
|
|
|
# Format (container) duration type: image2
|
|
|
|
if "N/A" in duration:
|
|
|
|
command = ["ffprobe", "-v", "error", "-f", "image2", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", full_path]
|
|
|
|
data = subprocess.run(command , stdout=subprocess.PIPE)
|
|
|
|
duration = data.stdout.decode('utf-8')
|
|
|
|
|
|
|
|
# Get frame roughly 35% through video
|
|
|
|
grabTime = str( int( float( duration.split(".")[0] ) * 0.35) )
|
2023-01-29 06:10:09 +00:00
|
|
|
command = ["ffmpeg", "-ss", grabTime, "-an", "-i", full_path, "-s", "320x180", "-vframes", "1", hash_img_path]
|
2021-10-10 06:45:55 +00:00
|
|
|
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
|
|
|
|
proc.wait()
|
|
|
|
except Exception as e:
|
|
|
|
print("Video thumbnail generation issue in thread:")
|
2024-06-30 02:37:44 +00:00
|
|
|
logger.info(repr(e))
|