ugoiras: encode .webm samples using VP9 instead of VP8.
Switch the codec for .webm samples from VP8 to VP9. All modern browsers support VP9 (Safari was the last to add support in ~2020), so it should be safe to provide only VP9 .webms without a fallback. VP9 lets us use two-pass encoding, which should offer better compression. Fixes ugoira samples still having poor quality even after4c652cf3e.4c652cf3etried to remove the max bitrate limit by setting `-b:v 0`, but this only worked in FFmpeg 4.2. In production Danbooru uses FFmpeg 4.4, and apparently in 4.4 `-b:v 0` means "use the default max bitrate of 256kb/s" instead of "no bitrate limit". https://trac.ffmpeg.org/wiki/Encode/VP9 https://developers.google.com/media/vp9/bitrate-modes https://developers.google.com/media/vp9/settings/vod http://wiki.webmproject.org/ffmpeg/vp9-encoding-guide https://www.reddit.com/r/AV1/comments/k7colv/encoder_tuning_part_1_tuning_libvpxvp9_be_more/
This commit is contained in:
@@ -85,7 +85,10 @@ class MediaFile::Ugoira < MediaFile
|
||||
end
|
||||
|
||||
ext = zipfile.first.name.match(/\.(\w{,4})$/)[1]
|
||||
ffmpeg_out, status = Open3.capture2e("ffmpeg -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx -crf 12 -b:v 0 -an #{tmpdir}/tmp.webm")
|
||||
ffmpeg_out, status = Open3.capture2e("ffmpeg -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx-vp9 -crf 12 -b:v 0 -an -threads 8 -tile-columns 2 -tile-rows 1 -row-mt 1 -pass 1 -f null /dev/null")
|
||||
raise Error, "ffmpeg failed: #{ffmpeg_out}" unless status.success?
|
||||
|
||||
ffmpeg_out, status = Open3.capture2e("ffmpeg -i #{tmpdir}/images/%06d.#{ext} -codec:v libvpx-vp9 -crf 12 -b:v 0 -an -threads 8 -tile-columns 2 -tile-rows 1 -row-mt 1 -pass 2 #{tmpdir}/tmp.webm")
|
||||
raise Error, "ffmpeg failed: #{ffmpeg_out}" unless status.success?
|
||||
|
||||
mkvmerge_out, status = Open3.capture2e("mkvmerge -o #{output_file.path} --webm --timecodes 0:#{tmpdir}/timecodes.tc #{tmpdir}/tmp.webm")
|
||||
|
||||
Reference in New Issue
Block a user