Skip to content

Commit 0082dd8

Browse files
committed
add ffmpeg to github actions, pyproject, try to use in slakh
1 parent 4154ea1 commit 0082dd8

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

.github/workflows/tox.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
python-version: ${{ matrix.py }}
3131
- uses: actions/checkout@v3
3232
- name: Install soundlibs Ubuntu
33-
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y --fix-missing pkg-config libsndfile1 sox
33+
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y --fix-missing pkg-config libsndfile1 sox ffmpeg
3434
if: matrix.os == 'ubuntu-latest'
3535
- name: Install soundlibs MacOs
36-
run: brew install libsndfile llvm libomp sox
36+
run: brew install libsndfile llvm libomp sox ffmpeg
3737
if: matrix.os == 'macos-latest-xlarge'
3838
- name: Install soundlibs Windows
39-
run: choco install libsndfile sox.portable flac
39+
run: choco install libsndfile sox.portable flac ffmpeg
4040
if: matrix.os == 'windows-latest'
4141
- name: Upgrade pip
4242
run: python -m pip install -U pip

basic_pitch/data/datasets/slakh.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def process(self, element: Tuple[str, str]) -> Any:
4444
import tempfile
4545

4646
import apache_beam as beam
47-
import sox
47+
import ffmpeg
4848

4949
from basic_pitch.constants import (
5050
AUDIO_N_CHANNELS,
@@ -77,11 +77,10 @@ def process(self, element: Tuple[str, str]) -> Any:
7777
return None
7878

7979
local_wav_path = "{}_tmp.wav".format(track_local.audio_path)
80-
tfm = sox.Transformer()
81-
tfm.rate(AUDIO_SAMPLE_RATE)
82-
tfm.channels(AUDIO_N_CHANNELS)
8380
try:
84-
tfm.build(track_local.audio_path, local_wav_path)
81+
ffmpeg.input(track_local.audio_path).output(
82+
local_wav_path, ar=AUDIO_SAMPLE_RATE, ac=AUDIO_N_CHANNELS
83+
).run()
8584
except Exception as e:
8685
logging.info(f"Could not process {local_wav_path}. Exception: {e}")
8786
return None
@@ -113,7 +112,7 @@ def process(self, element: List[str]) -> List[Any]:
113112
import tempfile
114113

115114
import numpy as np
116-
import sox
115+
import ffmpeg
117116

118117
from basic_pitch.constants import (
119118
AUDIO_N_CHANNELS,
@@ -145,12 +144,11 @@ def process(self, element: List[str]) -> List[Any]:
145144
d.write(s.read())
146145

147146
local_wav_path = "{}_tmp.wav".format(track_local.audio_path)
148-
tfm = sox.Transformer()
149-
tfm.rate(AUDIO_SAMPLE_RATE)
150-
tfm.channels(AUDIO_N_CHANNELS)
151-
tfm.build(track_local.audio_path, local_wav_path)
147+
ffmpeg.input(track_local.audio_path).output(
148+
local_wav_path, ar=AUDIO_SAMPLE_RATE, ac=AUDIO_N_CHANNELS
149+
).run()
152150

153-
duration = sox.file_info.duration(local_wav_path)
151+
duration = float(ffmpeg.probe(local_wav_path)["format"]["duration"])
154152
time_scale = np.arange(0, duration + ANNOTATION_HOP, ANNOTATION_HOP)
155153
n_time_frames = len(time_scale)
156154

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ data = [
5757
"apache_beam",
5858
"mirdata",
5959
"smart_open",
60-
"sox"
60+
"sox",
61+
"ffmpeg-python"
6162
]
6263
test = [
6364
"basic_pitch[data]",

0 commit comments

Comments
 (0)