VideoHelp Forum




+ Reply to Thread
Results 1 to 25 of 25
  1. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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 ?
    Quote Quote  
  2. Member bat999's Avatar
    Join Date
    Feb 2008
    Location
    United Kingdom
    Search Comp PM
    ...
    Last edited by bat999; 14th Oct 2010 at 04:47.
    Quote Quote  
  3. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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
    Quote Quote  
  4. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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 ?
    Quote Quote  
  5. Explorer Case's Avatar
    Join Date
    Feb 2004
    Location
    Middle Earth
    Search Comp PM
    Originally Posted by Klagar View Post
    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
    Quote Quote  
  6. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    Nice ! Exactly what I was looking for !
    I'll post about OS-dependency as soon as I've run some tests.

    Thanksssssss !!!
    Quote Quote  
  7. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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).
    So it seems Case's trick would work independently of OS, or at the very least with Windows and Linux.
    Quote Quote  
  8. You realise that it's just syntactic sugar, right?
    Quote Quote  
  9. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    Sure
    Just wanted to emphasize that the "&&" trick should work.
    Quote Quote  
  10. Originally Posted by Klagar View Post
    Sure
    Just wanted to emphasize that the "&&" trick should work.
    I'm saying that it's the same thing in practice, except that command1 && command2 means that it will only execute command2 if command1 was successful. Basically, you still "encode the file twice"; it's not "executed in one shot".

    Just wanted to make sure you knew that .
    Quote Quote  
  11. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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
    Quote Quote  
  12. 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"
    Quote Quote  
  13. Explorer Case's Avatar
    Join Date
    Feb 2004
    Location
    Middle Earth
    Search Comp PM
    Originally Posted by majcho View Post
    Tried to concantenate two or more files
    How about using mencoder for that:
    Code:
    mencoder -forceidx -ovc copy -oac copy -o output.avi part1.avi part2.avi ...
    Quote Quote  
  14. Member ricardouk's Avatar
    Join Date
    Mar 2005
    Location
    Portugal
    Search Comp PM
    Originally Posted by Klagar View Post
    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 dont need the ""&&"" just write the 2 commands in the same bat, it should do the 2 pass without further intervention from you, its what i do.
    I love it when a plan comes together!
    Quote Quote  
  15. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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
    Quote Quote  
  16. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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.
    Quote Quote  
  17. Member ricardouk's Avatar
    Join Date
    Mar 2005
    Location
    Portugal
    Search Comp PM
    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!
    Quote Quote  
  18. Member ricardouk's Avatar
    Join Date
    Mar 2005
    Location
    Portugal
    Search Comp PM
    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!
    Quote Quote  
  19. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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
    In brief, I took the integrality of your code, adapted the file locations, and added "-f mp4". That's all.

    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>
    I know this is a lot, but maybe someone can help me make sense of this ?
    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 !
    Quote Quote  
  20. Member ricardouk's Avatar
    Join Date
    Mar 2005
    Location
    Portugal
    Search Comp PM
    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
    for h264
    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!
    Quote Quote  
  21. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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.
    Quote Quote  
  22. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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 !
    Quote Quote  
  23. Member Klagar's Avatar
    Join Date
    Sep 2010
    Location
    Montreal, Canada
    Search Comp PM
    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 !
    Quote Quote  
  24. Member ricardouk's Avatar
    Join Date
    Mar 2005
    Location
    Portugal
    Search Comp PM
    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 cmd
    I love it when a plan comes together!
    Quote Quote  
  25. Banned karatang's Avatar
    Join Date
    Oct 2010
    Location
    Shenzhen,China
    Search Comp PM
    It seems difficult.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!