Articles | Late-2018/2019 Video Processing Guide
This article assumes you've read this article and all corresponding articles. In this article I won't be discussing many technical elements, and I've decided to separate it from the others primarily to preserve the information for the old pipelines they possess for the sake of cross referencing future research.
Following the Drunk Swede's extensive research following the base OBS pipeline established in mid-2018, we now have a series of batch commands that allow us to pull what is nearly the limit of what the x264 codec can give us for quality in public video media without using placebo settings and taking huge hits on encoding speed. In this article I will provide the bat files and a summary of their applications in my setup.
Updated - 2019-09-04
Further cleanup to scripts and some format alterations.
Tools -
OBS - Following the OBS pipeline outlined here. We're using a custom build that fixes the 444 Chroma Subsampling setting.
FFMPEG - I've removed Megui from my pipeline as it isn't necessary anymore at all. FFMPEG also handles our final audio.
AVISynth - Avisynth exists solely to hand ffmpeg a file from Vegas frameserver.
Bat Files - The Drunk Swede has provided several bat files that allows us to automate some logistics. All of our ffmpeg and many audio related commands will be handled via bat files.
Audition 1.5, Vegas, Frameserver, MKVToolnix - Nothing new here.
Environment
For my encodes, I have a folder on the Windows task bar that contains a series of bat files, and edit the bat files accordingly. However, some additional features in my pipeline make use of a context menu editor for additional automation, such as converting MKV to mp4 and splitting audio channels, for Vegas, as well as encoding wav to vorbis.
For each project type I maintain a separate bat file to make automation a bit easier, but the bat files only really change for Vegas and base encode projects.
Before we continue, there's a few things we need to make note of.
Audio will desync if we merge it separately from the video.
I encountered a desync in Warcraft 3's later videos by creating audio from individual files via ffmpeg. This is because sometimes the audio files have different timestamps and lengths compared to the video. However, when encoded with the video, ffmpeg will timestamp and splice them correctly and consistently. Thus, we want to first merge the audio with the video and then pull the merged audio from this. Previously, using avisynth, the AviSource++ command shielded us from this behavior by culling unused audio data, but since we phased out avisynth we need to take this extra step to be 100% sure our audio is synced.
We have two choices we can make when encoding a base video (without using vegas for editing). We can encode straight to a final format and then pull the audio from it. Or, if we think we might want to change the video bitrate part-way through verification, we can simply merge the video together and still have audio for the verification process and not need to do two full encodes.
Base Encodes
A base encode is the replacement of my old encodes that used the Fraps -> Megui pipeline.
In the initial version of the pipeline as outlined in the 2018 video article, I was manually splicing videos together. That is now unnecessary.
Record (OBS) -> Sort (Move to Encoding Folder)-> Encode (Bat) -> Encode Audio from resulting MKV (Bat) -> Process Audio (See Below) -> Mux (Mkvtoolnix)
We record with OBS, then move the files to an annointed directory, and run this bat.
set current_directory=Q:\mangoatsexum
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
(for %%i in ("%current_directory%\*.mkv") do @echo file '%%i') > "%current_ffmpeg_directory%\concat.txt"
"%current_ffmpeg_directory%\ffmpeg.exe" -f concat -safe 0 -i "%current_ffmpeg_directory%\concat.txt" -map 0:0 -map 0:1 -map 0:2 -c:v copy -c:a copy "%current_directory%\merged_file.mkv"
"%current_ffmpeg_directory%\ffmpeg64.exe" -y -i "%current_directory%\merged_file.mkv" -map 0:1 -c:a copy "%current_directory%\merged_file_audio1.wav"
"%current_ffmpeg_directory%\ffmpeg64.exe" -y -i "%current_directory%\merged_file.mkv" -map 0:2 -c:a copy "%current_directory%\merged_file_audio2.wav"
"%current_ffmpeg_directory%\ffmpeg.exe" -y -i "%current_directory%\merged_file.mkv" -map 0:0 -c:v copy "%current_directory%\merged_file_video0.m4v"
del /s "%current_ffmpeg_directory%\concat.txt"
pause
The directories to alter should be self-explanatory.
This bat first produces a merged mkv file, then pukes out wavs and an m4v. We can omit the m4v if we don't need it for Vegas - it would allow us to merge a billion small files for ease of management in an editing project, but it isn't necessary if we're just doing a base encode for an LP or the like. To encode the m4v we'd use something like this.
set current_file=Q:\mangoatsexum\merged_file_video0.m4v
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
"%current_ffmpeg_directory%\ffmpeg.exe" -i "%current_file%" -sn -dn -map_chapters -1 -map 0:0 -c:v libx264 -pix_fmt yuv444p10le -me_method umh -x264-params crf=28:subme=9:trellis=2:fullrange=on:colormatrix=bt709:partitions=all:direct=temporal:aq-mode=3 -psy-rd 1.00:1.00 -vf scale="in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" "%current_file%_encoded.mkv"
Concat allows us to automate the otherwise painful logistics of merging a large number of recordings. We've replaced the process of generating avisynth scripts for directories of fraps files with simply using these bat files, basically. We can mix and match commands as necessary. For example, if we want to do a final encode while ripping audio, we can just take our encode settings from the second example and place them in the first, like so.
set current_directory=Q:\mangoatsexum
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
(for %%i in ("%current_directory%\*.mkv") do @echo file '%%i') > "%current_ffmpeg_directory%\concat.txt"
"%current_ffmpeg_directory%\ffmpeg.exe" -f concat -safe 0 -i "%current_ffmpeg_directory%\concat.txt" -sn -dn -map_chapters -1 -map 0:0 -map 0:1 -map 0:2 -c:v libx264 -pix_fmt yuv444p10le -me_method umh -x264-params crf=28:subme=9:trellis=2:fullrange=on:colormatrix=bt709:partitions=all:direct=temporal:aq-mode=3 -psy-rd 1.00:1.00 -vf scale="in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" -c:a copy "%current_directory%\merged_file_encoded.mkv"
"%current_ffmpeg_directory%\ffmpeg64.exe" -y -i "%current_directory%\merged_file_encoded.mkv" -map 0:1 -c:a copy "%current_directory%\merged_file_encoded_audio1.wav"
"%current_ffmpeg_directory%\ffmpeg64.exe" -y -i "%current_directory%\merged_file_encoded.mkv" -map 0:2 -c:a copy "%current_directory%\merged_file_encoded_audio2.wav"
del /s "%current_ffmpeg_directory%\concat.txt"
pause
Vegas Encodes
As opposed to concat, Vegas encodes still require Avisynth because ffmpeg isn't able to hook the signpost file directly and I had a lot of issues with it. Our Avisynth file is just the one line pointing to that file.
AVISource("H:\SKYRIMJOB.avi")
The vegas file is similar to our other one except it exchanges concat for the avisynth source.
set current_file=F:\anonh.avs
set encoded_file=H:\Vegass_encode.mkv
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
"%current_ffmpeg_directory%\ffmpeg.exe" -i "%current_file%" -map 0:0 -c:v libx264 -psy-rd 1.00:1.00 -me_method umh -x264-params crf=26:subme=9:trellis=2:fullrange=on:colormatrix=bt709:partitions=all:direct=temporal:aq-mode=3 -pix_fmt yuv444p10le -vf scale="in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" "%encoded_file%"
pause
Spline64 Rescaling
The spline64 rescaling researched a year ago was ported to ffmpeg to be used in Skyrim and similar recordings. Here's the bat I used for Skyrim Season 2 Segment 1.
set current_file=F:\anonh.avs
set encoded_file=H:\KMesk_skyrimjob-s2-seg1-aq3.mkv
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
"%current_ffmpeg_directory%\ffmpeg.exe" -i "%current_file%" -map 0:0 -c:v libx264 -psy-rd 1.00:1.00 -me_method umh -x264-params crf=26:subme=9:trellis=2:fullrange=on:colormatrix=bt709:partitions=all:direct=temporal:aq-mode=3 -pix_fmt yuv444p10le -vf scale="in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709:w=1280:h=800:sws_flags=spline+accurate_rnd+full_chroma_int+full_chroma_inp+bitexact" "%encoded_file%"
pause
The aq-mode=3 command helps a little bit with allocating data to darks, which is a common issue in Skyrim, though its effects are very subtle.
Converting 444 to 420 for Vegas
Sometimes we need to convert chroma subsampled files for Vegas. This will do so in as non-destructive a way as managable without being super hard on drive space.
set current_directory=E:\MANSPLAIN
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
for %%a in ("%current_directory%\*.mkv") do "%current_ffmpeg_directory%\ffmpeg64.exe" -i "%%a" -map 0:0 -c:v:0 libx264 -pix_fmt yuv420p -me_range 4 -preset ultrafast -x264-params crf=16:fullrange=on:colormatrix=bt709 -vf scale="in_range=full:in_color_matrix=bt709:out_range=full:out_color_matrix=bt709" "%current_directory%\%%~nastream_0.mp4"
pause
And this one handled the audio for those files.
set current_directory=E:\MANSPLAIN
set current_ffmpeg_directory=E:\drunkswede's ffmpeg\bin
for %%a in ("%current_directory%\*.mkv") do "%current_ffmpeg_directory%\ffmpeg64.exe" -i "%%a" -map 0:1 -c:a pcm_s24le "%current_directory%\%%~na-stream_1.wav"
for %%a in ("%current_directory%\*.mkv") do "%current_ffmpeg_directory%\ffmpeg64.exe" -i "%%a" -map 0:2 -c:a pcm_s24le "%current_directory%\%%~na-stream_2.wav"
pause
Dumping Audio/Video from 420 mkv's for Vegas, Encoding Final Audio
Whether it's for D&D or Skyrim videos or other equivalents, I still record files as mkv in OBS because mkv is more resilient to possible interruptions in the recording process such as power outages. However, I need a quick and easy way to get those files vegas-ready, and the best way is by having context menus for mkv. If we want something for a large set of files we're better off using the the first Base Encode script that dumps an m4v copy. Neither of these convert i444 to i420, though, so be sure you're recording in weedspace if your target is vegas-compliant files, or defer to the above script for a large-scale conversion solution.
Furthermore, we have a quick and easy way to convert .wav files that come out of audition or vegas for our release candidates - we can use the right-click menu for that, too.
Default Programs Editor bat files ->
Convert to Mp4
SET args=%*
ECHO %1
"E:\drunkswede's ffmpeg\bin\ffmpeg64.exe" -i "%~$PATH:1" -map 0:0 -c:v copy "%~$PATH:1-video.mp4"
PAUSE
Extract Audio
SET args=%*
ECHO %1
"E:\drunkswede's ffmpeg\bin\ffmpeg.exe" -i "%~$PATH:1" -map 0:1 -c:a copy "%~$PATH:1-audio1.wav"
"E:\drunkswede's ffmpeg\bin\ffmpeg.exe" -i "%~$PATH:1" -map 0:2 -c:a copy "%~$PATH:1-audio2.wav"
PAUSE
Convert Audio to Vorbis
We transitioned to using Vorbis over AAC following research in mid-2019, but this bat could be adapted to any format using ffmpeg.
SET args=%*
ECHO %1
"E:\drunkswede's ffmpeg\bin\ffmpeg64.exe" -i "%~$PATH:1" -c:a libvorbis -b:a 500k -minrate:a 500k -strict -2 "%~n1.ogg"
PAUSE