mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
修复一些mp4点播不支持的问题
This commit is contained in:
parent
048b30c41c
commit
d363871601
@ -1 +1 @@
|
||||
Subproject commit 97cf5e47a5af1ff3d4d187f3ebffd9254595df75
|
||||
Subproject commit 24519a594c2c634b21fbe09fad28d54c4eba0885
|
@ -142,7 +142,9 @@ struct Context{
|
||||
BufferRaw::Ptr buffer;
|
||||
};
|
||||
|
||||
Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame) {
|
||||
Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) {
|
||||
keyFrame = false;
|
||||
eof = false;
|
||||
static mov_reader_onread mov_reader_onread = [](void *param, uint32_t track_id, const void *buffer, size_t bytes, int64_t pts, int64_t dts, int flags) {
|
||||
Context *ctx = (Context *) param;
|
||||
ctx->pts = pts;
|
||||
@ -162,18 +164,22 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame) {
|
||||
Context ctx = {this, 0};
|
||||
auto ret = mov_reader_read2(_mov_reader.get(), mov_onalloc, mov_reader_onread, &ctx);
|
||||
switch (ret) {
|
||||
case 0 :
|
||||
case 0 : {
|
||||
eof = true;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
case 1 : {
|
||||
keyFrame = ctx.flags & MOV_AV_FLAG_KEYFREAME;
|
||||
return makeFrame(ctx.track_id, ctx.buffer, ctx.pts, ctx.dts);
|
||||
}
|
||||
|
||||
default:
|
||||
default : {
|
||||
eof = true;
|
||||
WarnL << "读取mp4文件数据失败:" << ret;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Parent>
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
MP4Demuxer(const char *file);
|
||||
~MP4Demuxer() override;
|
||||
int64_t seekTo(int64_t stamp_ms);
|
||||
Frame::Ptr readFrame(bool &keyFrame);
|
||||
Frame::Ptr readFrame(bool &keyFrame, bool &eof);
|
||||
vector<Track::Ptr> getTracks(bool trackReady) const override ;
|
||||
uint64_t getDurationMS() const;
|
||||
private:
|
||||
|
@ -48,11 +48,10 @@ MP4Reader::MP4Reader(const string &strVhost,const string &strApp, const string &
|
||||
bool MP4Reader::readSample() {
|
||||
bool keyFrame = false;
|
||||
bool eof = false;
|
||||
while (true) {
|
||||
auto frame = _demuxer->readFrame(keyFrame);
|
||||
while (!eof) {
|
||||
auto frame = _demuxer->readFrame(keyFrame, eof);
|
||||
if (!frame) {
|
||||
eof = true;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
_mediaMuxer->inputFrame(frame);
|
||||
if (frame->dts() > getCurrentStamp()) {
|
||||
@ -122,11 +121,12 @@ bool MP4Reader::seekTo(uint32_t ui32Stamp){
|
||||
}
|
||||
//搜索到下一帧关键帧
|
||||
bool keyFrame = false;
|
||||
while (true) {
|
||||
auto frame = _demuxer->readFrame(keyFrame);
|
||||
bool eof = false;
|
||||
while (!eof) {
|
||||
auto frame = _demuxer->readFrame(keyFrame, eof);
|
||||
if(!frame){
|
||||
//文件读完了都未找到下一帧关键帧
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
if(keyFrame || frame->keyFrame() || frame->configFrame()){
|
||||
//定位到key帧
|
||||
@ -136,6 +136,7 @@ bool MP4Reader::seekTo(uint32_t ui32Stamp){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MP4Reader::close(MediaSource &sender,bool force){
|
||||
|
Loading…
Reference in New Issue
Block a user