Skip to content

Commit

Permalink
make_waveform() twitter video resolution fix (#5296)
Browse files Browse the repository at this point in the history
* waveform res fix

* add changeset

* add changeset

* Improve audio streaming (#5238)

* changes

* changes

* add changeset

* add changeset

* chages

* Update silver-clowns-brush.md

* changes

* chagers

* changes

* Update silver-clowns-brush.md

* change

* change

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>

* Tweaks to `icon` parameter in `gr.Button()` (#5285)

* button

* add changeset

* fix

* add changeset

* add changeset

* types

* type fix

* formatting

* fix based on review

* fix unit tests

* stories

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>

* test

* test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: aliabid94 <aabid94@gmail.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
5 people committed Aug 28, 2023
1 parent 78376fe commit f8edf50
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-poets-kneel.md
@@ -0,0 +1,5 @@
---
"gradio": minor
---

fix:`make_waveform()` twitter video resolution fix
8 changes: 4 additions & 4 deletions gradio/helpers.py
Expand Up @@ -892,7 +892,7 @@ def get_color_gradient(c1, c2, n):

if not animate:
waveform_img = PIL.Image.open(tmp_img.name)
waveform_img = waveform_img.resize((1000, 200))
waveform_img = waveform_img.resize((1000, 400))

# Composite waveform with background image
if bg_image is not None:
Expand Down Expand Up @@ -987,11 +987,11 @@ def _animate(_):
"-i",
audio_file,
"-filter_complex",
"[0:v][1:a]concat=n=1:v=1:a=1[v][a]",
"[0:v][1:a]concat=n=1:v=1:a=1[v];[v]scale=1000:400,format=yuv420p[v_scaled]",
"-map",
"[v]",
"[v_scaled]",
"-map",
"[a]",
"1:a",
"-c:v",
"libx264",
"-c:a",
Expand Down
26 changes: 26 additions & 0 deletions test/test_helpers.py
Expand Up @@ -452,6 +452,32 @@ def test_make_waveform_with_spaces_in_filename():
waveform = gr.make_waveform(audio)
assert waveform.endswith(".mp4")

try:
command = [
"ffprobe",
"-v",
"error",
"-select_streams",
"v:0",
"-show_entries",
"stream=width,height",
"-of",
"json",
waveform,
]

result = subprocess.run(command, capture_output=True, text=True, check=True)
output = result.stdout
data = json.loads(output)

width = data["streams"][0]["width"]
height = data["streams"][0]["height"]
assert width == 1000
assert height == 400

except subprocess.CalledProcessError as e:
print("Error retrieving resolution of output waveform video:", e)


def test_make_waveform_raises_if_ffmpeg_fails(tmp_path, monkeypatch):
"""
Expand Down

0 comments on commit f8edf50

Please sign in to comment.