ffmpeg flv missing PTS

问题

在对接某几款海康ipc时,通过ffmpeg - rstp … -f flv rtmp://…. 时会导致ffmpeg 命令失败,报错如下

1
2
3
[flv @ 0x940bc0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[flv @ 0x940bc0] Packet is missing PTS
av_interleaved_write_frame(): Invalid argument

解决

这个问题在ffmpeg 4.2.2 版本中正常, 比对ffmpeg4.2.2 和 ffmpeg 4.3.2 的flvenc.c 代码
删除 flv_write_packet 函数中 如下代码

1
2
3
4
5
6
7
8
9
10
11
if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) {

if (pkt->pts == AV_NOPTS_VALUE) {

av_log(s, AV_LOG_ERROR, "Packet is missing PTS\n");

return AVERROR(EINVAL);

}

}