我在编写从RTP数据包到MP4文件的h264帧时遇到了问题.视频播放(例如)命令avplay/ffplay,但我收到这些错误:
[h264 @ 0x7faebc006d40] no frame!0KB vq= 79KB sq= 0B f=0/9
Run Code Online (Sandbox Code Playgroud)
当然,看起来有些帧错过了.我写数据包的方式如下:
如果我们找到了PPS和SPS表,那么创建MP4文件:
char*application_name ="isom"; _mp4file = MP4CreateEx(name,0,1,1,application_name,1);
然后创建VideoTrack:
_video = MP4AddH264VideoTrack(_mp4file, _videoTimeScale, _videoTimeScale / _videoSampleDuration, _videoWidth, _videoHeight,
_sps->getData()[1], //sps[1] AVCProfileIndication
_sps->getData()[2], //sps[2] profile_compat
_sps->getData()[3], //sps[3] AVCLevelIndication
3); // 4 (minusOne) bytes length before each NAL unit
Run Code Online (Sandbox Code Playgroud)
并设置一些东西:
MP4SetVideoProfileLevel(_mp4file, 0x7F);
MP4AddH264SequenceParameterSet(_mp4file, _video, _sps->getData(), _sps->getSize());
MP4AddH264PictureParameterSet(_mp4file, _video, _pps->getData(), _pps->getSize());
Run Code Online (Sandbox Code Playgroud)从列表到文件刷新等待帧,在开头的Big Endian中添加了帧大小:
MP4WriteSample(_mp4file, _video, waitingFrame->getDataWithNalSize(), waitingFrame->getSize(), MP4_INVALID_DURATION, 0, 1);Run Code Online (Sandbox Code Playgroud)MP4WriteSample(_mp4file, _video, …Run Code Online (Sandbox Code Playgroud)