Skip to content

Commit

Permalink
支持MP4录制
Browse files Browse the repository at this point in the history
  • Loading branch information
liangzhuohua committed Jun 15, 2024
1 parent 96eefa6 commit 21dbf35
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,17 @@ ApplicationWindow {
recordTimer.started = player.startRecord();
if(recordTimer.started){
recordTimer.start();
}else{
tips.showPop('Record failed! ',3000);
}
}else{
recordTimer.started = false;
player.stopRecord();
let f = player.stopRecord();
if(f!==''){
tips.showPop('Saved '+f,3000);
}else{
tips.showPop('Record failed! ',3000);
}
recordTimer.stop();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/player/Mp4Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class Mp4Encoder {
//音视频index
int videoIndex = -1;
int audioIndex = -1;
//文件保存路径
string _saveFilePath;
private:
//是否已经初始化
bool _isOpen = false;
//文件保存路径
string _saveFilePath;
//编码上下文
shared_ptr<AVFormatContext> _formatCtx;
//原始视频流时间基
Expand Down
6 changes: 5 additions & 1 deletion src/player/QQuickRealTimePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,13 @@ bool QQuickRealTimePlayer::startRecord() {
return true;
}

void QQuickRealTimePlayer::stopRecord() {
QString QQuickRealTimePlayer::stopRecord() {
if(!_mp4Encoder){
return {};
}
_mp4Encoder->stop();
decoder->_gotPktCallback = nullptr;
return {_mp4Encoder->_saveFilePath.c_str()};
}

int QQuickRealTimePlayer::getVideoWidth() {
Expand Down
2 changes: 1 addition & 1 deletion src/player/QQuickRealTimePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class QQuickRealTimePlayer : public QQuickFramebufferObject
Q_INVOKABLE QString captureJpeg();
//录像
Q_INVOKABLE bool startRecord();
Q_INVOKABLE void stopRecord();
Q_INVOKABLE QString stopRecord();
//录制GIF
Q_INVOKABLE bool startGifRecord();
Q_INVOKABLE void stopGifRecord();
Expand Down

0 comments on commit 21dbf35

Please sign in to comment.