Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise WasmUnsupportedError for ffmpeg usage on Lite #9130

Merged
merged 9 commits into from
Aug 20, 2024
5 changes: 5 additions & 0 deletions .changeset/puny-bats-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

feat:Raise WasmUnsupportedError for ffmpeg usage on Lite
6 changes: 5 additions & 1 deletion gradio/components/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from gradio_client.documentation import document
from pydub import AudioSegment

from gradio import processing_utils, utils
from gradio import processing_utils, utils, wasm_utils
from gradio.components.base import Component, StreamingInput, StreamingOutput
from gradio.data_classes import FileData, FileDataDict, MediaStreamChunk
from gradio.events import Events
Expand Down Expand Up @@ -310,6 +310,10 @@ def postprocess(

@staticmethod
def _convert_to_adts(data: bytes):
if wasm_utils.IS_WASM:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also raise if needs_conversion is True in preprocess. I am pretty sure that pydub is using ffmpeg under the hood in that case.

raise wasm_utils.WasmUnsupportedError(
"Audio streaming is not supported in the Wasm mode."
)
segment = AudioSegment.from_file(io.BytesIO(data))

buffer = io.BytesIO()
Expand Down
10 changes: 10 additions & 0 deletions gradio/components/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ def example_value(self) -> Any:

@staticmethod
def get_video_duration_ffprobe(filename: str):
if wasm_utils.IS_WASM:
raise wasm_utils.WasmUnsupportedError(
"ffprobe is not supported in the Wasm mode."
)

result = subprocess.run(
[
"ffprobe",
Expand Down Expand Up @@ -452,6 +457,11 @@ def get_video_duration_ffprobe(filename: str):

@staticmethod
async def async_convert_mp4_to_ts(mp4_file, ts_file):
if wasm_utils.IS_WASM:
raise wasm_utils.WasmUnsupportedError(
"Streaming is not supported in the Wasm mode."
)

ff = FFmpeg( # type: ignore
inputs={mp4_file: None},
outputs={
Expand Down
4 changes: 4 additions & 0 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ def audio_from_file(
def audio_to_file(sample_rate, data, filename, format="wav"):
if format == "wav":
data = convert_to_16_bit_wav(data)
elif wasm_utils.IS_WASM:
raise wasm_utils.WasmUnsupportedError(
"Audio formats other than .wav are not supported in the Wasm mode."
)
audio = AudioSegment(
data.tobytes(),
frame_rate=sample_rate,
Expand Down
Loading