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