Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
2 changes: 1 addition & 1 deletion gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def video_is_playable(video_filepath: str) -> bool:
(".webm", "vp9"),
]
# If anything goes wrong, assume the video can be played to not convert downstream
except FFRuntimeError:
except (FFRuntimeError, IndexError, KeyError):
return True


Expand Down
23 changes: 19 additions & 4 deletions test/test_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ffmpy
import matplotlib.pyplot as plt
import numpy as np
import pytest
from PIL import Image

import gradio as gr
Expand Down Expand Up @@ -150,6 +151,24 @@ def test_video_has_playable_codecs(test_file_dir):
)


def raise_ffmpy_runtime_exception(*args, **kwargs):
raise ffmpy.FFRuntimeError("", "", "", "")


@pytest.mark.parametrize(
"exception_to_raise", [raise_ffmpy_runtime_exception, KeyError(), IndexError()]
)
def test_video_has_playable_codecs_catches_exceptions(
exception_to_raise, test_file_dir
):
with patch("ffmpy.FFprobe.run", side_effect=exception_to_raise):
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
shutil.copy(
str(test_file_dir / "bad_video_sample.mp4"), tmp_not_playable_vid.name
)
assert gr.processing_utils.video_is_playable(tmp_not_playable_vid.name)


def test_convert_video_to_playable_mp4(test_file_dir):
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
shutil.copy(
Expand All @@ -161,10 +180,6 @@ def test_convert_video_to_playable_mp4(test_file_dir):
assert gr.processing_utils.video_is_playable(playable_vid)


def raise_ffmpy_runtime_exception():
raise ffmpy.FFRuntimeError("", "", "", "")


@patch("ffmpy.FFmpeg.run", side_effect=raise_ffmpy_runtime_exception)
def test_video_conversion_returns_original_video_if_fails(mock_run, test_file_dir):
with tempfile.NamedTemporaryFile(suffix="out.avi") as tmp_not_playable_vid:
Expand Down