|
@@ -12,7 +12,17 @@ AvRecorder::AvRecorder(QWidget* parent)
|
|
|
m_settingsParam.audioParam.bitRate = 160'000;
|
|
m_settingsParam.audioParam.bitRate = 160'000;
|
|
|
m_settingsParam.videoParam.bitRate = 8'000'000;
|
|
m_settingsParam.videoParam.bitRate = 8'000'000;
|
|
|
m_settingsParam.videoParam.fps = 30;
|
|
m_settingsParam.videoParam.fps = 30;
|
|
|
- m_settingsParam.videoParam.name = Encoder<MediaType::VIDEO>::GetUsableEncoders().front();
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& encs = Encoder<MediaType::VIDEO>::GetUsableEncoders();
|
|
|
|
|
+ m_settingsParam.videoParam.name = encs.empty() ? std::string("libx264") : encs.front();
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& aencs = Encoder<MediaType::AUDIO>::GetUsableEncoders();
|
|
|
|
|
+ m_settingsParam.audioParam.name = aencs.empty() ? std::string("aac") : aencs.front();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 设置安全的默认分辨率,避免在捕获首帧前width/height为0
|
|
|
|
|
+ m_settingsParam.videoParam.width = 1280;
|
|
|
|
|
+ m_settingsParam.videoParam.height = 720;
|
|
|
m_settingsParam.outputDir = ".";
|
|
m_settingsParam.outputDir = ".";
|
|
|
m_settingsParam.liveUrl = "rtmp://127.0.0.1:1935/stream/V1";
|
|
m_settingsParam.liveUrl = "rtmp://127.0.0.1:1935/stream/V1";
|
|
|
m_settingsParam.liveName = "stream";
|
|
m_settingsParam.liveName = "stream";
|
|
@@ -114,7 +124,17 @@ void AvRecorder::setSettings(const SettingsPage::Param& param)
|
|
|
m_settingsParam.audioParam.bitRate = 160'000;
|
|
m_settingsParam.audioParam.bitRate = 160'000;
|
|
|
m_settingsParam.videoParam.bitRate = 8'000'000;
|
|
m_settingsParam.videoParam.bitRate = 8'000'000;
|
|
|
m_settingsParam.videoParam.fps = 30;
|
|
m_settingsParam.videoParam.fps = 30;
|
|
|
- m_settingsParam.videoParam.name = Encoder<MediaType::VIDEO>::GetUsableEncoders().front();
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& encs = Encoder<MediaType::VIDEO>::GetUsableEncoders();
|
|
|
|
|
+ m_settingsParam.videoParam.name = encs.empty() ? std::string("libx264") : encs.front();
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ const auto& aencs = Encoder<MediaType::AUDIO>::GetUsableEncoders();
|
|
|
|
|
+ m_settingsParam.audioParam.name = aencs.empty() ? std::string("aac") : aencs.front();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 重置时也保持安全默认分辨率,实际分辨率会在捕获后更新
|
|
|
|
|
+ m_settingsParam.videoParam.width = 1280;
|
|
|
|
|
+ m_settingsParam.videoParam.height = 720;
|
|
|
m_settingsParam.outputDir = ".";
|
|
m_settingsParam.outputDir = ".";
|
|
|
m_settingsParam.liveUrl = param.liveUrl; // "rtmp://192.168.3.76:1935/stream/V1";
|
|
m_settingsParam.liveUrl = param.liveUrl; // "rtmp://192.168.3.76:1935/stream/V1";
|
|
|
m_settingsParam.liveName = param.liveName; // "stream";
|
|
m_settingsParam.liveName = param.liveName; // "stream";
|
|
@@ -321,6 +341,9 @@ void AvRecorder::dealCapture()
|
|
|
m_speakerWidget->setEnabled(m_audioRecorder.GetCaptureInfo(SPEAKER_INDEX) != nullptr);
|
|
m_speakerWidget->setEnabled(m_audioRecorder.GetCaptureInfo(SPEAKER_INDEX) != nullptr);
|
|
|
m_fpsLabel->setText(QString("FPS: %1").arg(m_settingsParam.videoParam.fps));
|
|
m_fpsLabel->setText(QString("FPS: %1").arg(m_settingsParam.videoParam.fps));
|
|
|
m_videoEncodeLabel->setText(("编码器: " + m_settingsParam.videoParam.name).c_str());
|
|
m_videoEncodeLabel->setText(("编码器: " + m_settingsParam.videoParam.name).c_str());
|
|
|
|
|
+ if (m_audioEncodeLabel) {
|
|
|
|
|
+ m_audioEncodeLabel->setText(("音频编码器: " + m_settingsParam.audioParam.name).c_str());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void AvRecorder::stopCapture()
|
|
void AvRecorder::stopCapture()
|
|
@@ -401,6 +424,18 @@ bool AvRecorder::startStream(std::string_view path, std::string_view format)
|
|
|
qDebug() << "Failed to start video recording";
|
|
qDebug() << "Failed to start video recording";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ // 同步:展示实际使用的编码器名称(考虑自动回退后的结果)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::string used = m_videoRecorder.GetEncoderNameForMuxer(m_avMuxer);
|
|
|
|
|
+ if (!used.empty()) {
|
|
|
|
|
+ m_videoEncodeLabel->setText((std::string("编码器: ") + used).c_str());
|
|
|
|
|
+ }
|
|
|
|
|
+ std::string aused = m_audioRecorder.GetEncoderNameForMuxer(m_avMuxer);
|
|
|
|
|
+ if (!aused.empty()) {
|
|
|
|
|
+ m_audioEncodeLabel->setText((std::string("音频编码器: ") + aused).c_str());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
m_recordTime = QTime::currentTime();
|
|
m_recordTime = QTime::currentTime();
|
|
|
m_captureStatusLabel->setText("状态: 正在工作");
|
|
m_captureStatusLabel->setText("状态: 正在工作");
|
|
|
m_settingsBtn->setEnabled(false);
|
|
m_settingsBtn->setEnabled(false);
|
|
@@ -527,6 +562,7 @@ void AvRecorder::updateCaptureList()
|
|
|
void AvRecorder::initStatusBarUi()
|
|
void AvRecorder::initStatusBarUi()
|
|
|
{
|
|
{
|
|
|
m_videoEncodeLabel = new QLabel;
|
|
m_videoEncodeLabel = new QLabel;
|
|
|
|
|
+ m_audioEncodeLabel = new QLabel;
|
|
|
auto hLayout = new QHBoxLayout;
|
|
auto hLayout = new QHBoxLayout;
|
|
|
hLayout->setContentsMargins(0, 0, 0, 0);
|
|
hLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
hLayout->addWidget(new QLabel("捕获方式:"));
|
|
hLayout->addWidget(new QLabel("捕获方式:"));
|
|
@@ -543,6 +579,7 @@ void AvRecorder::initStatusBarUi()
|
|
|
|
|
|
|
|
// 添加各个状态信息到状态栏
|
|
// 添加各个状态信息到状态栏
|
|
|
m_statusBar->addWidget(m_videoEncodeLabel);
|
|
m_statusBar->addWidget(m_videoEncodeLabel);
|
|
|
|
|
+ m_statusBar->addWidget(m_audioEncodeLabel);
|
|
|
|
|
|
|
|
auto widget = new QWidget;
|
|
auto widget = new QWidget;
|
|
|
widget->setLayout(hLayout);
|
|
widget->setLayout(hLayout);
|