Skip to content

h264_cuvid解码,前面4帧左右都是空 #1583

@lgbest123

Description

@lgbest123

采用以下代码进行硬解码,出现了前面4帧左右都是空的问题,一般4帧之后就没有问题了,ffmpeg版本:7.1.0;av版本:13.1.0
video = av.open(VIDEO_FILE_PATH)
#target_stream = video.streams.video[0]
#target_stream = next(s for s in video.streams if s.type == 'video')
target_stream = next((stream for stream in video.streams.video), None)

获取视频编码格式

codec_name = target_stream.codec_tag
codec = target_stream.codec_context.codec.name
print("encode_format: ", codec_name)
print("encode_format2: ", codec)

decoder = str(target_stream.codec_context).split()[1]
ctx = av.Codec('hevc_cuvid', 'r').create() if 'hevc' in decoder else av.Codec('h264_cuvid', 'r').create()
ctx.extradata = target_stream.extradata
print(ctx)
frame_index = 0
for packet in video.demux(target_stream):
print(packet)
frame = ctx.decode(packet)
print("hard_decode: ",frame)
frame = packet.decode()
print("soft_decode: ",frame)
frame_index += 1

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