Skip to content

VA-API encoding fails on Ubuntu 25.10 with PyAV 16.1.0 #2156

@calllivecn

Description

@calllivecn

Description: I am encountering an issue with VA-API encoding using PyAV. While decoding via VA-API works as expected, encoding fails.

Environment:

OS: Ubuntu 25.10

FFmpeg Version: 7.1.1

PyAV Version: v16.1.0 (Installed from source via pip install av --no-binary av)

Test Script: 04-使用lavfi实际测试vaapi.py

Output and Error Logs:

 ==================== 测试编码器: h264_vaapi ====================                                                                       
2026-02-05 21:47:11,657 - INFO - 04-使用lavfi实际测试vaapi.py:196 - 开始测试硬件解码: h264_vaapi                                        
                                                                                                                                        
2026-02-05 21:47:12,475 - INFO - 04-使用lavfi实际测试vaapi.py:231 - 硬件解码测试成功: h264_vaapi                                        
测试 h264_vaapi 解码 成功。                                                                                                             
2026-02-05 21:47:12,485 - INFO - 04-使用lavfi实际测试vaapi.py:137 - 开始测试硬件编码: h264_vaapi                                        
2026-02-05 21:47:12,503 - ERROR - 04-使用lavfi实际测试vaapi.py:187 - 硬件编码测试失败 h264_vaapi: [Errno 22] Invalid argument: 'avcodec_open2(h264_vaapi)'                                                                                                                      
Traceback (most recent call last):                                                                                                      
  File "/code/04-使用lavfi实际测试vaapi.py", line 172, in test_hardware_encoding                                                        
    for packet_encode in output_stream.encode(frame):                                                                                   
                         ~~~~~~~~~~~~~~~~~~~~^^^^^^^                
  File "av/video/stream.py", line 25, in av.video.stream.VideoStream.encode                                                             
    @cython.ccall                                                                                                                       
    ^^^^^^^                                                                                                                             
  File "av/video/stream.py", line 35, in av.video.stream.VideoStream.encode                                                             
    packets = self.codec_context.encode(frame)                                                                                          
    ^^^                                                                                                                                                                                                                                                                         
  File "av/codec/context.pyx", line 410, in av.codec.context.CodecContext.encode                                                        
    for frame in self._prepare_and_time_rebase_frames_for_encode(frame):                                                                
    ^^^                                                      
  File "av/codec/context.pyx", line 395, in av.codec.context.CodecContext._prepare_and_time_rebase_frames_for_encode                    
    self.open(strict=False)                                                                                                             
    ^^^                                                                                                                                 
  File "av/codec/context.pyx", line 220, in av.codec.context.CodecContext.open                                                          
    err_check(lib.avcodec_open2(self.ptr, self.codec.ptr, &options.ptr), "avcodec_open2(" + self.codec.name + ")")
    ^^^
  File "av/error.pyx", line 424, in av.error.err_check
    raise cls(code, message, filename, log)
    ^^^
av.error.ValueError: [Errno 22] Invalid argument: 'avcodec_open2(h264_vaapi)'
测试 h264_vaapi 编码 失败。
 ==================== 测试编码器: hevc_vaapi ====================
2026-02-05 21:47:12,505 - INFO - 04-使用lavfi实际测试vaapi.py:196 - 开始测试硬件解码: hevc_vaapi
2026-02-05 21:47:13,850 - INFO - 04-使用lavfi实际测试vaapi.py:231 - 硬件解码测试成功: hevc_vaapi
测试 hevc_vaapi 解码 成功。
2026-02-05 21:47:13,870 - INFO - 04-使用lavfi实际测试vaapi.py:137 - 开始测试硬件编码: hevc_vaapi
2026-02-05 21:47:13,900 - ERROR - 04-使用lavfi实际测试vaapi.py:187 - 硬件编码测试失败 hevc_vaapi: [Errno 22] Invalid argument: 'avcodec_open2(hevc_vaapi)'
Traceback (most recent call last):
  File "/code/04-使用lavfi实际测试vaapi.py", line 172, in test_hardware_encoding 
    for packet_encode in output_stream.encode(frame):
                         ~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "av/video/stream.py", line 25, in av.video.stream.VideoStream.encode
    @cython.ccall
    ^^^^^^^
  File "av/video/stream.py", line 35, in av.video.stream.VideoStream.encode
    packets = self.codec_context.encode(frame)
    ^^^
  File "av/codec/context.pyx", line 410, in av.codec.context.CodecContext.encode
    for frame in self._prepare_and_time_rebase_frames_for_encode(frame):
    ^^^
  File "av/codec/context.pyx", line 395, in av.codec.context.CodecContext._prepare_and_time_rebase_frames_for_encode
    self.open(strict=False)
    ^^^
  File "av/codec/context.pyx", line 220, in av.codec.context.CodecContext.open
    err_check(lib.avcodec_open2(self.ptr, self.codec.ptr, &options.ptr), "avcodec_open2(" + self.codec.name + ")")
    ^^^
  File "av/error.pyx", line 424, in av.error.err_check
    raise cls(code, message, filename, log)
    ^^^
av.error.ValueError: [Errno 22] Invalid argument: 'avcodec_open2(hevc_vaapi)'
测试 hevc_vaapi 编码 失败。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions