K3上的ffmpeg命令行参数无效
环境信息
| 项目 | 值 |
|---|---|
| 板卡 | K3 Pico-ITX (SpacemiT) |
| 系统 | Bianbu 4.0.1 (Resolute Raccoon) |
| 内核 | 6.18.3-generic #1.0.2.4 SMP PREEMPT_DYNAMIC riscv64 |
| FFmpeg | 7:8.0.1-3ubuntu2bb1 (with --enable-stcodec --extra-libs=-lspacemit_mpp) |
| 编码驱动 | CONFIG_VIDEO_LINLON_K3=y (V4L2 LinlonV5V7 硬件编码器) |
问题概述
FFmpeg h264_stcodec 和 hevc_stcodec 等硬件编码器忽略所有通用及私有编码参数,以固定 QP 默认值运行。-b:v、-g、-r、-profile 等参数完全无效。
验证方法
# 使用不同参数编码同一源文件
ffmpeg -i /tmp/test.y4m -c:v h264_stcodec -b:v 500k -an /tmp/out_500k.h264
ffmpeg -i /tmp/test.y4m -c:v h264_stcodec -b:v 10000k -an /tmp/out_10m.h264
ffmpeg -i /tmp/test.y4m -c:v h264_stcodec -g 5 -an /tmp/out_g5.h264
ffmpeg -i /tmp/test.y4m -c:v h264_stcodec -g 1 -an /tmp/out_g1.h264
# 所有输出文件完全一致(byte-identical)
md5sum /tmp/out_*.h264
原因分析
1. stVencPara 字段未映射
stcodecenc.c::stcodec_init_encoder() 中,调用 VENC_Init() 之前仅设置了以下字段:
encoder->mpp_venc_ctx->stVencPara.eCodingType = codectype;
encoder->mpp_venc_ctx->stVencPara.nWidth = avctx->width;
encoder->mpp_venc_ctx->stVencPara.nHeight = avctx->height;
encoder->mpp_venc_ctx->stVencPara.nStride = get_stride(...);
encoder->mpp_venc_ctx->stVencPara.PixelFormat = stcodec_get_pixelformat(avctx);
encoder->mpp_venc_ctx->stVencPara.eFrameBufferType = MPP_FRAME_BUFFERTYPE_NORMAL_EXTERNAL;
encoder->mpp_venc_ctx->eCodecType = CODEC_V4L2_LINLONV5V7;
缺失字段:nBitrate、nFrameRate、nProfile、nRotateDegree。其中 nBitrate 和 nFrameRate 是 MPP 硬件编码器的基本参数,未设置则硬件使用默认值(0)。
2. VENC_SetParam 从未调用
VENC_Init() 之后,代码从未调用 VENC_SetParam() 来配置:
- 码率控制:
MPP_VENC_CMD_SET_CBR_RATE_CONTROL_PARAM等 - GOP/QP:
MPP_VENC_CMD_SET_PARAM_H264_CBR/HEVC_CBR等 - 镜像、切片间距 等其他硬件参数
3. 硬件默认行为
LinlonV5V7 编码器在 VENC_Init 时默认配置为 rate_control=off,固定 QP:
- HEVC: IQP=35, PQP=30
- H.264: 类似固定 QP 配置
因此无论 FFmpeg 命令行传入什么参数,硬件始终以固定 QP 编码。