diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index 63546596..3609ff41 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -40,7 +40,7 @@ typedef enum { XX(CodecVP8, TrackVideo, 7, "VP8", PSI_STREAM_VP8) \ XX(CodecVP9, TrackVideo, 8, "VP9", PSI_STREAM_VP9) \ XX(CodecAV1, TrackVideo, 9, "AV1", PSI_STREAM_AV1) \ - XX(CodecJPEG, TrackVideo, 10, "JPEG", PSI_STREAM_JPEG_2000) + XX(CodecJPEG, TrackVideo, 10, "JPEG", PSI_STREAM_RESERVED) typedef enum { CodecInvalid = -1, diff --git a/src/Record/MPEG.cpp b/src/Record/MPEG.cpp index 985cf98f..153fd796 100644 --- a/src/Record/MPEG.cpp +++ b/src/Record/MPEG.cpp @@ -30,19 +30,18 @@ MpegMuxer::~MpegMuxer() { releaseContext(); } -#define XX(name, type, value, str, mpeg_id) \ - case name : { \ - if (mpeg_id == PSI_STREAM_RESERVED) { \ - break; \ - } \ - _codec_to_trackid[track->getCodecId()] = mpeg_muxer_add_stream((::mpeg_muxer_t *)_context, mpeg_id, nullptr, 0); \ - return true; \ +#define XX(name, type, value, str, mpeg_id) \ + case name: { \ + if (mpeg_id == PSI_STREAM_RESERVED) { \ + break; \ + } \ + if (track->getTrackType() == TrackVideo) { \ + _have_video = true; \ + } \ + _codec_to_trackid[track->getCodecId()] = mpeg_muxer_add_stream((::mpeg_muxer_t *)_context, mpeg_id, nullptr, 0); \ + return true; \ } - bool MpegMuxer::addTrack(const Track::Ptr &track) { - if (track->getTrackType() == TrackVideo) { - _have_video = true; - } switch (track->getCodecId()) { CODEC_MAP(XX) default: break; @@ -85,6 +84,11 @@ bool MpegMuxer::inputFrame(const Frame::Ptr &frame) { //没有视频时,才以音频时间戳为TS的时间戳 _timestamp = frame->dts(); } + + if(frame->getTrackType() == TrackType::TrackVideo){ + _key_pos = frame->keyFrame(); + _timestamp = frame->dts(); + } _max_cache_size = 512 + 1.2 * frame->size(); mpeg_muxer_input((::mpeg_muxer_t *)_context, track_id, frame->keyFrame() ? 0x0001 : 0, frame->pts() * 90LL, frame->dts() * 90LL, frame->data(), frame->size()); flushCache();