Skip to content

Commit

Permalink
fix: Transposing hangs when ffmpeg does not have librubberband (#435)
Browse files Browse the repository at this point in the history
Fix for #427
  • Loading branch information
jepes1981 authored and vicwomg committed Dec 24, 2024
1 parent 3ea46de commit 8939e60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pikaraoke/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def home():
title="Home",
transpose_value=k.now_playing_transpose,
admin=is_admin(),
is_transpose_enabled=k.is_transpose_enabled,
)


Expand Down Expand Up @@ -164,6 +165,7 @@ def nowplaying():
"is_paused": k.is_paused,
"transpose_value": k.now_playing_transpose,
"volume": k.volume,
# "is_transpose_enabled": k.is_transpose_enabled,
}
rc["hash"] = hash_dict(rc) # used to detect changes in the now playing data
return json.dumps(rc)
Expand Down Expand Up @@ -582,6 +584,7 @@ def info():
cpu=cpu,
disk=disk,
ffmpeg_version=k.ffmpeg_version,
is_transpose_enabled=k.is_transpose_enabled,
youtubedl_version=youtubedl_version,
platform=k.platform,
os_version=k.os_version,
Expand Down
3 changes: 3 additions & 0 deletions pikaraoke/karaoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_os_version,
get_platform,
is_raspberry_pi,
is_transpose_enabled,
supports_hardware_h264_encoding,
)

Expand Down Expand Up @@ -66,6 +67,7 @@ class Karaoke:
ffmpeg_process = None
ffmpeg_log = None
ffmpeg_version = get_ffmpeg_version()
is_transpose_enabled = is_transpose_enabled()
supports_hardware_h264_encoding = supports_hardware_h264_encoding()
normalize_audio = False

Expand Down Expand Up @@ -144,6 +146,7 @@ def __init__(
platform: {self.platform}
os version: {self.os_version}
ffmpeg version: {self.ffmpeg_version}
ffmpeg transpose support: {self.is_transpose_enabled}
hardware h264 encoding: {self.supports_hardware_h264_encoding}
youtubedl-version: {self.get_youtubedl_version()}
"""
Expand Down
12 changes: 12 additions & 0 deletions pikaraoke/lib/get_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def get_ffmpeg_version():
return "Unable to parse FFmpeg version"


def is_transpose_enabled():
try:
filters = subprocess.run(["ffmpeg", "-filters"], capture_output=True)
except FileNotFoundError:
# FFmpeg is not installed
return False
except IndexError:
# Unable to parse FFmpeg filters
return False
return "rubberband" in filters.stdout.decode()


def is_raspberry_pi():
try:
return (
Expand Down
8 changes: 6 additions & 2 deletions pikaraoke/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
$(".control-box").hide();

var slider = document.getElementById("transpose");
console.log("slider returned: ", slider)
var output = document.getElementById("semitones-label");
if (slider) {
console.log("output returned: ", output)
if (slider && output) {
output.innerHTML = getSemitonesLabel(slider.value);
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function () {
Expand Down Expand Up @@ -230,6 +232,8 @@ <h4>{% trans %}Player Control{% endtrans %}</h4>
</div>
</div>
<hr />

{% if is_transpose_enabled %}
<div class="is-flex" style="justify-content: space-between">
<div>
{# MSG: Title of a control to change the key/pitch of the playing song. #}
Expand All @@ -242,7 +246,6 @@ <h4 id="semitones-label"></h4>
></a>
</div>
</div>

<div style="width: 100%">
<div class="is-flex">
<input
Expand All @@ -265,6 +268,7 @@ <h4 id="semitones-label"></h4>
</button>
</div>
</div>
{% endif %}
</div>
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion pikaraoke/templates/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1>{% trans %}System Info{% endtrans %}</h1>
{# MSG: The version of the program "Youtube-dl". #}
<li><u>{% trans %}Youtube-dl (yt-dlp) version:{% endtrans %}</u> {{ youtubedl_version }}</li>
{# MSG: The version of the program "ffmpeg". #}
<li><u>{% trans %}FFmpeg version:{% endtrans %}</u> {{ ffmpeg_version }}</li>
<li><u>{% trans %}FFmpeg version:{% endtrans %}</u> {{ ffmpeg_version }} {% if not is_transpose_enabled %} (missing lib-rubberband, pitch shift is not supported) {% endif %}</li>
{# MSG: The version of Pikaraoke running right now. #}
<li><u>{% trans %}Pikaraoke version:{% endtrans %}</u> {{ pikaraoke_version }}</li>
</ul>
Expand Down

0 comments on commit 8939e60

Please sign in to comment.