您需要使用AVC解码器配置记录填写extradata,而不仅仅是SPS / PPS
以下是记录的外观: AVCDCR
我终于找到了解决方案。我的MP4现在可以在Chrome中播放(同时还在其他经过测试的浏览器中播放)。
在Chrome中 铬://媒体内部/ 显示MSE日志(排序)。当我看到那里时,我发现了一些针对我的测试玩家的警告:
ISO-BMFF container metadata for video frame indicates that the frame is not a keyframe, but the video frame contents indicate the opposite.
这让我思考和鼓励设定 AV_PKT_FLAG_KEY 对于具有关键帧的数据包。我将以下代码添加到填充部分 AVPacket 结构体:
AV_PKT_FLAG_KEY
AVPacket
//Check if keyframe field needs to be set int allowedNalsCount = 3; //In one packet there would be at most three NALs: SPS, PPS and video frame packet.flags = 0; for(int i = 0; i < frameSize && allowedNalsCount > 0; ++i) { uint32_t *curr = (uint32_t*)(frameBuffer + i); if(*curr == synchMarker) { uint8_t nalType = frameBuffer[i + sizeof(uint32_t)] & 0x1F; if(nalType == KEYFRAME) { std::cout << "Keyframe detected at frame nr " << framesTotal << std::endl; packet.flags = AV_PKT_FLAG_KEY; break; } else i += sizeof(uint32_t) + 1; //We parsed this already, no point in doing it again --allowedNalsCount; } }
一个 KEYFRAME 事实证明是 0x5 在我的情况下(切片IDR)。
KEYFRAME
0x5
两个文件的MP4原子看起来非常相似(它们具有相同的avcc 部分肯定)
仔细检查一下,提供的代码不同于我。
什么是有趣的(但不确定它是否有任何重要性),两者都有 文件具有与输入文件不同的NAL格式(RPI相机产生 附件B格式的视频流,而输出MP4文件包含NAL AVCC格式......或者至少看起来比较我的情况 输入H264数据的mdat原子)。
这非常重要,mp4不适用于附件b。