mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-24 11:40:37 +08:00
Merge branch 'master' into hls_record_disk
This commit is contained in:
commit
55362f7d29
@ -64,9 +64,7 @@ public:
|
||||
*/
|
||||
void setInitSegment(string str) {
|
||||
_init_segment = std::move(str);
|
||||
if (_ring) {
|
||||
regist();
|
||||
}
|
||||
createRing();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void onSegmentData(const string &string, uint32_t stamp, bool key_frame) override {
|
||||
void onSegmentData(string string, uint32_t stamp, bool key_frame) override {
|
||||
if (string.empty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -9,9 +9,11 @@
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_MP4
|
||||
|
||||
#include "MP4Muxer.h"
|
||||
#include "Util/File.h"
|
||||
#include "Extension/H264.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
MP4Muxer::MP4Muxer() {}
|
||||
@ -84,7 +86,6 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) {
|
||||
//mp4文件时间戳需要从0开始
|
||||
auto &track_info = it->second;
|
||||
int64_t dts_out, pts_out;
|
||||
|
||||
switch (frame->getCodecId()) {
|
||||
case CodecH264:
|
||||
case CodecH265: {
|
||||
@ -320,22 +321,23 @@ bool MP4MuxerMemory::inputFrame(const Frame::Ptr &frame){
|
||||
}
|
||||
|
||||
bool key_frame = frame->keyFrame();
|
||||
if (_ticker.elapsedTime() > 50 || key_frame) {
|
||||
//遇到关键帧或者超过50ms则切片
|
||||
_ticker.resetTime();
|
||||
|
||||
//flush切片
|
||||
saveSegment();
|
||||
|
||||
auto data = _memory_file->getAndClearMemory();
|
||||
if (!data.empty()) {
|
||||
//输出切片数据
|
||||
onSegmentData(_memory_file->getAndClearMemory(), frame->dts(), _key_frame);
|
||||
onSegmentData(std::move(data), frame->dts(), _key_frame);
|
||||
_key_frame = false;
|
||||
}
|
||||
|
||||
if (key_frame) {
|
||||
_key_frame = true;
|
||||
}
|
||||
|
||||
return MP4MuxerInterface::inputFrame(frame);
|
||||
}
|
||||
|
||||
|
||||
}//namespace mediakit
|
||||
#endif//#ifdef ENABLE_MP4
|
||||
|
@ -134,14 +134,13 @@ protected:
|
||||
* @param stamp 切片末尾时间戳
|
||||
* @param key_frame 是否有关键帧
|
||||
*/
|
||||
virtual void onSegmentData(const string &string, uint32_t stamp, bool key_frame) = 0;
|
||||
virtual void onSegmentData(string string, uint32_t stamp, bool key_frame) = 0;
|
||||
|
||||
protected:
|
||||
MP4FileIO::Writer createWriter() override;
|
||||
|
||||
private:
|
||||
bool _key_frame = false;
|
||||
Ticker _ticker;
|
||||
string _init_segment;
|
||||
MP4FileMemory::Ptr _memory_file;
|
||||
};
|
||||
|
@ -59,17 +59,15 @@ bool MP4Reader::readSample() {
|
||||
|
||||
bool keyFrame = false;
|
||||
bool eof = false;
|
||||
while (!eof) {
|
||||
while (!eof && _last_dts < getCurrentStamp()) {
|
||||
auto frame = _demuxer->readFrame(keyFrame, eof);
|
||||
if (!frame) {
|
||||
continue;
|
||||
}
|
||||
_last_dts = frame->dts();
|
||||
if (_muxer) {
|
||||
_muxer->inputFrame(frame);
|
||||
}
|
||||
if (frame->dts() > getCurrentStamp()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GET_CONFIG(bool, fileRepeat, Record::kFileRepeat);
|
||||
@ -129,6 +127,7 @@ uint32_t MP4Reader::getCurrentStamp() {
|
||||
void MP4Reader::setCurrentStamp(uint32_t new_stamp){
|
||||
auto old_stamp = getCurrentStamp();
|
||||
_seek_to = new_stamp;
|
||||
_last_dts = new_stamp;
|
||||
_seek_ticker.resetTime();
|
||||
if (old_stamp != new_stamp && _muxer) {
|
||||
//时间轴未拖动时不操作
|
||||
|
@ -60,6 +60,7 @@ private:
|
||||
bool _have_video = false;
|
||||
bool _paused = false;
|
||||
float _speed = 1.0;
|
||||
uint32_t _last_dts = 0;
|
||||
uint32_t _seek_to;
|
||||
string _file_path;
|
||||
recursive_mutex _mtx;
|
||||
|
Loading…
Reference in New Issue
Block a user