better video duration probe

This commit is contained in:
jr-k 2024-07-22 03:56:27 +02:00
parent 4f775afa98
commit f6e27ba9bf
6 changed files with 23 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -190,6 +190,7 @@ ul.explr-dirview {
max-width: 84px;
min-width: 84px;
position: relative;
word-break: break-all;
&.with-thumbnail {

View File

@ -5,4 +5,3 @@ waitress
flask-login
pysqlite3
psutil
moviepy

View File

@ -2,7 +2,6 @@ import os
from typing import Dict, Optional, List, Tuple, Union
from werkzeug.datastructures import FileStorage
from moviepy.editor import VideoFileClip
from src.model.entity.Content import Content
from src.model.entity.Playlist import Playlist
@ -16,6 +15,7 @@ from src.manager.VariableManager import VariableManager
from src.service.ModelManager import ModelManager
from src.util.UtilFile import randomize_filename
from src.util.UtilNetwork import get_preferred_ip_address
from src.util.UtilVideo import mp4_duration_with_ffprobe
class ContentManager(ModelManager):
@ -195,8 +195,7 @@ class ContentManager(ModelManager):
content.location = object_path
if type == ContentType.VIDEO:
with VideoFileClip(content.location) as video:
content.duration = int(video.duration)
content.duration = mp4_duration_with_ffprobe(content.location)
else:
content.location = location

18
src/util/UtilVideo.py Normal file
View File

@ -0,0 +1,18 @@
import struct
def mp4_duration_with_ffprobe(filename):
import subprocess, json
result = subprocess.check_output(
f'ffprobe -v quiet -show_streams -select_streams v:0 -of json "{filename}"',
shell=True).decode()
fields = json.loads(result)['streams'][0]
if 'tags' in fields and 'DURATION' in fields['tags']:
return int(float(fields['tags']['DURATION']))
if 'duration' in fields:
return int(float(fields['duration']))
return 0