Skip to content

VideoFrame.to_ndarray(format="rgb24") raises [Errno 95] Operation not supported for NVDEC frames with reserved colorspace metadata (regression from 16.1.0) #2208

Closed

Description

@bazookanu

Calling VideoFrame.to_ndarray(format="rgb24") on frames decoded by h264_cuvid/hevc_cuvid (NVDEC) raises [Errno 95] Operation not supported in 17.0.0.

This worked correctly in 16.1.0.

Error

[swscaler] Unsupported input (Operation not supported): fmt:nv12 csp:gbr prim:reserved trc:reserved -> fmt:rgb24 csp:gbr prim:reserved trc:reserved OSError: [Errno 95] Operation not supported

Reproducing

import av                                                                                                          
                  
codec = av.Codec("hevc_cuvid", "r")                                                                                
ctx = av.CodecContext.create(codec)
ctx.options = {"surfaces": "8"}                                                                                    
                                                                                                                   
with open("sample.h265", "rb") as f:                                                                               
    raw = f.read()                                                                                                 
                                                                                                                   
packet = av.Packet(raw)                                                                                            
frames = ctx.decode(packet)                                                                                        
for frame in frames:                                                                                               
    img = frame.to_ndarray(format="rgb24")  # raises in 17.0.0, works in 16.1.0
  • PyAV 16.1.0: works
  • PyAV 17.0.0: fails
  • Decoder: hevc_cuvid (NVDEC)
  • Source streams: H.265

Activity

  1. neon-ninja commented on Jun 23, 2026

    @neon-ninja

    I think the scope of this bug is a bit wider than you think. It seems to occur with VP9 too. Here's a yt-dlp command to download a sample video file:

    yt-dlp -o video.mp4 https://www.facebook.com/healthPluspharmacyng/videos/menopause-is-a-natural-phase-of-life-that-every-woman-will-experience-yet-it-oft/1498212924203766/

    Here's a test script using that video file:

    #!/usr/bin/env python
    import av
    print(av.__version__)
    import sys
    
    container = av.open("video.mp4")
    frame = next(container.decode(video=0))
    
    print("colorspace:", frame.colorspace)
    print("color_range:", frame.color_range)
    print("color_primaries:", getattr(frame, "color_primaries", None))
    print("format:", frame.format.name)
    print("hwaccel:", getattr(frame, "hwaccel", None))
    print("is_corrupt:", frame.is_corrupt)
    for i, plane in enumerate(frame.planes):
        print(f"\nPlane {i}")
        print("  buffer_size:", plane.buffer_size)
        print("  stride (linesize):", plane.line_size)
        print("  ptr type:", type(plane))
    print("\nFrame layout:")
    print(frame)
    
    for fmt in [
        "rgb24",
        "bgr24",
        "gray",
        "yuv420p",
    ]:
        try:
            x = frame.to_ndarray(format=fmt)
            print(fmt, "OK", x.shape)
        except Exception as e:
            print(fmt, "FAIL", repr(e))

    This script outputs:

    17.1.0
    colorspace: 2
    color_range: 1
    color_primaries: 3
    format: yuv420p
    hwaccel: None
    is_corrupt: False
    
    Plane 0
      buffer_size: 2211840
      stride (linesize): 1152
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Plane 1
      buffer_size: 552960
      stride (linesize): 576
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Plane 2
      buffer_size: 552960
      stride (linesize): 576
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Frame layout:
    <av.VideoFrame, pts=0 yuv420p 1080x1920 at 0x7fa89d4a6140>
    rgb24 FAIL OSError(95, 'Operation not supported')
    bgr24 FAIL OSError(95, 'Operation not supported')
    gray FAIL OSError(95, 'Operation not supported')
    yuv420p OK (2880, 1080)

    after downgrading to av<17, it outputs:

    16.1.0
    colorspace: 2
    color_range: 1
    color_primaries: None
    format: yuv420p
    hwaccel: None
    is_corrupt: False
    
    Plane 0
      buffer_size: 2211840
      stride (linesize): 1152
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Plane 1
      buffer_size: 552960
      stride (linesize): 576
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Plane 2
      buffer_size: 552960
      stride (linesize): 576
      ptr type: <class 'av.video.plane.VideoPlane'>
    
    Frame layout:
    <av.VideoFrame, pts=0 yuv420p 1080x1920 at 0x7f8e61399fc0>
    rgb24 OK (1920, 1080, 3)
    bgr24 OK (1920, 1080, 3)
    gray OK (1920, 1080)
    yuv420p OK (2880, 1080)
    ffprobe video.mp4

    outputs:

    ffprobe version 6.1.1-3ubuntu5 Copyright (c) 2007-2023 the FFmpeg developers
      built with gcc 13 (Ubuntu 13.2.0-23ubuntu3)
      configuration: --prefix=/usr --extra-version=3ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --disable-omx --enable-gnutls --enable-libaom --enable-libass --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libharfbuzz --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-openal --enable-opencl --enable-opengl --disable-sndio --enable-libvpl --disable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-ladspa --enable-libbluray --enable-libjack --enable-libpulse --enable-librabbitmq --enable-librist --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libx264 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-sdl2 --enable-libplacebo --enable-librav1e --enable-pocketsphinx --enable-librsvg --enable-libjxl --enable-shared
      libavutil      58. 29.100 / 58. 29.100
      libavcodec     60. 31.102 / 60. 31.102
      libavformat    60. 16.100 / 60. 16.100
      libavdevice    60.  3.100 / 60.  3.100
      libavfilter     9. 12.100 /  9. 12.100
      libswscale      7.  5.100 /  7.  5.100
      libswresample   4. 12.100 /  4. 12.100
      libpostproc    57.  3.100 / 57.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2mp41
        title           : 402311786265573
        encoder         : Lavf60.16.100
      Duration: 00:01:26.10, start: 0.000000, bitrate: 3311 kb/s
      Stream #0:0[0x1](und): Video: vp9 (Profile 0) (vp09 / 0x39307076), yuv420p(tv, unknown/reserved/reserved, progressive), 1080x1920, 3177 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
        Metadata:
          handler_name    : VideoHandler
          vendor_id       : [0][0][0][0]
          encoder         : Lavc60.31.102 libeve-vp9
      Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
          vendor_id       : [0][0][0][0]

    My browser also fails to play this video, but VLC works

  2. added a commit that references this issue on Jul 1, 2026
    52b8f6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions