I've encoded a wmv file to xvid/mp3 -qscale 3
and the resulting video is bytewise identical whether I specify 2 passes or 1. The ffmpeg commandline log does show the first pass takes place. Any ideas?
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 14 of 14
Thread
-
-
I don't know how you did it but FFmpeg requires to manually run the command line twice.
First time with -pass 1 on it, it scans the clip and creates the log file.
Second time with -pass 2 on it, it uses the log file for the final conversion.
You must use exactly the same command line for both passes, only change the -pass number. -
Originally Posted by TJohns
EDIT: The answer then could be... use -qmax 3 instead of -qscale 3 if you insist on 2-pass encoding. -
Originally Posted by Chris K
I think I might get away from WinFF though (even though it has the best interface imo) - FAAC isn't as good as the nero AAC codec and there is a bug in reading the FPS from rmvb files. Not sure I like the alternatives for batch encodes (gnot - old, mediacoder - audio desync, staxrip - quality wasn't on par with other trials). So what's state of the art these days? -
Do you know about ffmpeg's -sameq switch [same quality as original file] that works w/2pass? FF usage docs are included w/WinFF. Here is the, re-encode video & copy audio, preset I use for batching FLV's of same aspect ratio [also select 2pass checkbox & type in aspect]:
-f avi -vcodec libxvid -vtag XVID -sameq -mbd 2 -bf 2 -flags +4mv -trellis -aic -cmp 2 -subcmp 2 -g 300 -acodec copy
Other good apps, usually FFMPEG or MEncoder gui's & pertaining to FLV, I've found are: AutoMen, AutoMKV, Avanti, FFCoder, FormatFactory, HDConvertToX, MEGUI, WinMEnc, & XMediaRecode. A stream repair w/AviDemux is useful on some outputs. Other's 2 look at include: convertvideo, dvd::rip [linux], dotNET, MPEG StreamClip, SMSG, XviD4PSP -
Those flags (with -sameq) gave me a 50m avi for a 150mb wmv. I think I've given up on ffmpeg - they are more concerned with promoting new features than fixing their bugs:
lamemp3 - buffer too small error (really file bug reports and work with other projects on this one - after all, they're one of your dependencies. If there is a regression in lamemp3, it really shouldn't be finger pointing and "not my bug", but that seems to be the case here).
rmvb - ffmpeg doesn't get the fps right for this format
And to top it off, no good AAC codec (comparable to nero's) since everything's a library.
My latest fascination is determining the bitrate accurately with avisynth and then batching some scripts to pipe together the various x264 tools. This will let me determine a good bitrate to use and still have 2-pass for quality (allocation of bits per pixel, which is what matters the most). I'm also convinced an avisynth source (a la meGUI) piped to the commandline encoders is going to give the best quality with fewest desync issues. So I'll give this route a try. Of course post back anything I come up with if it's worthwhile. -
OK, project is done.
It's a powershell script to glue together various utilities to do:
1. Batch encode a bunch of different video files
2. Get the approximate bitrate of each source file (errs on the side of slight overestimation)
3. Use this as the -bitrate parameter for a 2-pass H264/AAC encode
Features:
1. Displays all output in a command prompt. This lets you
a. See the progress and ETA in the title bar
b. Pause encoding with the Pause button on your keyboard
2. As few keystrokes as possible to batch encode - simply put all files to encode in the 'source' directory and run the script
3. High quality encodes - 2-pass, x264, AAC, bitrate equal to the source file bitrate
4. Customizable - everything is in variables at the top of the script which you can edit to tweak the encoding
Why:
1. FFMpeg -sameq didn't give expected results (bad quality)
2. Only WinFF and a handfull of other GUIs have easy batching of many input files
3. Commandline nero AAC encoder outperforms FAAC library
4. -crf is a single pass with less information than a 2-pass encode: http://forum.handbrake.fr/viewtopic.php?f=6&t=848
Download:
http://www.sendspace.com/file/wixy53
Includes all needed tools. Just extract the zip to c:\
Setup:
Put your videos to encode in c:\video\source
cmd
powershell c:\video\encode.ps1
(you can also open with... powershell.exe to set it to open with powershell by default, and then just click on the file to start encoding)
Script (download dependencies seperately):
#--------------------------------------------------------------------------------------------------------------------------
# An AVS script is generated for every AVI that is found in the folder given as a command line argument.
# The source video total bitrate is approximated based on the filesize and video runtime. This will give a good value to use as the bitrate for a 2-pass encode to ensure
# little loss of quality during transcoding.
#
# If you haven't used Powershell before, you can download it from Microsoft for free, then type in "Set-ExecutionPolicy RemoteSigned" to allow execution of unsigned scripts.
# Save the code in a .ps1 file, navigate to that folder in Powershell (works just like in cmd.exe) and type in ".\encode.ps1".
# Or you can just open a cmd shell and type: "powershell .\encode.ps1"
# Description: Batch encoding from various file formats to x264/AAC in an MP4 container.
# Example Usage: .\encode.ps1
# Required tools: x264, bepipe, neroaacenc, mp4box, AviSynth, avsutil - be sure to adapt exe paths below
#Param (
#[string]$Path
#)
# Configure paths here.
# Videos to encode are in $Path
# Temporary files (AVS, video, audio) are saved in $TempPath which is cleared out after every file except on exceptions.
# Muxed video is saved to $OutPath
# $FileTypes lists all file types in $Path that will be encoded
$Path = 'C:\video\source\'
$TempPath = 'C:\video\temp\'
$OutPath = 'C:\video\encoded\'
$FileTypes = @("*.avi","*.mpg","*.mpeg","*.wmv","*.rmvb","*.mkv ")
# Configure exe paths here.
$ExePath = @{}
$ExePath['x264'] = 'C:\video\bin\x264.exe'
$ExePath['bepipe'] = 'C:\video\bin\BePipe.exe'
$ExePath['neroaacenc'] = 'C:\video\bin\neroAacEnc.exe'
$ExePath['mp4box'] = 'C:\video\bin\MP4Box.exe'
$ExePath['avsutil'] = 'C:\video\bin\avsutil.exe'
# Configure AVS script and command line parameters here
$Config = @{}
$Config['AVS'] = 'DirectShowSource("$FilenameIn", convertfps = true)'
#$Config['x264'] = '--crf 22 --ref 5 --mixed-refs --bframes 3 --b-adapt 2 --b-pyramid --weightb --deblock -1:-1 --trellis 2 --partitions all --8x8dct --me umh ' +
#'--threads auto --thread-input --progress --no-psnr --no-ssim --output "$FilenameVideo" "$FilenameAVS"'
$Config['x264pass1'] = '--pass 1 --bitrate $BitrateKbps --stats "$FilenameStats" --output NUL "$FilenameAVS"'
$Config['x264pass2'] = '--pass 2 --bitrate $BitrateKbps --stats "$FilenameStats" --output "$FilenameVideo" "$FilenameAVS"'
$Config['neroaacenc'] = '-q 0.55 -if - -of "$FilenameAudio"'
$Config['AVSBitrate'] = 'DirectShowSource("$FilenameIn")' + "`r`n" +
'filename = "$FilenameDuration"' + "`r`n" +
'WriteFileStart(filename, "FrameCount/FrameRate")'
function Encode($FilenameIn) {
Trap {
write-error $_.Exception.Message
return
}
Write-Host "Encoding $FilenameIn"
$Basename = [system.io.path]::GetFilenameWithoutExtension($FilenameIn)
$FilenameAVS = $TempPath + $Basename + '.avs'
$FilenameAVSBitrate = $TempPath + $Basename + '_bitrate.avs'
$FilenameVideo = $TempPath + $Basename + '_video.mp4'
$FilenameAudio = $TempPath + $Basename + '_audio.mp4'
$FilenameStats = $TempPath + $Basename + '.stats'
$FilenameDuration = $TempPath + $Basename + '_duration.txt'
$FilenameOut = $OutPath + $Basename + '.mp4'
Write-Host '- Generating AVS scripts...'
$Config['AVS'].Replace('$FilenameIn', $FilenameIn) | Out-File $FilenameAVS -Encoding 'ASCII'
$Config['AVSBitrate'].Replace('$FilenameIn', $FilenameIn).Replace('$FilenameDuration', $FilenameDuration) | Out-File $FilenameAVSBitrate -Encoding 'ASCII'
Write-Host '- Getting bitrate...'
& $ExePath['avsutil'] "$FilenameAVSBitrate"
$FileLengthSeconds = Get-Content "$FilenameDuration"
$file = Get-Item "$FilenameIn"
$FileSize = $file.Length
$BitrateKbps = [int]($FileSize / $FileLengthSeconds * 8 / 1000)
Write-Host "$BitrateKbps kbps"
Write-Host '- Encoding video...'
Write-Host '- Pass 1...'
$Execute = $ExePath['x264'] + ' ' + $Config['x264Pass1'].Replace('$FilenameAVS', $FilenameAVS).Replace('$FilenameStats', $FilenameStats).Replace('$BitrateKbps', $BitrateKbps)
& cmd /c "$Execute"
Write-Host '- Pass 2...'
$Execute = $ExePath['x264'] + ' ' + $Config['x264Pass2'].Replace('$FilenameVideo', $FilenameVideo).Replace('$FilenameAVS', $FilenameAVS).Replace('$FilenameStats', $FilenameStats).Replace('$BitrateKbps', $BitrateKbps)
& cmd /c "$Execute"
'- Encoding audio...'
$Execute = $ExePath['bepipe'] + ' --script "Import(^' + $FilenameAVS + '^)"' + ' | ' + $ExePath['neroaacenc'] + ' ' + $Config['neroaacenc'].Replace('$FilenameAudio', $FilenameAudio)
& cmd /c "$Execute"
Write-Host '- Muxing...'
$Execute = $ExePath['mp4box'] + ' -new -add "' + $FilenameVideo + '" -add "' + $FilenameAudio + '" "' + $FilenameOut + '"'
& cmd /c "$Execute"
Write-Host '- Cleaning up...'
Get-ChildItem $TempPath | ForEach-Object { Remove-Item $_.fullname }
Write-Host '- Done'
}
Write-Host '===Begin Batch Encode==='
$OutPath, $TempPath | ForEach-Object {
if ((Test-Path -PathType 'Container' $_) -eq $False) {
if ((Read-Host "Error: Folder `"$_`" not found, type `"y`" to create it") -eq 'y') {
New-Item $_ -Type Directory | Out-Null
} else {
Write-Host 'Exiting. Edit source file to set up temp and output folders!'
exit
}
}
}
foreach ($Exe in $ExePath.Values) {
if ((Test-Path -PathType 'Leaf' $Exe) -eq $False) {
Write-Host "Error: Executable `"$Exe`" not found."
Write-Host 'Exiting. Edit source file to set up exe paths for x264, bepipe, neroaacenc and mp4box!'
exit
}
}
if ($Path -eq '') {
Write-Host 'Error: No path/file specified'
} elseif (Test-Path -PathType 'Leaf' $Path) {
Encode $Path
} elseif (Test-Path -PathType 'Container' $Path) {
Get-ChildItem ($Path + '*') -Include $FileTypes | ForEach-Object { Encode $_.FullName }
} else {
Write-Host "$Path is not a file/folder"
}
Write-Host '===End Batch Encode==='
#-------------------------------------------------------------------------------------------------------------------------- -
Fixed script above to use convertfps=true which is needed for some wmv files
-
you are such a interesting geek
sendspace link expired , and all the files removed, so i went and recreated the whole project, thanks you for adding the powershell script in its full text without it i wouldn't bothered in getting all the requirements together and upload them online , i have to say this power shell script is very cool , i just wondering how would i use qt-faststart.exe after mp4box, im not sure if mp4box enables mp4 to stream, straight away
download here
http://www.megaupload.com/?d=TJZP6TO1
you need Avisynth_258.exe
and of course you need to set powershell as follows " Set-ExecutionPolicy RemoteSigned "
so you can run the script
can you add support for vp8 ? -
there is some type of error or typo not sure what it is, but can you see whats wrong
PS C:\Users\mysoogals> powershell c:\video\encode.ps1
The term 'Script' is not recognized as the name of a cmdlet, function, script file, or operable pro
gram. Check the spelling of the name, or if a path was included, verify that the path is correct an
d try again.
At C:\video\encode.ps1:1 char:7
+ Script <<<< (download dependencies seperately):
+ CategoryInfo : ObjectNotFound: (Script:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
'- Encoding audio...'
$Execute = $ExePath['bepipe'] + ' --script "Import(^' + $FilenameAVS + '^)"' + ' | ' + $ExePath['neroaacenc'] + ' ' + $Config['neroaacenc'].Replace('$FilenameAudio', $FilenameAudio)
& cmd /c "$Execute" -
is there a way to add --bitrate 300 ? whatever i do it always encodes with the full bit-rate, anime is 170mb and i want to turn it into 80mb or 90 could you help
Similar Threads
-
FFMPEG 2-pass syntax help needed
By ITemplate in forum Video ConversionReplies: 7Last Post: 2nd Jul 2011, 19:41 -
2-pass in FFmpeg ?
By Klagar in forum Video ConversionReplies: 24Last Post: 5th Nov 2010, 00:40 -
2-pass conversion using ffmpeg and Send To under Windows XP
By bidmead in forum Video ConversionReplies: 15Last Post: 6th Oct 2008, 12:20 -
Is 2 pass encoding (wmv2) with FFMpeg possible?
By xorfodan in forum LinuxReplies: 0Last Post: 25th Aug 2007, 08:25 -
Need help with ffmpeg 2-pass VBR encoding
By SliderVF14 in forum Video ConversionReplies: 8Last Post: 14th May 2007, 18:03