Just a question about 2-passing in FFmpeg : is it necessary to encode the file twice, or is it possible to put it all in only one command line, so the 2 passes are executed in one shot ?
+ Reply to Thread
Results 1 to 25 of 25
-
-
Is my question unclear ?
Let me try to ask it otherwise :
From what I've seen so far, I deduce a 2-pass encoding using FFmpeg involves using a command line with the -pass 1 parameter (or something similar), producing an output file, which I must encode a second time using the -pass 2 parameter (or something similar, again) and some other different options. Am I correct ? If so, is the same result obtainable using a single command line ? If not, where is my understanding flawed ? :S -
Maybe an example would help :
In this thread, Slider used two command lines :
ffmpeg -i %~n1.mpg -pass 1 -passlogfile %~n1 -an foo.mpg
and
ffmpeg -i %~n1.mpg -pass 2 -passlogfile %~n1 -b 2200 -bufsize 600 -vcodec mpeg2video -s 720x480 -an %~n1(720x480).mpg
So he had to encode the same file twice, in two shots, right ?
Is it possible to obtain the same result in one command line ? -
You can concatenate several ffmpeg commands with the "&&" separator. Not sure if it is OS dependent.
http://forums.creativecow.net/readpost/291/70 -
Nice ! Exactly what I was looking for !
I'll post about OS-dependency as soon as I've run some tests.
Thanksssssss !!! -
Reply from the Doom9 forum where I asked for clarifications :
"&&" is the same on Unix/Linux. The following command is only run when the previous command ends successfully (returns a zero exit code). If you want all the commands to run one after another regardless of their exit status, use "&" with cmd.exe and ";" on Unix/Linux (where "&" would make the previous command run in background). -
Sure
Just wanted to emphasize that the "&&" trick should work. -
-
Oh yeah, I know...
The thing is, I didn't want to have to open the file twice, or press twice the "Encode" button... You know, just let it start, go grab some coffee, and know that when I'm back, It'll be fully done -
Tried to concantenate (join, combine) two or more files with this &&-ffmpeg command. However, when it comes to concatenating the files, the "cat" command returns a 0 byte file. Does anyone know how to concatenate the two files with ffmpeg?
Tools\ffmpeg\ffmpeg_06 -i "HQ-in\%%i" -ss 00:00:10 -t 00:00:10 -vcodec copy -f mp4 tmp1.mp4 && Tools\ffmpeg\ffmpeg_06 -i "HQ-in\%%i" -ss 00:00:30 -t 00:00:10 -vcodec copy -f mp4 tmp2.mp4 && cat tmp1.mp4 tmp2.mp4 > "HQ-mp4\%%i.mp4" -
-
I love it when a plan comes together!
-
Ok this will be a very newbie question, cause I thought I had it figured out, but ultimately looks like I didn't...
When you do a 2-pass encoding, does it mean you take your source (say, movie A), convert it to movie B, and then re-convert movie B to movie C ? Or does it mean you take your movie A, let the encoder run over it once, and then a second time, which will directly output the movie C without having a movie B in between ?
The answer might seem obvious, but what confised me is that Robert Swain, on his x264 encoding guide, gives some advice on 2-passes, and tells that for the first pass it is not necessary to encode the audio. Does that mean that the second solution I propose is the good one, or is it that Robert Swain omitted some part of the encoding that would transfer the audio ? Right now, the way I see it, you go from movie A to a movie B without audio, and it tells nothing in particular about recovering the sound and putting it back in movie C.
If the second guess is the good one, and 2-passing means encoding movie A twice and having movie C at the output, can anyone tell me how it works concretely ? Does the pass 1 create a temporary file that will be used as a reference somehow in pass 2 ? Or does the pass 1 store information on the bitrate distribution and other things about the video that the pass 2 will recover and use ? And if so, what command, what part of the script or whatever, tells where the information comes from and where it should go ?
That's the point that bugs me most : there seems to be no relation between the two commands, and I wonder how they interact at all...
Any enlightenment is welcome, information is rather scarce on the subject.
Regards and thanks so much !Last edited by Klagar; 2nd Nov 2010 at 13:24. Reason: Clarification
-
Also, @Ricardouk : can you please give me an example of how you do ? I'd like to have the exact syntax, for I've tried many combinations before encountering the "&&" trick and came out with naught.
You do pass your script directly in the command prompt, right ? No particular FFmpeg GUI used ?
If it worked I'd be a happy guy. I like simple. -
here's what i used in the past, it was used for testing x264 in ffmpeg, it might not be "up to date" but it works:
Code:ffmpeg -y -i 123.avi -an -pass 1 -threads 0 -vcodec libx264 -b 400k -bf 3 -subq 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 test3.mp4 ffmpeg -y -i 123.avi -acodec libfaac -ar 22050 -ab 48k -pass 2 -threads 0 -vcodec libx264 -b 400k -bf 3 -subq 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 test3.mp4 del ffmpeg2pass-0.log del x264_2pass.log
Last edited by ricardouk; 3rd Nov 2010 at 07:37.
I love it when a plan comes together! -
ffmpeg guis:
1- Avanti - (the one i use)
http://avanti.arrozcru.com/
2- sgi's video converter gui
http://sourceforge.net/projects/sgisgui/
(you can see the cmd used by the program and learn)
3- Winff
http://winff.org/
(you can see the cmd used by the program and learn)I love it when a plan comes together! -
Thanks ricardouk for the lines ! I'm trying to make them work out, but I'm having issues with it.
Here are the lives I used :
Code:ffmpeg -y -i "C:/Documents and Settings/User/Desktop/video test/big_buck_bunny.avi" -f mp4 -an -pass 1 -threads 0 -vcodec libx264 -b 400k -bf 3 -subq 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 "C:/Documents and Settings/User/Desktop/video test results/bbb_2pass_try1_0.mp4" ffmpeg -y -i "C:/Documents and Settings/User/Desktop/video test/big_buck_bunny.avi" -f mp4 -acodec libfaac -ar 22050 -ab 48k -pass 2 -threads 0 -vcodec libx264 -b 400k -bf 3 -subq 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 "C:/Documents and Settings/User/Desktop/video test results/bbb_2pass_try1_0.mp4" del ffmpeg2pass-0.log del x264_2pass.log
Here's what the commant prompt gave me as an answer :
Code:C:\Program Files\ffmpeg5>ffmpeg -y -i "C:/Documents and Settings/User/Desktop/video test/big_buck_bunny.avi" -f mp4 -an -pass 1 -threads 0 -vcodec libx264 -b 400k -bf 3 -subq 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 "C:/Documents and Settings/User/Desktop/video test results/bbb_2pass_try1_0.mp4" FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al. configuration: --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-avisynth --enable-libfaac --enable-libfaad --enable-libmp3lame --en able-libspeex --enable-libtheora --enable-libvorbis --enable-libxvid --enable-libx264 --enable-memalign-hack libavutil 49.15. 0 / 49.15. 0 libavcodec 52.20. 0 / 52.20. 0 libavformat 52.31. 0 / 52.31. 0 libavdevice 52. 1. 0 / 52. 1. 0 libavfilter 0. 4. 0 / 0. 4. 0 libswscale 0. 7. 1 / 0. 7. 1 libpostproc 51. 2. 0 / 51. 2. 0 built on Mar 16 2009 16:09:18, gcc: 4.2.4 [Sherpya] Input #0, avi, from 'C:/Documents and Settings/User/Desktop/video test/big_buck_bunny.avi': Duration: 00:09:56.48, start: 0.000000, bitrate: 4456 kb/s Stream #0.0: Video: mpeg4, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 24 tbr, 24 tbn, 24 tbc Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s Output #0, mp4, to 'C:/Documents and Settings/User/Desktop/video test results/bbb_2pass_try1_0.mp4': Stream #0.0: Video: libx264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], q=10-51, pass 1, 400 kb/s, 90k tbn, 25 tbc Stream mapping: Stream #0.0 -> #0.0 [libx264 @ 0x1725010]using SAR=1/1 [libx264 @ 0x1725010]using cpu capabilities: MMX2 SSE2Fast SSSE3 PHADD SSE4.2 [libx264 @ 0x1725010]profile High, level 3.1 Press [q] to stop encoding frame= 73 fps= 52 q=-1.0 Lsize= 160kB time=2.96 bitrate= 442.1kbits/s video:158kB audio:0kB global headers:1kB muxing overhead 0.893650% [libx264 @ 0x1725010]slice I:1 Avg QP:11.00 size: 168 [libx264 @ 0x1725010]slice P:18 Avg QP:22.69 size: 4225 [libx264 @ 0x1725010]slice B:54 Avg QP:21.53 size: 1579 [libx264 @ 0x1725010]consecutive B-frames: 0.0% 0.0% 0.0% 100.0% [libx264 @ 0x1725010]mb I I16..4: 100.0% 0.0% 0.0% [libx264 @ 0x1725010]mb P I16..4: 41.5% 29.5% 0.3% P16..4: 6.1% 0.3% 0.3% 0.0% 0.0% skip:22.0% [libx264 @ 0x1725010]mb B I16..4: 17.2% 0.0% 0.0% B16..8: 5.0% 0.1% 0.1% direct: 9.2% skip:68.5% L0:46.8% L1:44.4% BI: 8.7% [libx264 @ 0x1725010]final ratefactor: 37.56 [libx264 @ 0x1725010]8x8 transform intra:23.0% inter:90.4% [libx264 @ 0x1725010]ref P L0 72.6% 14.0% 10.3% 2.4% 0.7% [libx264 @ 0x1725010]ref B L0 93.2% 2.8% 2.8% 1.1% [libx264 @ 0x1725010]ref B L1 97.7% 2.3% [libx264 @ 0x1725010]SSIM Mean Y:0.9861921 [libx264 @ 0x1725010]kb/s:442.4 C:\Program Files\ffmpeg5> 6 -cmp 256 -refs 5 -qmin 10 -qmax 51 -qdiff 4 -coder 1 -flags +loop -me_method hex -me_range 16 -trellis 1 -flags +mv4 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 240 -r 25 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 "C:/Documents and Settings/User/Desktop/video test results/bbb_2pass_try1_0.mp4" '6' is not recognized as an internal or external command, operable program or batch file. C:\Program Files\ffmpeg5>
It seems to process the first pass, but stops after having encoded 160Ko (or 3 seconds) worth of video file. And then it automatically displays the second command line (the one starting with a "6 -cmp 256") and I don't understand why it omits the first part of that line.
You said your code might not be up to date, but I can't believe it is the reason for not working.
I'll keep posting if I ever encounter a quick solution !
Regards ! -
taken from sgi video converter bat file
for xvid
Code:ffmpeg.exe -y -i 123.avi -pass 1 -passlogfile text.log -threads 2 -vcodec libxvid -vtag XVID -f mp4 -aspect 16:9 -r 25 -s 720x576 -b 2000kb -minrate 2000kb -maxrate 2000kb -bufsize 2048k -an output.mp4 ffmpeg.exe -y -i 123.avi -pass 2 -passlogfile text.log -threads 2 -vcodec libxvid -vtag XVID -f mp4 -aspect 16:9 -r 25 -s 720x576 -b 2000kb -minrate 2000kb -maxrate 2000kb -bufsize 2048k -acodec libfaac -ac 2 -ab 128kb -ar 44100 output.mp4
Code:ffmpeg.exe -y -i 123.avi -pass 1 -passlogfile text.log -threads 2 -vcodec libx264 -f mp4 -aspect 16:9 -r 25 -s 480x340 -b 512kb -minrate 512kb -maxrate 512kb -bufsize 2048k -an output.mp4 ffmpeg.exe -y -i 123.avi -pass 2 -passlogfile text.log -threads 2 -vcodec libx264 -f mp4 -aspect 16:9 -r 25 -s 480x340 -b 512kb -minrate 512kb -maxrate 512kb -bufsize 2048k -acodec libfaac -ac 2 -ab 128kb -ar 44100 output.mp4
I love it when a plan comes together! -
Do you enter the lines "as is" ?
'Cause when I do, it seems to run the first command and forget the second one. However, if I try to put both lines in a single one (with only a whitespace to separate them) it gives me an error and refuses to proceed.
If I try and run the commands one after the other, it does the first pass just fine, and at the second one gives me the following message :
[libx264 @ 0x1725010]using SAR=1/1
[libx264 @ 0x1725010]using cpu capabilities: MMX2 SSE2Fast SSSE3 PHADD SSE4.2
And then it stops, and doesn't even writes the usual "C:\Program Files\ffmpeg5>", so I can't write anything more in this window.
I tried to Google it. To no avail. Does it even mean anything useful ?
I used the commands for H264, changing only the path to input and output files, and setting the size to 1280x720. Nothing else.
The log file creates itself but is empty when I open it. Dunno if it's normal...
Thanks so much for your patience, at every step I fell I'm getting closer to the goal, there must be just some shitty detail that doesn't want me to succeed...
Regards. -
Ok after a few tries I noticed the Xvid lines work perfectly (although I still have to put "&&" between them if I want them to run in one shot). I compared with a 1-pass "equivalent" and the 2-pass produced a file slightly heavier but of better quality. I'll adapt parameters to suit my needs and see what it gives.
Any idea why the x264 would not work ???
Thanks as always ! -
I found the solution to my problem.
Turns out I had the wrong version. That's all.
I was testing with version 0.5. I updated to SVN-r25669 and now it works (almost) totally neat !
So thanks Ricarcouk, your intervention amply answered my (second) initial question : I understand the information that has to be retrieved by the second pass in stored in a .log file which, when used in conjunction with the source video, give all the information needed for a quality encoding.
Correct me immediately if I understood wrong, but if I am correct, I hope some people find the (small) fruits of my search useful.
Points of the story :
1. Get the freakin latest version, lest you want to look like a total n00b ;
2. Make sure you did point 1 ;
3. Respect Case, Roflwaffle and Ricardo and everybody who looks like them.
Kidding.
Regards ! -
no need to thank me, just passing what i learn here, if i'm allowed i will had one more thing to your list:
whenever possible try to use programs (guis) that let you see which cmd they use.
ex:
Multix264
http://forum.doom9.org/showthread.php?t=151272
see the cmd it uses in the "queue" section, select different encoders and "refresh" that section to see the updated cmdI love it when a plan comes together!
Similar Threads
-
FFMPEG 2-pass syntax help needed
By ITemplate in forum Video ConversionReplies: 7Last Post: 2nd Jul 2011, 19:41 -
ffmpeg 2-pass does nothing
By grv575 in forum Video ConversionReplies: 13Last Post: 6th Oct 2010, 20:24 -
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