not properly using ffmpeg

I am following this tutorial about hardware-accelerated gpu encoding/decoding for PyTorch [Hardware-Accelerated Video Decoding and Encoding — Torchaudio nightly documentation], I am encountering an error with the following code:

import torch
import torchaudio

print(torch.__version__) # 1.14.0.dev20221013+cu116
print(torchaudio.__version__) # 0.13.0.dev20221013+cu116
print(torchaudio._extension._FFMPEG_INITIALIZED) # True

from import StreamReader, StreamWriter
local_src = "vid.mp4"
cuda_conf = {
    "decoder": "h264_cuvid",  # Use CUDA HW decoder
    "hw_accel": "cuda:0",  # Then keep the memory on CUDA:0

def decode_vid(src, config):
    frames = []
    s = StreamReader(src)
    s.add_video_stream(5, **config)
    for i, (chunk,) in enumerate(

if __name__ == "__main__":
    vid = decode_vid(local_src, cuda_conf)

The error message (somewhat truncated) is:

line 23, in decode_vid
s.add_video_stream(5, **config) File “/home/james/anaconda3/envs/alphapose/lib/python3.7/site-packages/torchaudio/io/”,
line 624, in add_video_stream
hw_accel, RuntimeError: Unsupported codec: “h264_cuvid”.

I have an RTX 3090 ti as my GPU, which does support the h264_cuvid, and I have been able to decode a video on the command line running (taken from the tutorial linked above)

sudo ffmpeg -hide_banner -y -vsync 0 -hwaccel cuvid -hwaccel_output_format cuda -c:v h264_cuvid -i "" -c:a copy -c:v h264_nvenc -b:v 5M test.mp4

So it seems is not properly using ffmpeg. Any insights of how to fix this problem much appreciated. I’m using Ubuntu 22.04.