diff --git a/src/platform/ffmpeg/ffmpeg-encoder.c b/src/platform/ffmpeg/ffmpeg-encoder.c index a016fa3dd..4d84653b5 100644 --- a/src/platform/ffmpeg/ffmpeg-encoder.c +++ b/src/platform/ffmpeg/ffmpeg-encoder.c @@ -29,6 +29,7 @@ void FFmpegEncoderInit(struct FFmpegEncoder* encoder) { FFmpegEncoderSetAudio(encoder, "flac", 0); FFmpegEncoderSetVideo(encoder, "png", 0); FFmpegEncoderSetContainer(encoder, "matroska"); + FFmpegEncoderSetDimensions(encoder, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); encoder->resampleContext = 0; encoder->absf = 0; encoder->context = 0; @@ -143,6 +144,11 @@ bool FFmpegEncoderSetContainer(struct FFmpegEncoder* encoder, const char* contai return true; } +void FFmpegEncoderSetDimensions(struct FFmpegEncoder* encoder, int width, int height) { + encoder->width = width > 0 ? width : VIDEO_HORIZONTAL_PIXELS; + encoder->height = height > 0 ? height : VIDEO_VERTICAL_PIXELS; +} + bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder* encoder) { AVOutputFormat* oformat = av_guess_format(encoder->containerFormat, 0, 0); AVCodec* acodec = avcodec_find_encoder_by_name(encoder->audioCodec); @@ -218,8 +224,8 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { encoder->videoStream = avformat_new_stream(encoder->context, vcodec); encoder->video = encoder->videoStream->codec; encoder->video->bit_rate = encoder->videoBitrate; - encoder->video->width = VIDEO_HORIZONTAL_PIXELS; - encoder->video->height = VIDEO_VERTICAL_PIXELS; + encoder->video->width = encoder->width; + encoder->video->height = encoder->height; encoder->video->time_base = (AVRational) { VIDEO_TOTAL_LENGTH, GBA_ARM7TDMI_FREQUENCY }; encoder->video->pix_fmt = encoder->pixFormat; encoder->video->gop_size = 15; @@ -234,8 +240,8 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { encoder->videoFrame->height = encoder->video->height; encoder->videoFrame->pts = 0; encoder->scaleContext = sws_getContext(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, AV_PIX_FMT_0BGR32, - VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, encoder->video->pix_fmt, - 0, 0, 0, 0); + encoder->videoFrame->width, encoder->videoFrame->height, encoder->video->pix_fmt, + SWS_POINT, 0, 0, 0); av_image_alloc(encoder->videoFrame->data, encoder->videoFrame->linesize, encoder->video->width, encoder->video->height, encoder->video->pix_fmt, 32); avio_open(&encoder->context->pb, outfile, AVIO_FLAG_WRITE); diff --git a/src/platform/ffmpeg/ffmpeg-encoder.h b/src/platform/ffmpeg/ffmpeg-encoder.h index ffed42940..59639086e 100644 --- a/src/platform/ffmpeg/ffmpeg-encoder.h +++ b/src/platform/ffmpeg/ffmpeg-encoder.h @@ -35,6 +35,8 @@ struct FFmpegEncoder { struct AVCodecContext* video; enum AVPixelFormat pixFormat; struct AVFrame* videoFrame; + int width; + int height; int64_t currentVideoFrame; struct SwsContext* scaleContext; struct AVStream* videoStream; @@ -44,6 +46,7 @@ void FFmpegEncoderInit(struct FFmpegEncoder*); bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr); bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr); bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container); +void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height); bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*); bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile); void FFmpegEncoderClose(struct FFmpegEncoder*); diff --git a/src/platform/qt/VideoView.cpp b/src/platform/qt/VideoView.cpp index 17c509239..122c61b3c 100644 --- a/src/platform/qt/VideoView.cpp +++ b/src/platform/qt/VideoView.cpp @@ -79,6 +79,9 @@ VideoView::VideoView(QWidget* parent) connect(m_ui.abr, SIGNAL(valueChanged(int)), this, SLOT(setAudioBitrate(int))); connect(m_ui.vbr, SIGNAL(valueChanged(int)), this, SLOT(setVideoBitrate(int))); + connect(m_ui.width, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int))); + connect(m_ui.height, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int))); + connect(m_ui.showAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced(bool))); FFmpegEncoderInit(&m_encoder); @@ -107,7 +110,7 @@ VideoView::VideoView(QWidget* parent) .container = "MP4", .vcodec = "h.264", .acodec = "AAC", - .vbr = 6000, + .vbr = 5000, .abr = 384, .width = 1620, .height = 1080 @@ -144,6 +147,8 @@ VideoView::VideoView(QWidget* parent) setAudioBitrate(m_ui.abr->value()); setVideoBitrate(m_ui.vbr->value()); setContainer(m_ui.container->currentText()); + setWidth(m_ui.width->value()); + setHeight(m_ui.height->value()); showAdvanced(false); } @@ -246,6 +251,24 @@ void VideoView::setVideoBitrate(int br, bool manual) { } } +void VideoView::setWidth(int width, bool manual) { + m_width = width; + FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height); + validateSettings(); + if (manual) { + uncheckIncompatible(); + } +} + +void VideoView::setHeight(int height, bool manual) { + m_height = height; + FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height); + validateSettings(); + if (manual) { + uncheckIncompatible(); + } +} + void VideoView::showAdvanced(bool show) { m_ui.advancedBox->setVisible(show); } @@ -290,7 +313,9 @@ void VideoView::uncheckIncompatible() { .acodec = m_audioCodec, .vcodec = m_videoCodec, .abr = m_abr / 1000, - .vbr = m_vbr / 1000 + .vbr = m_vbr / 1000, + .width = m_width, + .height = m_height }; for (auto iterator = m_presets.constBegin(); iterator != m_presets.constEnd(); ++iterator) { @@ -371,6 +396,14 @@ void VideoView::setPreset(const Preset& preset) { setVideoBitrate(preset.vbr, false); safelySet(m_ui.vbr, preset.vbr); } + if (preset.width) { + setWidth(preset.width, false); + safelySet(m_ui.width, preset.width); + } + if (preset.height) { + setHeight(preset.height, false); + safelySet(m_ui.height, preset.height); + } uncheckIncompatible(); validateSettings(); diff --git a/src/platform/qt/VideoView.h b/src/platform/qt/VideoView.h index 351ffe7a4..633a052bb 100644 --- a/src/platform/qt/VideoView.h +++ b/src/platform/qt/VideoView.h @@ -52,6 +52,9 @@ private slots: void setAudioBitrate(int, bool manual = true); void setVideoBitrate(int, bool manual = true); + void setWidth(int, bool manual = true); + void setHeight(int, bool manual = true); + void showAdvanced(bool); void uncheckIncompatible(); @@ -81,6 +84,9 @@ private: int m_abr; int m_vbr; + int m_width; + int m_height; + QMap m_presets; static QMap s_acodecMap; diff --git a/src/platform/qt/VideoView.ui b/src/platform/qt/VideoView.ui index 9286c4b5f..685a630d1 100644 --- a/src/platform/qt/VideoView.ui +++ b/src/platform/qt/VideoView.ui @@ -152,9 +152,6 @@ - - false - 1080p @@ -165,9 +162,6 @@ - - false - 720p @@ -178,9 +172,6 @@ - - false - 480p @@ -191,9 +182,6 @@ - - false - GBA (240x160) @@ -423,9 +411,6 @@ - - false - 160 @@ -436,9 +421,6 @@ - - false - 240