求助, 与ffmpeg配合使用
因为没办法准确判断关键帧, 所以我尝试使用ffmpeg来解封装成AVPacket 然后在调用您的库写入hls或者mpeg_ts.
但是现在有一个很棘手的问题就是, 生成的文件播放时会花屏. 这个我觉得应该是dts的问题
AVRational time_base = {1,90000};
pkt->dts = (AV_NOPTS_VALUE == pkt->dts ? pkt->pts : pkt->dts);
pkt->pts = (AV_NOPTS_VALUE == pkt->pts ? pkt->dts : pkt->pts);
pkt->dts = av_rescale_q(pkt->dts, st->time_base, time_base);
pkt->pts = av_rescale_q(pkt->pts, st->time_base, time_base);
我写入时, 已经按照ts的基准时间转换过时间戳了. 应该不用在后续/90了吧?
[AVBSFContext @ 0x7fbe38055620] Invalid NAL unit 0, skipping.=0/0
Input #0, mpegts, from 'http://127.0.0.1:8081/proxy/aoshi.live.ts':
Duration: N/A, start: 3917.572000, bitrate: N/A
Program 1
Stream #0:0[0x101]: Audio: aac (HE-AAC) ([28][0][0][0] / 0x001C), 48000 Hz, stereo, fltp, 88 kb/s
Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
[h264 @ 0x7fbe3825da60] error while decoding MB 8 43, bytestream -6
[h264 @ 0x7fbe3825da60] concealing 201 DC, 201 AC, 201 MV errors in B frame
[h264 @ 0x7fbe38198480] error while decoding MB 47 13, bytestream -7
[h264 @ 0x7fbe38198480] concealing 2562 DC, 2562 AC, 2562 MV errors in P frame
[h264 @ 0x7fbe38209100] error while decoding MB 76 39, bytestream -5
[h264 @ 0x7fbe38209100] concealing 453 DC, 453 AC, 453 MV errors in P frame
[h264 @ 0x7fbe38279d80] error while decoding MB 41 14, bytestream -5
[h264 @ 0x7fbe38279d80] concealing 2488 DC, 2488 AC, 2488 MV errors in P frame
[h264 @ 0x7fbe380dfa00] error while decoding MB 10 23, bytestream -5
[h264 @ 0x7fbe380dfa00] concealing 1799 DC, 1799 AC, 1799 MV errors in P frame
[h264 @ 0x7fbe38279d80] error while decoding MB 43 12, bytestream -5
[h264 @ 0x7fbe38279d80] concealing 2646 DC, 2646 AC, 2646 MV errors in P frame
[h264 @ 0x7fbe38225420] error while decoding MB 37 42, bytestream -5
[h264 @ 0x7fbe38225420] concealing 252 DC, 252 AC, 252 MV errors in I frame
[h264 @ 0x7fbe380dfa00] error while decoding MB 48 28, bytestream -7
[h264 @ 0x7fbe380dfa00] concealing 1361 DC, 1361 AC, 1361 MV errors in P frame
[h264 @ 0x7fbe38198480] Reference 3 >= 3q= 126KB sq= 0B f=0/0
[h264 @ 0x7fbe38198480] error while decoding MB 70 25, bytestream -5
[h264 @ 0x7fbe38198480] concealing 1579 DC, 1579 AC, 1579 MV errors in P frame
[h264 @ 0x7fbe38241740] error while decoding MB 44 27, bytestream -7
[h264 @ 0x7fbe38241740] concealing 1445 DC, 1445 AC, 1445 MV errors in P frame
[h264 @ 0x7fbe38241740] error while decoding MB 17 20, bytestream -5
[h264 @ 0x7fbe38241740] concealing 2032 DC, 2032 AC, 2032 MV errors in P frame
[h264 @ 0x7fbe381d0ac0] error while decoding MB 37 10, bytestream -7
[h264 @ 0x7fbe381d0ac0] concealing 2812 DC, 2812 AC, 2812 MV errors in P frame
[aac @ 0x7fbe38011a40] channel element 2.4 is not allocated f=0/0
[aac @ 0x7fbe38011a40] Prediction is not allowed in AAC-LC.
[aac @ 0x7fbe38011a40] env_facs_q 255 is invalid
[h264 @ 0x7fbe38050780] error while decoding MB 6 26, bytestream -5
[h264 @ 0x7fbe38050780] concealing 1563 DC, 1563 AC, 1563 MV errors in B frame
[h264 @ 0x7fbe38198480] error while decoding MB 43 22, bytestream -7
[h264 @ 0x7fbe38198480] concealing 1846 DC, 1846 AC, 1846 MV errors in P frame
3938.84 A-V: -0.012 fd= 20 aq= 19KB vq= 106KB sq= 0B f=0/0
这次我读取hls, 使用ffmpeg解封装, 然后使用mpeg_muxer_input写入ts文件 但是写入的文件, ffplay播放时就一直花屏并且显示上面的错误.
看起来时p帧,b帧丢失了???我应该怎么做才能让mpeg_muxer_input正确写入?
确认下ffmpeg生成的avpacket数据内容是不是以00 00 00 01开始。
说实话ffmpeg真心没有大佬您的库好用.
就最简单的使用avio_alloc_context来自定义读数据
av_read_frame读取时候, 如果数据没有填充及时, 直接给你返回的avpaket就是不完整的. 如果数据来源时内存, 只能开线程, 确保av_read_frame读数据时候都有数据存在. 还是您的库好用, 采用通知回调的方式.
h264关键帧识别的代码估计周六能写完,不着急可以等2天。
不着急, 大佬先忙正事, 工作要紧.
我等您好了.
ffmpeg真心搞的头大, 上面说的花屏的问题解决了, 把av_read_frame放到单独的线程中去, 他读取数据时, 如果没有足够的数据就阻塞掉, 而不是返回错误. 就避免了av_read_frame解析出现帧不全时丢失数据.
虽然通过mpeg_muxer_input写入ts流. 客户端播放时不花屏了, 但是有时候几分钟都正常, 有时候很快就会出现一堆错误, 不知道什么原因. av_read_frame也没有报错, 数据也肯定都是读全的. mpeg_muxer_input((::mpeg_muxer_t *)_context, track_id, _key_pos ? 0x0001 : 0, frame->pts() * 90LL,frame->dts() * 90LL, frame->data(), frame->size()); 也没有报错.
[aac @ 0x7fdadc537900] Multiple frames in a packet.
[aac @ 0x7fdadc537900] Number of bands (21) exceeds limit (5).
[aac @ 0x7fdadc537900] Sample rate index in program config element does not match the sample rate index configured by the container.
[h264 @ 0x7fdadc045da0] co located POCs unavailable
[aac @ 0x7fdadc537900] Inconsistent channel configuration.0B f=0/0
[aac @ 0x7fdadc537900] get_buffer() failed
[aac @ 0x7fdadc537900] channel element 1.0 is not allocated
[aac @ 0x7fdadc537900] channel element 3.14 is not allocated
[aac @ 0x7fdadc537900] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x7fdadc537900] Inconsistent channel configuration.
[aac @ 0x7fdadc537900] get_buffer() failed
[aac @ 0x7fdadc537900] Number of bands (50) exceeds limit (47).
[aac @ 0x7fdadc537900] Reserved bit set.
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
[aac @ 0x7fdadc537900] channel element 3.8 is not allocated
[aac @ 0x7fdadc537900] Number of bands (63) exceeds limit (47).
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
[aac @ 0x7fdadc537900] Invalid bitstream, too many QMF subbands: -10
[aac @ 0x7fdadc537900] SBR reset failed. Switching SBR to pure upsampling mode.
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
Last message repeated 3 times
[aac @ 0x7fdadc537900] invalid band type
[aac @ 0x7fdadc537900] Reserved bit set.
[aac @ 0x7fdadc537900] Prediction is not allowed in AAC-LC.
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
Last message repeated 6 times
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
Last message repeated 1 times
[aac @ 0x7fdadc537900] channel element 3.8 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 3.4 is not allocatedB f=0/0
Last message repeated 1 times
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] Number of bands (54) exceeds limit (47).0/0
[aac @ 0x7fdadc537900] channel element 3.2 is not allocated
[aac @ 0x7fdadc537900] channel element 2.11 is not allocated
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 3.8 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] Number of bands (49) exceeds limit (47).
[aac @ 0x7fdadc537900] channel element 0.0 is not allocated
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] invalid band type
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] TNS filter order 25 is greater than maximum 12.
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] Number of bands (53) exceeds limit (47).
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 0.0 is not allocatedB f=0/0
[aac @ 0x7fdadc537900] channel element 3.8 is not allocatedB f=0/0
总之您这个库, 我用起来真心的舒服. 可惜了, 就是你这个项目没有好好推广下, 如果能补齐文档, 然后好好推广下, 肯定会火.
如果有需要, 我可以有空可以写一些文档给您.只是水平有限, 需要一边学习一边写.
另外还有一个问题就是 mpeg_ts_write 中的sdt, 我看好像有些生成的流有写入, 有些没有. 这是为什么?
如果有需要, 我可以有空可以写一些文档给您.只是水平有限, 需要一边学习一边写
欢迎补充文档!
SDT目前只在第一个ts包中写入了,后面都没有再写。
如果需要重复生成SDT,可以修改SDT生成逻辑。
说实话ffmpeg真心没有大佬您的库好用.
就最简单的使用avio_alloc_context来自定义读数据
av_read_frame读取时候, 如果数据没有填充及时, 直接给你返回的avpaket就是不完整的.
如果数据来源时内存, 只能开线程, 确保av_read_frame读数据时候都有数据存在.
还是您的库好用, 采用通知回调的方式.
Chen @.***> 于2022年3月10日周四 09:09写道:
确认下ffmpeg生成的avpacket数据内容是不是以00 00 00 01开始。
— Reply to this email directly, view it on GitHub https://github.com/ireader/media-server/issues/206#issuecomment-1063544469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3RPRLNN634CGP2GAOPE4TU7FDVRANCNFSM5QKCBLGA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
方便参考一下您的demo么