Log in

View Full Version : ffmpeg.exe as a general purpose encoder


agressiv
10th September 2014, 03:24
I'm encoding all of my "extras" from various blu-rays to x264 or HEVC via ffmpeg.exe since, well, I don't care that much about cropping, indexing or the like, and I'm just scripting them in powershell without much thought.

What limitations does ffmpeg have on conversion versus using indexing and avisynth? Does it have just a greater chance at failure, similar to using something like DirectShowSource() ? I'm able to do a yadif (which I was surprised at) for some interlaced content, so it certainly isn't lacking in features.

I've never used ffmpeg.exe for a movie, but I'm curious to see what problems people have run into if they don't have anything they really need to do in avisynth scripts.

(Forgive me if this is in the wrong forum!)

foxyshadis
10th September 2014, 04:33
ffmpeg is insanely powerful, and has become much more so since the introduction of avfilter; the x264 in it is the same, and the decoder is the same as LWlibav, ffms, and many directshow decoders (like LAV filters). What it can't do is fix badly broken transfers, but for everything else, it works just as well as a typical "Input->IVTC/Deint->optional light denoise or sharpen" Avisynth script, and it can sometimes be faster. The biggest downside is the plethora of command-line options that combine everything you'd otherwise do into one long line, but if you're scripting, you only have to figure them out once.

smok3
10th September 2014, 07:32
I'am "bash-ing" the ffmpeg for some years now (see ffdrop), (nothing really complicated), but since we are getting back to win editing stations a powershell example would be nice, care to share some agressiv?

agressiv
10th September 2014, 23:29
I guess I'm more curious on what hits the lack of indexing has. I'm assuming it's more for handling imperfect content than anything else. I've heard of audio sync issues, but that's about it.

Here is a place where we encode any sort of random video format (whether it be from iPhone, a Windows device, camcorder etc - and convert it into x264 MP4 for a web page.


$FFMPEGCommand = "D:\Movies\Utilities\ffmpeg.exe"
$FFProbeCommand = "D:\Movies\Utilities\ffprobe.exe"

$SourceDirectory = Get-ChildItem "\\mediaplatformfiles\MediaUpload\Prod" | Where-Object {$_.PSIsContainer}

foreach ($Directory in $SourceDirectory) {
$OriginalVideo = Get-ChildItem ($Directory.FullName + "\Original") | Select-Object -ExpandProperty FullName
$VideoPath = "D:\Staging\" + $Directory + "\Encoded"
#$VideoPath = $Directory.FullName + "\Encoded"
$TranscodedVideo = $VideoPath + "\" + $Directory + ".mp4"
if (!(Test-Path $VideoPath)) {
[xml]$VidXML = &$FFProbeCommand -v quiet -print_format xml -select_streams v -show_entries stream=codec_name $OriginalVideo
New-Item ("D:\Staging\" + $Directory + "\Encoded") -Type Directory
$TranscodedVideo = "D:\Staging\" + $Directory + "\Encoded\" + $Directory + ".mp4"

#FFmpeg barfs on mss2 files
if ($VidXML.ffprobe.streams.stream.codec_name -eq "mss2") {
$TranscodedVideoAVI = "D:\Staging\" + $Directory + "\Encoded\" + $Directory + ".avi"
&$FFMPEGCommand -i $OriginalVideo -acodec libvo_aacenc -movflags +faststart -preset slow -y $TranscodedVideoAVI
&$FFMPEGCommand -i $TranscodedVideoAVI -vcodec copy -acodec copy -bsf:a aac_adtstoasc -y $TranscodedVideo
Remove-Item -Path $TranscodedVideoAVI -Force -ErrorAction 'SilentlyContinue'
} else {
&$FFMPEGCommand -i $OriginalVideo -crf 27 -movflags +faststart -preset slow -y $TranscodedVideo
}
}
}


So, we're looping through some folders, looking for any single video which exists in a folder. We're then encoding that to a MP4 container with x264 and aac.

We're using ffprobe to see if the source stream has the mss2 codec. This is a Microsoft "screen" codec which is very low bitrate (e.g. Powerpoint screencaps) that ffmpeg barfs on if you attempt to encode it to x264 with metadata. However, it's just fine if you encode it to ASP MP4 through AVI. This "strange" combination is a result of a lot of experimentation. High CRF because this this is largely presentations, low quality captures of meetings etc - hardly anything approaching blu-ray. Disk space is a larger concern since this all replicates throughout the world.

Here is what I'm doing for my mpeg2 extras from blu-rays which are SD and interlaced:


$ffmpeg = "C:\Movies\Utilities\ffmpeg.exe"
$mpeg2 = Get-ChildItem "C:\Movies\Extras\mpeg2" | Sort-Object
foreach ($File in $mpeg2) {
&$ffmpeg -i $File.FullName -filter:v yadif=1 -c:v libx265 -x265-params crf=20 -c:a libopus "C:\Movies\Extras\Final\$($File.Name)"
}


This simply doubles the framerate (yadif=1) and converts them to x265 and the OPUS codec.