better video duration probe
This commit is contained in:
parent
7810374fa4
commit
eb84dc13dd
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -190,6 +190,7 @@ ul.explr-dirview {
|
|||||||
max-width: 84px;
|
max-width: 84px;
|
||||||
min-width: 84px;
|
min-width: 84px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
&.with-thumbnail {
|
&.with-thumbnail {
|
||||||
|
|
||||||
|
|||||||
@ -5,4 +5,3 @@ waitress
|
|||||||
flask-login
|
flask-login
|
||||||
pysqlite3
|
pysqlite3
|
||||||
psutil
|
psutil
|
||||||
moviepy
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import os
|
|||||||
|
|
||||||
from typing import Dict, Optional, List, Tuple, Union
|
from typing import Dict, Optional, List, Tuple, Union
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
from moviepy.editor import VideoFileClip
|
|
||||||
|
|
||||||
from src.model.entity.Content import Content
|
from src.model.entity.Content import Content
|
||||||
from src.model.entity.Playlist import Playlist
|
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.service.ModelManager import ModelManager
|
||||||
from src.util.UtilFile import randomize_filename
|
from src.util.UtilFile import randomize_filename
|
||||||
from src.util.UtilNetwork import get_preferred_ip_address
|
from src.util.UtilNetwork import get_preferred_ip_address
|
||||||
|
from src.util.UtilVideo import mp4_duration_with_ffprobe
|
||||||
|
|
||||||
|
|
||||||
class ContentManager(ModelManager):
|
class ContentManager(ModelManager):
|
||||||
@ -195,8 +195,7 @@ class ContentManager(ModelManager):
|
|||||||
content.location = object_path
|
content.location = object_path
|
||||||
|
|
||||||
if type == ContentType.VIDEO:
|
if type == ContentType.VIDEO:
|
||||||
with VideoFileClip(content.location) as video:
|
content.duration = mp4_duration_with_ffprobe(content.location)
|
||||||
content.duration = int(video.duration)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
content.location = location
|
content.location = location
|
||||||
|
|||||||
18
src/util/UtilVideo.py
Normal file
18
src/util/UtilVideo.py
Normal 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
|
||||||
Loading…
Reference in New Issue
Block a user