gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
30.64k stars 2.28k forks source link

Lite: Support ffmpeg features #6000

Open whitphx opened 8 months ago

whitphx commented 8 months ago

Because ffmpeg features are not supported on the Wasm ver., for example the camera-input video causes an error,

pyodide.asm.js:9 Traceback (most recent call last):
pyodide.asm.js:9   File "/lib/python3.11/site-packages/gradio/routes.py", line 534, in predict
pyodide.asm.js:9     output = await route_utils.call_process_api(
pyodide.asm.js:9              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodide.asm.js:9   File "/lib/python3.11/site-packages/gradio/route_utils.py", line 226, in call_process_api
pyodide.asm.js:9     output = await app.get_blocks().process_api(
pyodide.asm.js:9              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodide.asm.js:9   File "/lib/python3.11/site-packages/gradio/blocks.py", line 1548, in process_api
pyodide.asm.js:9     inputs = self.preprocess_data(fn_index, inputs, state)
pyodide.asm.js:9              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodide.asm.js:9   File "/lib/python3.11/site-packages/gradio/blocks.py", line 1329, in preprocess_data
pyodide.asm.js:9     processed_input.append(block.preprocess(inputs[i]))
pyodide.asm.js:9                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodide.asm.js:9   File "/lib/python3.11/site-packages/gradio/components/video.py", line 223, in preprocess
pyodide.asm.js:9     raise wasm_utils.WasmUnsupportedError(
pyodide.asm.js:9 gradio.wasm_utils.WasmUnsupportedError: Video formatting is not supported in the Wasm mode.
webworker.js?type=classic&worker_file:2 

Sample app to reproduce:

import gradio as gr

def snap(image, video):
    return [image, video]

demo = gr.Interface(
    snap,
    [gr.Image(source="webcam", tool=None), gr.Video(source="webcam")],
    ["image", "video"],
)

if __name__ == "__main__":
    demo.launch()
pngwn commented 8 months ago

I'm actually moving this webcam flip logic to the front end in v4 which will solve this specific case. We do use ffmpeg elsewhere though.

whitphx commented 5 days ago

Another situation where ffmpeg is used in Gradio is to upload an audio file other than .wav. pydub offloads file loading to ffmpeg internally.

https://github.com/gradio-app/gradio/blob/cccf0fe20834d2ce4f63659b520d27d1f651d08c/gradio/processing_utils.py#L536

https://github.com/jiaaro/pydub/blob/996cec42e9621701edb83354232b2c0ca0121560/pydub/audio_segment.py#L766