mirror of https://github.com/mgba-emu/mgba.git
Qt: Automatically change video file extension as appropriate
This commit is contained in:
parent
e07684e3ac
commit
47941aa0b0
1
CHANGES
1
CHANGES
|
@ -28,6 +28,7 @@ Misc:
|
|||
- GBA: Improve detection of valid ELF ROMs
|
||||
- Qt: Include wayland QPA in AppImage (fixes mgba.io/i/2796)
|
||||
- Qt: Stop eating boolean action key events (fixes mgba.io/i/2636)
|
||||
- Qt: Automatically change video file extension as appropriate
|
||||
- Scripting: Add `callbacks:oneshot` for single-call callbacks
|
||||
|
||||
0.10.1: (2023-01-10)
|
||||
|
|
|
@ -20,6 +20,7 @@ using namespace QGBA;
|
|||
QMap<QString, QString> VideoView::s_acodecMap;
|
||||
QMap<QString, QString> VideoView::s_vcodecMap;
|
||||
QMap<QString, QString> VideoView::s_containerMap;
|
||||
QMap<QString, QStringList> VideoView::s_extensionMap;
|
||||
|
||||
bool VideoView::Preset::compatible(const Preset& other) const {
|
||||
if (!other.container.isNull() && !container.isNull() && other.container != container) {
|
||||
|
@ -71,6 +72,23 @@ VideoView::VideoView(QWidget* parent)
|
|||
if (s_containerMap.empty()) {
|
||||
s_containerMap["mkv"] = "matroska";
|
||||
}
|
||||
if (s_extensionMap.empty()) {
|
||||
s_extensionMap["matroska"] += ".mkv";
|
||||
s_extensionMap["matroska"] += ".mka";
|
||||
s_extensionMap["webm"] += ".webm";
|
||||
s_extensionMap["avi"] += ".avi";
|
||||
s_extensionMap["mp4"] += ".mp4";
|
||||
s_extensionMap["mp4"] += ".m4v";
|
||||
s_extensionMap["mp4"] += ".m4a";
|
||||
|
||||
s_extensionMap["flac"] += ".flac";
|
||||
s_extensionMap["mpeg"] += ".mpg";
|
||||
s_extensionMap["mpeg"] += ".mpeg";
|
||||
s_extensionMap["mpegts"] += ".ts";
|
||||
s_extensionMap["mp3"] += ".mp3";
|
||||
s_extensionMap["ogg"] += ".ogg";
|
||||
s_extensionMap["ogv"] += ".ogv";
|
||||
}
|
||||
|
||||
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &VideoView::close);
|
||||
connect(m_ui.start, &QAbstractButton::clicked, this, &VideoView::startRecording);
|
||||
|
@ -195,6 +213,9 @@ void VideoView::setController(std::shared_ptr<CoreController> controller) {
|
|||
}
|
||||
|
||||
void VideoView::startRecording() {
|
||||
if (QFileInfo(m_filename).suffix().isEmpty()) {
|
||||
changeExtension();
|
||||
}
|
||||
if (!validateSettings()) {
|
||||
return;
|
||||
}
|
||||
|
@ -238,6 +259,7 @@ void VideoView::selectFile() {
|
|||
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select output file"));
|
||||
if (!filename.isEmpty()) {
|
||||
m_ui.filename->setText(filename);
|
||||
changeExtension();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,6 +311,7 @@ void VideoView::setContainer(const QString& container) {
|
|||
m_containerCstr = nullptr;
|
||||
m_container = QString();
|
||||
}
|
||||
changeExtension();
|
||||
validateSettings();
|
||||
uncheckIncompatible();
|
||||
}
|
||||
|
@ -458,6 +481,30 @@ void VideoView::uncheckIncompatible() {
|
|||
}
|
||||
}
|
||||
|
||||
void VideoView::changeExtension() {
|
||||
if (m_filename.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s_extensionMap.contains(m_container)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList extensions = s_extensionMap.value(m_container);
|
||||
QString filename = m_filename;
|
||||
int index = m_filename.lastIndexOf(".");
|
||||
if (index >= 0) {
|
||||
if (extensions.contains(filename.mid(index))) {
|
||||
// This extension is already valid
|
||||
return;
|
||||
}
|
||||
filename.truncate(index);
|
||||
}
|
||||
filename += extensions.front();
|
||||
|
||||
m_ui.filename->setText(filename);
|
||||
}
|
||||
|
||||
QString VideoView::sanitizeCodec(const QString& codec, const QMap<QString, QString>& mapping) {
|
||||
QString sanitized = codec.toLower();
|
||||
sanitized = sanitized.remove(QChar('.'));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#ifdef USE_FFMPEG
|
||||
|
||||
#include <QStringList>
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
@ -62,6 +63,8 @@ private slots:
|
|||
void uncheckIncompatible();
|
||||
void updatePresets();
|
||||
|
||||
void changeExtension();
|
||||
|
||||
private:
|
||||
struct Preset {
|
||||
QString container;
|
||||
|
@ -123,6 +126,7 @@ private:
|
|||
static QMap<QString, QString> s_acodecMap;
|
||||
static QMap<QString, QString> s_vcodecMap;
|
||||
static QMap<QString, QString> s_containerMap;
|
||||
static QMap<QString, QStringList> s_extensionMap;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue