Search code examples
pythonffmpeg

When I run this it is showing ffmpeg has no attribute input. How to solve this?


def extract_audio_from_video(file_path: str) -> np.ndarray:
    inputfile = ffmpeg.input(file_path)
    out = inputfile.output('-', format='f32le', acodec='pcm_f32le', ac=1, ar='44100')
    raw = out.run(capture_stdout=True)
    del inputfile, out
    return np.frombuffer(raw[0],np.float32)

Solution

  • If you'd like to explore a different option, check out [my ffmpegio package:

    pip install ffmpegio
    
    import ffmpegio
    
    fs,x = ffmpegio.audio.read(file_path, sample_fmt='f32le', ac=1, ar=44100)
    # fs - actual sampling rate
    # x - [nx1] numpy array