FFmpeg: Support lossless h.264 encoding

This commit is contained in:
Vicki Pfau 2018-07-08 22:44:57 -07:00
parent 31e0642e64
commit d6e5bfb640
4 changed files with 17 additions and 19 deletions

View File

@ -68,6 +68,7 @@ Misc:
- GB: Fix VRAM/palette locking (fixes mgba.io/i/1109)
- GB Video: Darken colors in GBA mode
- FFmpeg: Support libswresample (fixes mgba.io/i/1120, mgba.io/b/123)
- FFmpeg: Support lossless h.264 encoding
0.6.3: (2017-04-14)
Bugfixes:

View File

@ -311,6 +311,15 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
encoder->video->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}
if (encoder->video->codec->id == AV_CODEC_ID_H264 &&
(strcasecmp(encoder->containerFormat, "mp4") ||
strcasecmp(encoder->containerFormat, "m4v") ||
strcasecmp(encoder->containerFormat, "mov"))) {
// QuickTime and a few other things require YUV420
encoder->video->pix_fmt = AV_PIX_FMT_YUV420P;
}
if (strcmp(vcodec->name, "libx264") == 0) {
// Try to adaptively figure out when you can use a slower encoder
if (encoder->width * encoder->height > 1000000) {
@ -320,16 +329,12 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) {
} else {
av_opt_set(encoder->video->priv_data, "preset", "faster", 0);
}
av_opt_set(encoder->video->priv_data, "tune", "zerolatency", 0);
if (encoder->videoBitrate == 0) {
av_opt_set(encoder->video->priv_data, "crf", "0", 0);
encoder->video->pix_fmt = AV_PIX_FMT_YUV444P;
}
}
if (encoder->video->codec->id == AV_CODEC_ID_H264 &&
(strcasecmp(encoder->containerFormat, "mp4") ||
strcasecmp(encoder->containerFormat, "m4v") ||
strcasecmp(encoder->containerFormat, "mov"))) {
// QuickTime and a few other things require YUV420
encoder->video->pix_fmt = AV_PIX_FMT_YUV420P;
}
avcodec_open2(encoder->video, vcodec, 0);
#if LIBAVCODEC_VERSION_MAJOR >= 55
encoder->videoFrame = av_frame_alloc();

View File

@ -99,7 +99,7 @@ VideoView::VideoView(QWidget* parent)
setPreset({
.container = "MKV",
.vcodec = "PNG",
.vcodec = "h.264",
.acodec = "FLAC",
.vbr = 0,
.abr = 0,
@ -179,7 +179,7 @@ void VideoView::updatePresets() {
if (m_nativeWidth && m_nativeHeight) {
addPreset(m_ui.presetLossless, {
.container = "MKV",
.vcodec = "PNG",
.vcodec = "h.264",
.acodec = "FLAC",
.vbr = 0,
.abr = 0,

View File

@ -254,11 +254,6 @@
<property name="editable">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>PNG</string>
</property>
</item>
<item>
<property name="text">
<string>h.264</string>
@ -353,9 +348,6 @@
<property name="suffix">
<string/>
</property>
<property name="minimum">
<number>200</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
@ -523,7 +515,7 @@
<resources/>
<connections/>
<buttongroups>
<buttongroup name="presets"/>
<buttongroup name="resolutions"/>
<buttongroup name="presets"/>
</buttongroups>
</ui>