mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
Fix video conversion bug (#4467)
* Fix bug * CHANGELOG * Add feature * Revert "Add feature" This reverts commit 834fed6a9f48c4c6fc2d73ff2f8e080302a82def. --------- Co-authored-by: aliabid94 <aabid94@gmail.com>
This commit is contained in:
parent
17a3be3d81
commit
ba25158420
@ -12,6 +12,7 @@
|
||||
- Ensure Tabs only occupy the space required by [@pngwn](https://github.com/pngwn) in [PR 4419](https://github.com/gradio-app/gradio/pull/4419)
|
||||
- Ensure components have the correct empty sizes to prevent empty containers from collapsing by [@pngwn](https://github.com/pngwn) in [PR 4447](https://github.com/gradio-app/gradio/pull/4447).
|
||||
- Frontend code no longer crashes when there is a relative URL in an `<a>` element, by [@akx](https://github.com/akx) in [PR 4449](https://github.com/gradio-app/gradio/pull/4449).
|
||||
- Fix bug where setting `format='mp4'` on a video component would cause the function to error out if the uploaded video was not playable by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4467](https://github.com/gradio-app/gradio/pull/4467)
|
||||
|
||||
## Other Changes:
|
||||
|
||||
|
@ -2413,9 +2413,7 @@ class Video(
|
||||
"""
|
||||
if video is None:
|
||||
return None
|
||||
|
||||
returned_format = video.split(".")[-1].lower()
|
||||
|
||||
if self.format is None or returned_format == self.format:
|
||||
conversion_needed = False
|
||||
else:
|
||||
@ -2436,9 +2434,16 @@ class Video(
|
||||
"Video does not have browser-compatible container or codec. Converting to mp4"
|
||||
)
|
||||
video = processing_utils.convert_video_to_playable_mp4(video)
|
||||
# Recalculate the format in case convert_video_to_playable_mp4 already made it the
|
||||
# selected format
|
||||
returned_format = video.split(".")[-1].lower()
|
||||
if self.format is not None and returned_format != self.format:
|
||||
output_file_name = video[0 : video.rindex(".") + 1] + self.format
|
||||
ff = FFmpeg(inputs={video: None}, outputs={output_file_name: None})
|
||||
ff = FFmpeg(
|
||||
inputs={video: None},
|
||||
outputs={output_file_name: None},
|
||||
global_options="-y",
|
||||
)
|
||||
ff.run()
|
||||
video = output_file_name
|
||||
|
||||
|
@ -1409,6 +1409,15 @@ class TestVideo:
|
||||
full_path_to_output = Path(tmp_not_playable_vid.name).with_suffix(".mp4")
|
||||
assert processing_utils.video_is_playable(str(full_path_to_output))
|
||||
|
||||
def test_convert_video_to_playable_format(self, monkeypatch, tmp_path):
|
||||
test_file_dir = Path(Path(__file__).parent, "test_files")
|
||||
monkeypatch.setenv("GRADIO_TEMP_DIR", str(tmp_path))
|
||||
video = gr.Video(format="mp4")
|
||||
output = video.postprocess(
|
||||
str(test_file_dir / "playable_but_bad_container.mkv")
|
||||
)
|
||||
assert Path(output[0]["name"]).suffix == ".mp4"
|
||||
|
||||
@patch("pathlib.Path.exists", MagicMock(return_value=False))
|
||||
@patch("gradio.components.FFmpeg")
|
||||
def test_video_preprocessing_flips_video_for_webcam(self, mock_ffmpeg):
|
||||
|
Loading…
x
Reference in New Issue
Block a user