Getting Errno. 22 on line 112 of test_effects.py
MODIFY
nussl/core/effects.py
nussl/core/effects.py
@@ -7,6 +7,8 @@ import warnings
import ffmpeg
import tempfile
from pysndfx import AudioEffectsChain
+import av
+from av.filter import Filter, Graph
from .constants import LEVEL_MIN, LEVEL_MAX
from .utils import _close_temp_files
@@ -23,9 +25,17 @@ class FilterFunction():
return self.func(stream)
class FFmpegFilter(FilterFunction):
+ @staticmethod
+ def _dict_to_ffmpeg_kwargs(dictionary):
+ str_params = []
+ for key, value in dictionary.items():
+ str_params.append(f"{key}={value}")
+ return ":".join(str_params)
+
def __init__(self, _filter, **filter_kwargs):
self.filter = _filter
- self.func = lambda stream: stream.filter(_filter, **filter_kwargs)
+ self.func = lambda graph: graph.add(_filter,
+ FFmpegFilter._dict_to_ffmpeg_kwargs(filter_kwargs))
class SoXFilter(FilterFunction):
def __init__(self, _filter, **filter_kwargs):
@@ -56,23 +66,65 @@ def build_effects_ffmpeg(audio_signal, filters, silent=False):
tmpfiles = []
- input_args = {}
- if silent:
- input_args['loglevel'] = 'quiet'
+ # input_args = {}
+ # if silent:
+ # input_args['loglevel'] = 'quiet'
with _close_temp_files(tmpfiles):
curr_tempfile = tempfile.NamedTemporaryFile(suffix=".wav")
- audio_signal.write_audio_to_file(curr_tempfile)
+ output_tempfile = tempfile.NamedTemporaryFile(suffix=".wav")
tmpfiles.append(curr_tempfile)
- stream = ffmpeg.input(curr_tempfile.name, **input_args)
- for _filter in filters:
- stream = _filter(stream)
- (stream
- .output(curr_tempfile.name)
- .overwrite_output()
- .run()
+ tmpfiles.append(output_tempfile)
+ audio_signal.write_audio_to_file(curr_tempfile)
+
+ in_cont = av.open(curr_tempfile.name, mode='r')
+ out_cont = av.open(output_tempfile.name, mode='w')
+
+ in_stream = in_cont.streams.audio[0]
+ out_stream = out_cont.add_stream(
+ codec_name=in_stream.codec_context.codec,
+ rate=audio_signal.sample_rate
+ )
+ # out_stream = out_count.add_stream(template=in_stream)
+
+ buffer_args = "sample_rate=%d:sample_fmt=%s:channel_layout=%s:time_base=%d/%d" % (
+ in_stream.rate, in_stream.format.name,
+ in_stream.layout.name,
+ 1, in_stream.rate,
)
- augmented_signal = AudioSignal(path_to_input_file=curr_tempfile.name)
+
+ print(buffer_args)
+
+ graph = Graph()
+ fchain = [graph.add('abuffer', buffer_args)]
+ for _filter in filters:
+ fchain.append(_filter(graph))
+ fchain[-2].link_to(fchain[-1])
+
+ fchain.append(graph.add("abuffersink"))
+ fchain[-2].link_to(fchain[-1])
+
+ graph.configure()
+
+ for in_frame in in_cont.decode(in_stream):
+ graph.push(in_frame)
+ out_frame = graph.pull()
+ for out_packet in out_stream.encode(out_frame):
+ out_cont.mux(out_packet)
+
+ out_cont.close()
+
+ # tmpfiles.append(curr_tempfile)
+ # stream = ffmpeg.input(curr_tempfile.name, **input_args)
+ # for _filter in filters:
+ # stream = _filter(stream)
+ # (stream
+ # .output(curr_tempfile.name)
+ # .overwrite_output()
+ # .run()
+ # )
+
+ augmented_signal = AudioSignal(path_to_input_file=output_tempfile.name)
return augmented_signal
def build_effects_sox(audio_signal, filters):

MODIFY
tests/core/test_effects.py
tests/core/test_effects.py
@@ -8,6 +8,7 @@ import os
import os.path as path
import librosa
import pytest
+import logging
REGRESSION_PATH="tests/core/regression/augmentation"
os.makedirs(REGRESSION_PATH, exist_ok=True)
@@ -53,6 +54,7 @@ def test_params(mix_and_sources):
effects.pitch_shift("this is a string")
def test_tremolo(mix_and_sources, check_against_regression_data):
+ logging.basicConfig()
f = 15
d = .5
signal, _ = mix_and_sources

Getting Errno. 22 on line 112 of test_effects.py