I need to trigger a long ffmpeg process by nicegui button. I have created a code :
from concurrent.futures import ProcessPoolExecutor
import shlex, subprocess
import argparse
import asyncio
from nicegui import ui, app
def run_cmd():
cmd = "ffmpeg -y -i data/video.mp4 -acodec libmp3lame -ab 128000 data/video.mp3"
subprocess.call(shlex.split(cmd))
pool = ProcessPoolExecutor()
async def async_run():
loop = asyncio.get_running_loop()
await loop.run_in_executor(pool, run_cmd)
args = argparse.ArgumentParser()
args.add_argument("--webui", action="store_true")
args = args.parse_args()
if args.webui:
ui.button('Translate', on_click=async_run)
app.on_shutdown(pool.shutdown)
ui.run()
else:
run_cmd()
ffmpeg works well if run just from python.
But when I run it from nicegui (python3 ./main.py --webui
)
ffmpeg failed or crashed:
...
Error while decoding stream #0:1: Invalid argument
[aac @ 0x555e54100440] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x555e54100440] Inconsistent channel configuration.
[aac @ 0x555e54100440] get_buffer() failed
...
ac @ 0x555e54100440] Error decoding AAC frame header.
Error while decoding stream #0:1: Error number -50531338 occurred
[aac @ 0x555e54100440] channel element 2.8 is not allocated
Error while decoding stream #0:1: Invalid data found when processing input
[aac @ 0x555e54100440] Pulse data corrupt or invalid.
Error while decoding stream #0:1: Invalid data found when processing input
ffmpeg: psymodel.c:576: calc_energy: Assertion `el >= 0' failed.
...
What am I doing wrong? Or maybe there is a more straightforward pattern to start long-term background process with nicegui?