Hey folks,
I created a PS script that will encode my files real tight with good quality. It first reads the resolution and will encode accordingly based on the input file’s resolution. For example, I encode at a lower bit rate for HD TV shows because they can handle it. I encode at a higher bit-rate for standard def but also do a decomb on it to help improve compatibility. Anyway, my gift back to the community for having helped me out so much in the past.
clear-host
$prox = Get-WmiObject Win32_Process -Filter "Name like '%handbrake%'" | Select-Object Commandline
$Proxc = $Prox | measure
if ($Proxc.Count -gt 0) {exit}
$watchFolders = @()
#$watchFolders += 'c:\Test'
$watchFolders += 'c:\Media'
$folder_Script = (Get-Variable PSScriptRoot).value
set-location $folder_Script
$files =@()
forEach ($folder in $watchFolders)
{
$File_Current = (Get-ChildItem $Folder\* -recurse -include *.tp,*.mpg,*.ts,*.mkv).fullname
If ($file_current -ne $null)
{$files += $File_current}
}
$count = 0
$handbrake = $Folder_Script + "\HandBrakeCli.exe"
$mediaInfo = $folder_script + "\MediaInfo.exe"
foreach ($file in $files)
{
$count += 1
$CurrentFile = (Get-item -Path $file)
If ($CurrentFile -like '*\.grab\*') {continue}
$newFileName = $CurrentFile.Directory.FullName + '\' + $CurrentFile.BaseName + '.mp4'
$host.ui.RawUI.WindowTitle = "Encoding: " + $count + " of " +$files.Count + ' -- ' + $CurrentFile.basename
If (Test-Path $newFileName) # Remove failed MP4 encode attempts
{
$newFileName = Get-Item $newFileName
$length_MP4 = $null
$length_mp4 = . $MediaInfo --Inform="Video;%Duration/String3%" $newFileName.FullName
If ($Length_mp4.Length -eq '0')
{
write-host 'Removing: ' $newFileName
Remove-Item $newFileName
}
}
If (!(Test-Path $newFileName))
{
# Old Settings: . $handbrake -i $currentFile.FullName -o $newFileName --format mp4 --width 640 --optimize --loose-anamorphic --modulus 2 --encoder x264 --vb 600 --two-pass --turbo --rate 29.97 --cfr --audio 1 --aencoder faac --mixdown stereo --arate Auto --ab 160 --audio-fallback ffac3 --x264-preset=VerySlow --x264-profile=main --h264-level="4.0"
# To add decombing, use these switches: --decomb --comb-detect fast
# If using Constant Quality, you have to enforce a framerate or else you'll get audio/video sync issues. --cfr --rate 29.97
# To increase the quality of the video, lower the quality argument to 21, or even 20. Don't go lower than 20 cause the file size will be huge.
#. $handBrake --input $currentFile.FullName --output $newFileName --format mp4 --optimize --encoder x264 --quality 22 --cfr --rate 29.97 --encoder-preset Veryslow --encoder-profile main --encoder-level 4.0 --maxHeight 720
# $height = [int]''
$height = . $MediaInfo --Inform="Video;%Height%" $currentFile.FullName
Start-Sleep -Seconds 1
If ([int]$height -gt [int]'500') # High Def
{
. $handBrake --input $currentFile.FullName --output $newFileName --format mp4 --optimize --encoder x264 --quality 23 --cfr --rate 29.97 --encoder-preset veryslow --encoder-profile main --encoder-level 4.0
}
Else # Low Def
{
. $handBrake --input $currentFile.FullName --output $newFileName --format mp4 --optimize --encoder x264 --quality 21 --cfr --rate 29.97 --encoder-preset veryslow --encoder-profile main --encoder-level 4.0 --decomb --comb-detect fast
}
}
}
Sir,
When we use hand brake to add subtitles to our video, we are getting crackling sound and audio quality is lost.
Not sure what parameter we need to set to get it straight.
We need to add UTF-8 font subtittles to the video with a font size of 30.
So we are using the following code as suggested by users in other forum
I am not an expert in ffmpeg, but I advise you to never use a sampling rate of 44.1 kHz for any audio that belongs into a video.
The default audio sampling rate for video is 48 kHz.
@“kamalakarbapanapalli@gmail.com” – personally, I would skip the handbrake part and just use ffmpeg. It looks like you are already remuxing the subtitle into a temporay file with ffmpeg to begin with anyway. Here’s a simple example that will make a web optimized mp4 video with stereo audio and burned in subtitles. It doesn’t try to resize (as your code seems to do) or change the frame rate. It just burns in the subtitles. Note: it uses “.srt” files instead of “.ass” files, simply because they are more common.
The above code sets the audio track language to English, but change that to whatever 3-letter code you want if that isn’t your language of choice. -metadata:s:a:0 language=eng << Change that code.
If you want or need to use “.ass” files, you need to configure ffmpeg to look for the proper fonts, but this code does the same thing: Unless you need particular formatting of the subtitles such as location on the screen, etc, srt files work just as well (even better in my opinion)
If that works, you can do some research to re-size, change frame rate, etc using ffmpeg. I’m pretty sure Handbrake is just a user interface for ffmpeg anyway.
Sir,
Appreciate your detailed reply and time.
We are hard coding subtitles in telugu using ffmpeg font. ffmpeg failed to hard code subtitles properly in telugu.
It is doing an excellent job in english. Hence with the help of an expert user in some other forum we came across through google search helped us with the above code.
With the above code we were able to get the telugu font properly with out any issues, but we are seeing poor audio and video quality.
We initially did hard coding with english subtitles.
FFmpeg didnot change any video and audio parameters it just added subtitles when compared with our original video
all our issue started with the hand brake software output file.
Now that we are using the above code. some how audio is completly lost
if i remove some part of the code, audio quality is lost.
What additional parameters do i need to add to hand brake to set my audio quality proper. kindly suggest
@OttoKerner said:
I am not an expert in ffmpeg, but I advise you to never use a sampling rate of 44.1 kHz for any audio that belongs into a video.
The default audio sampling rate for video is 48 kHz.
44.1 kHz was only used on audio CDs.
44.1 - bad
48 - good
My Roku won’t even play audio at 44.1- silence is not golden in this case.
The only time I ever heard ‘Train Wreck’ Audio was when using AAC Main.
There’s a handy Handbrake Guide in my signature and I fail to see how using the cli makes it any easier.
i have 30000 files to be created and corrected.
thats why i need to use hand brake along with ffmpeg as ffmpeg failed in adding utf-8 language properly