ireader / media-server

RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
MIT License
3.05k stars 1.07k forks source link

丢弃不完整的帧 #190

Open alexliyu7352 opened 2 years ago

alexliyu7352 commented 2 years ago

当做拉取hls转ts流的时候, 如果遇到拉取hls分片超时, 那么最终输出的ts流, 在播放器里面就会卡住. 因为解码失败, 实际上就是这个问题https://github.com/ZLMediaKit/ZLMediaKit/issues/1348

能否增加一个接口, 判断输出的帧是否完整?如果不完整就可以选择丢弃.

ireader commented 2 years ago

commit id: 6e6319aad1267af93e6b83c1a19a39f8ffc2315d TS/PS回调增加了2个标记

alexliyu7352 commented 2 years ago

明白了, 大佬太给力了! 我给zlm提交了好些pr, 也想给您的项目一些贡献. 但是编解码这块实在是有心无力.

但是真希望能给您的项目尽尽力

Chen @.***> 于2022年1月13日周四 18:07写道:

commit id: 6e6319aad1267af93e6b83c1a19a39f8ffc2315d TS/PS回调增加了2个标记

  • MPEG_FLAG_PACKET_CORRUPT: 当前回调帧数据不全,一般是丢帧导致,通常情况下应该丢弃
  • MPEG_FLAG_PACKET_LOST: 当前回调帧是完整的,但是前面有数据丢失,不能保证本帧可以正常解码。 通常需要判断是否有关键帧标记

— Reply to this email directly, view it on GitHub https://github.com/ireader/media-server/issues/190#issuecomment-1011983892, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3RPRITEWINEALCNXSFWNDUV2P7TANCNFSM5L3KNGLA . 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: @.***>

alexliyu7352 commented 2 years ago

我想请问下, 在实际使用中 MPEG_FLAG_PACKET_CORRUPT基本上不会看到, 是么? 因为您代码中 assert(pes->pkt.size == pes->len || (pkt->flags & MPEG_FLAG_PACKET_CORRUPT)); // packet lost 这里就直接触发了断言了.所以在ts_demuxer_create的回调中是看不到这个flag的?

ireader commented 2 years ago

如果发生了音频丢包就会出现MPEG_FLAG_PACKET_CORRUPT。

assert(pes->pkt.size == pes->len || (pkt->flags & MPEG_FLAG_PACKET_CORRUPT)); 这个assert两个条件,正常情况下应该是满足pes->pkt.size == pes->len,发生丢包时会pkt->flags & MPEG_FLAG_PACKET_CORRUPT. 当然,丢包也可能能满足第一个条件,但是长时间运行肯定会触发pkt->flags & MPEG_FLAG_PACKET_CORRUPT.

alexliyu7352 commented 2 years ago

所以, 也就是在回调中看不到flag==MPEG_FLAG_PACKET_CORRUPT? 因为断言提前触发了

Chen @.***> 于2022年1月22日周六 19:13写道:

如果发生了音频丢包就会出现MPEG_FLAG_PACKET_CORRUPT。

assert(pes->pkt.size == pes->len || (pkt->flags & MPEG_FLAG_PACKET_CORRUPT)); 这个assert两个条件,正常情况下应该是满足pes->pkt.size == pes->len,发生丢包时会pkt->flags & MPEG_FLAG_PACKET_CORRUPT. 当然,丢包也可能能满足第一个条件,但是长时间运行肯定会触发pkt->flags & MPEG_FLAG_PACKET_CORRUPT.

— Reply to this email directly, view it on GitHub https://github.com/ireader/media-server/issues/190#issuecomment-1019190712, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3RPRIL4XMHBW7IRY7VGZ3UXKGODANCNFSM5L3KNGLA . 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: @.***>

ireader commented 2 years ago

可以看到MPEG_FLAG_PACKET_CORRUPT标记的。

mpeg_ts_dec_test.cpp 文件中有判断例子。

alexliyu7352 commented 2 years ago
if(thiz->_on_decode){
            if(flags & MPEG_FLAG_PACKET_CORRUPT) {
                WarnL << "ts packet lost, dts:" << dts << " pts:" << pts << " bytes:" << bytes;
            }else{
                thiz->_on_decode(stream, codecid, flags, pts, dts, data, bytes);
            }
        }

我直接这样使用, 如果发现不正确包, 直接丢弃掉. 看日志, 在网络抖动时, 有可能拉流超时导致包不完整, 所以已经捕捉到了, 感谢大佬