enforce consistency for ffmpeg params

pull/173/head
Aevann 2023-07-29 21:50:09 +03:00
parent 3ee037c2c7
commit 19b30e726b
2 changed files with 7 additions and 5 deletions

View File

@ -19,6 +19,8 @@ from files.helpers.settings import get_setting
from .config.const import * from .config.const import *
generic_ffmpeg_params = ["ffmpeg", "-loglevel", "quiet", "-y", "-map_metadata", "-1"]
def subprocess_run(params): def subprocess_run(params):
subprocess.run(params, check=True, timeout=30) subprocess.run(params, check=True, timeout=30)
@ -88,7 +90,7 @@ def process_audio(file, v):
new = old + '.' + extension new = old + '.' + extension
try: try:
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:a", "copy", new]) subprocess_run(generic_ffmpeg_params + ["-i", old, "-c:a", "copy", new])
except: except:
os.remove(old) os.remove(old)
if os.path.isfile(new): if os.path.isfile(new):
@ -111,7 +113,7 @@ def process_audio(file, v):
def convert_to_mp4(old, new): def convert_to_mp4(old, new):
tmp = new.replace('.mp4', '-t.mp4') tmp = new.replace('.mp4', '-t.mp4')
try: try:
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp]) subprocess_run(generic_ffmpeg_params + ["-i", old, "-threads:v", "1", tmp])
except: except:
os.remove(old) os.remove(old)
if os.path.isfile(tmp): if os.path.isfile(tmp):
@ -151,7 +153,7 @@ def process_video(file, v):
gevent.spawn(convert_to_mp4, old, new) gevent.spawn(convert_to_mp4, old, new)
else: else:
try: try:
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new]) subprocess_run(["-i", old, "-c:v", "copy", "-c:a", "copy", new])
except: except:
os.remove(old) os.remove(old)
if os.path.isfile(new): if os.path.isfile(new):

View File

@ -22,7 +22,7 @@ from files.helpers.sanitize import *
from files.helpers.settings import get_setting from files.helpers.settings import get_setting
from files.helpers.slots import * from files.helpers.slots import *
from files.helpers.sorting_and_time import * from files.helpers.sorting_and_time import *
from files.helpers.media import subprocess_run from files.helpers.media import subprocess_run, generic_ffmpeg_params
from files.routes.routehelpers import execute_shadowban_viewers_and_voters from files.routes.routehelpers import execute_shadowban_viewers_and_voters
from files.routes.wrappers import * from files.routes.wrappers import *
@ -661,7 +661,7 @@ def submit_post(v:User, sub=None):
p.url = process_video(file, v) p.url = process_video(file, v)
name = f'/images/{time.time()}'.replace('.','') + '.webp' name = f'/images/{time.time()}'.replace('.','') + '.webp'
try: try:
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", p.url, "-vf", "scale='iw':-2", "-q:v", "3", "-frames:v", "1", name]) subprocess_run(generic_ffmpeg_params + ["-i", p.url, "-vf", "scale='iw':-2", "-q:v", "3", "-frames:v", "1", name])
except: except:
if os.path.isfile(name): if os.path.isfile(name):
os.remove(name) os.remove(name)