VideoHelp Forum




+ Reply to Thread
Results 1 to 29 of 29
  1. Anonymous543
    Guest
    Hii everyone am trying to do 2 pass encoding with ffmpeg cli in windows

    By following this guide

    https://trac.ffmpeg.org/wiki/Encode/H.264

    After typing 1st line which is

    ffmpeg -y -i input.mp4 -c:v libx264 -b:v 340k -pass 1 -an -f null NUL && ^

    I pressed enter and it shows
    more?
    Again I hit enter it shows
    more?

    Image
    [Attachment 62220 - Click to enlarge]



    After pressing enter 3rd time it starts some processing and makes 2 files

    Image
    [Attachment 62224 - Click to enlarge]


    Image
    [Attachment 62225 - Click to enlarge]


    1 file has .log extension and
    1 file has .log.mbtree

    Question 1. What does this files contains?

    After that I enter 2nd line in ffmpeg which is

    ffmpeg -i input.mp4 -c:v libx264 -b:v 340k -pass 2 -c:a copy output.mp4

    And hit entered and process happens and I got output.mp4


    Question 2. Is this the correct method to do 2 pass encoding or I should type 2nd line after typing 1 line when it asks more?

    Image
    [Attachment 62223 - Click to enlarge]


    Like this??




    Question 3. do I need to specify inputfile/outputfile containers formats also like input.mp4/output.mp4 or just need to specify file names?
    Quote Quote  
  2. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    Why not use a GUI frontend?
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  3. Anonymous543
    Guest
    Because I wanna learn ffmpeg cli
    Quote Quote  
  4. I'm a Super Moderator johns0's Avatar
    Join Date
    Jun 2002
    Location
    canada
    Search Comp PM
    kirito-please do no post in other threads about the same subject you asked for help here,i deleted your post,continue here.
    I think,therefore i am a hamster.
    Quote Quote  
  5. Anonymous543
    Guest
    Sorry ,it won't happend again
    Quote Quote  
  6. Member hech54's Avatar
    Join Date
    Jul 2001
    Location
    Yank in Europe
    Search PM
    Originally Posted by lordsmurf View Post
    Why not use a GUI frontend?
    Exactly.
    Quote Quote  
  7. Anonymous543
    Guest
    TBH in gui softwares we can do limited things ,and in cli we can do almost everything like adding subtitles, editing meta data ,etcetc so I think cli has more advantage then gui ,that's why wanna learn cli
    Last edited by Anonymous543; 8th Dec 2021 at 02:01.
    Quote Quote  
  8. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    if you want to enter the pass 1 and pass 2 commands in a single step, this seems to work:
    Code:
    ffmpeg.exe -y -i input.mp4 -c:v libx264 -b:v 2600k -pass 1 -an -f mp4 NUL &&  ffmpeg.exe -i input.mp4 -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k outputx.mp4
    You can separate it into two commands (entered one after the other) if you like
    Code:
    ffmpeg.exe -y -i 11am.mp4 -c:v libx264 -b:v 2600k -pass 1 -an -f mp4 NUL 
    ffmpeg.exe -i 11am.mp4 -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k outputx.mp4
    I'm not sure what the ^, ` or \ is supposed to do, I didn't use it
    Quote Quote  
  9. Anonymous543
    Guest
    Ohh let's see what others says
    I hope someone know
    Quote Quote  
  10. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Quote Quote  
  11. The ^ character followed by a New line is the equivalent of the \ in Linux - it means that you treat the next line as a continuation of the current line I believe, and makes it neater to read.

    So in Linux :

    ffmpeg -y -i input -c:v libx264 -b:v 2600k -pass 1 -an -f null /dev/null && \
    ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4

    That means do the first ffmpeg process, wait for it to complete without errors and then do the second ffmpeg process when the first process has finished. If you didn't have the && / it would just try to do the second command after the first whether the first one had completed without errors or not (and would be trickier to cut and paste directly into a CLI). It won't execute the second command if the first one errors.

    It's the equivalent of :

    ffmpeg -y -i input -c:v libx264 -b:v 2600k -pass 1 -an -f null /dev/null && ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4

    but easier to read.

    For Windows you replace /dev/null with NUL and replace && \ with && ^ to do the same thing.

    ^ is the 'treat the following character as a character not a command line thing' escape character in Windows, so it effectively tells Windows to ignore the new line between the two lines, and treat the second line as if it was typed at the end of the first without a newline. (^ is also how you insert characters into command lines as characters that would otherwise tell Windows to do something, like |)
    Quote Quote  
  12. Originally Posted by kirito View Post
    Hii everyone am trying to do 2 pass encoding with ffmpeg cli in windows

    By following this guide

    https://trac.ffmpeg.org/wiki/Encode/H.264

    After typing 1st line which is

    ffmpeg -y -i input.mp4 -c:v libx264 -b:v 340k -pass 1 -an -f null NUL && ^


    Either you should cut and paste both lines at once to the command line - the ^ followed by a newline is the instruction to the Windows CLI to ignore that newline or if you don't like it you can remove the ^ and just paste the second line right after the && and then run the command by hitting Enter.

    OR you can just leave the && ^ out entirely and run the first pass by pasting the first pass up to NUL , wait for it to finish, and then run the second line separately.

    All the && and && ^ do is let the second pass run automatically after the first pass (if the first pass completes without error) IF you have entered the second pass command after the && (on the same line) or the && ^ on the second line.

    After pressing enter 3rd time it starts some processing and makes 2 files

    1 file has .log extension and
    1 file has .log.mbtree

    Question 1. What does this files contains?
    These are log files of the first pass encoding - which will be use by the second pass to optimise the encode. They are the reason to do the first pass. They give the second pass encoder hints about more than just the video it is encoding at one specific moment.

    After that I enter 2nd line in ffmpeg which is

    ffmpeg -i input.mp4 -c:v libx264 -b:v 340k -pass 2 -c:a copy output.mp4

    And hit entered and process happens and I got output.mp4
    That has worked OK.

    The More? is the Windows CLI being confused by you asking it to run a second command after the first with the && and not giving it more code to run after the && I think?



    Question 3. do I need to specify inputfile/outputfile containers formats also like input.mp4/output.mp4 or just need to specify file names?
    You can either specify wrappers/containers explicitly or ffmpeg will guess from the file extension you have requested - such as .mkv, mp4, .mov, .mxf etc. If you aren't using a standard wrapper and outputting something less conventional (like raw video or a format without a standardised extension, or with more options than just a container choice, then you may need to specify output container or container options explicitly).

    For an x264 encoded h.264 .mp4 then -codec:v libx264 and output.mp4 tells ffmpeg what it needs to know.
    Quote Quote  
  13. Anonymous543
    Guest
    Nice!! Explaination

    But I'll use lines separately for simplicity in windows command prompt

    Question 1. so what will be the first line code and second line code?
    May be this?

    ffmpeg -y -i input -c:v libx264 -b:v 2600k -pass 1 -an -f null

    Enter key


    ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4


    Or correct it if am wrong?




    And I saw h265 two pass encoding guide also
    At here

    https://trac.ffmpeg.org/wiki/Encode/H.265

    It's almost same as h264

    Difference is -265-params pass=1 and
    -265-params pass=2

    Question 2. What this codes do? -265-params pass=1 and -265-params pass=2



    Question 3. If I have a input file named input.3gp and I wanna convert to output.mp4

    So In this case I have to specify inputfile name with its container and also outputfile name with its container right?

    Like this?
    ffmpeg -i input.3gp output.mp4

    If I don't specify output container
    Like this

    Ffmpeg -i input.3gp output

    then ffmpeg will convert my input in to raw output?
    Quote Quote  
  14. Originally Posted by kirito View Post
    Question 1. so what will be the first line code and second line code?
    May be this?

    ffmpeg -y -i input -c:v libx264 -b:v 2600k -pass 1 -an -f null

    Enter key

    ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4
    That looks OK.

    And I saw h265 two pass encoding guide also
    At here

    https://trac.ffmpeg.org/wiki/Encode/H.265

    It's almost same as h264
    I think you mean the libx265 encoder is almost the same as the libx264 encoder in ffmpeg? (There are often other h.264 and h.265 encoders you can use in ffmpeg to allow for nVidia, Intel, Apple hardware acceleration rather than software encoding)

    h.264/AVC and h.265/HEVC are the codecs, x264 and x265 are particular software implementations of those codecs.

    Difference is -265-params pass=1 and
    -265-params pass=2

    Question 2. What this codes do? -265-params pass=1 and -265-params pass=2
    libx264 and libx265 are separate implementations of two different encoders - I don't use libx265 much but it could be that the ffmpeg implementation of dual-pass encoding requires libx265 to be passed parameters differently to libx264. ffmpeg is a kit of parts - not all the components in that kit work identically.

    Looks to me like the way you tell ffmpeg and libx264 to do 2-pass encoding (and which pass they are to do) and the way you tell libx265 to do it may be different - or they may be two different ways of telling an encoder to do the same thing.


    libx264 (a software h.264 encoder in ffmpeg) passes parameters differently to say, h264_qsv (which is the Intel QuickSync accelerated h.264 encoder implementation which can be optionally used in ffmpeg)

    There are often multiple ways of telling ffmpeg to do the same thing...

    Question 3. If I have a input file named input.3gp and I wanna convert to output.mp4

    So In this case I have to specify inputfile name with its container and also outputfile name with its container right?

    Like this?
    ffmpeg -i input.3gp output.mp4
    In that case you are asking FFmpeg to implicitly guess what you want as an output container by the file extension - i.e. you want the output muxed into an mp4 container.

    For inputs ffmpeg will often look at what is IN the file rather than just the file extension - so it can cope if the extension is incorrect. The input extension doesn't FORCE ffmpeg to expect just one container.


    If I don't specify output container
    Like this

    Ffmpeg -i input.3gp output

    then ffmpeg will convert my input in to raw output?
    I think you are confusing containers/wrappers and codecs?

    You haven't told ffmpeg anything about the output codec OR wrapper/container - so it may just chose a default.

    If you want to transcode then you add -codec:v and -codec:a options to select the video and audio codec to use, if you want to retain the original encoding (not always possible as not all containers support all codecs) then you use -codec:v copy or -codec:a copy and it will remux but not transcode.

    The container can be selected either with a command line option OR you can let ffmpeg decide based on the output file extension. ffmpeg will also default to certain settings if you don't explicitly request them.
    Quote Quote  
  15. Anonymous543
    Guest
    No no no no I meant that codes for two pass encoding for libx264 and libx265 looks almost same

    libx264 code =
    ffmpeg -y -i input -c:v libx264 -b:v 2600k -pass 1 -an -f null /dev/null && \

    ffmpeg -i input -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k output.mp4



    libx265 code =
    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params pass=1 -an -f null /dev/null && \

    ffmpeg -i input -c:v libx265 -b:v 2600k -x265-params pass=2 -c:a aac -b:a 128k output.mp4


    Question 1. Difference is -265-params pass=1 and -265-params pass=2
    What does -265-params pass=1 and -265-params pass=2 do?
    I mean -265-params pass=1 and -265-params pass=2 what it specifies?
    Like -i code specifies input file
    Quote Quote  
  16. Anonymous543
    Guest
    -265-params option will not overight any h265 default parameters?
    Quote Quote  
  17. "-265-params" tells ffmpeg to pass the next argument directly to x265. It lets you send parameters that ffmepg doesn't support directly to the encoder. So "-265-params pass=1" tells ffmpeg not to parse "pass=1" itself but rather send it to the x265 encoder.

    Note that during a 2-pass encoding the first pass is used to get statistics about how much bitrate is needed by every frame (using a CRF encode). That's what's in the log files. During the second pass those statistics are used to allocate bits to each frame to best achieve the requested average bitrate.
    Last edited by jagabo; 8th Dec 2021 at 09:26.
    Quote Quote  
  18. Sorry - please re-read my explanation - I've already answered that question :

    libx264 and libx265 are separate implementations of two different encoders - I don't use libx265 much but it could be that the ffmpeg implementation of dual-pass encoding requires libx265 to be passed parameters differently to libx264. ffmpeg is a kit of parts - not all the components in that kit work identically.

    Looks to me like the way you tell ffmpeg and libx264 to do 2-pass encoding (and which pass they are to do) and the way you tell libx265 to do it may be different - or they may be two different ways of telling an encoder to do the same thing.


    libx264 (a software h.264 encoder in ffmpeg) passes parameters differently to say, h264_qsv (which is the Intel QuickSync accelerated h.264 encoder implementation which can be optionally used in ffmpeg)
    If ffmpeg doesn't have a built-in way of signalling two-pass encoding to libx265 in the way it does libx264 then you may have to pass that information implicitly using ffmpeg's ability to send flags/parameters directly into libx265.

    It's important to remember that libx264 and libx265 aren't specifically part of ffmpeg - they are separate libraries that ffmpeg uses. As such ffmpeg can be customised to pass flags/parameters from ffmpeg to that library (as is the case of -pass 1 and -pass 2 and libx264) but you can't expect ffmpeg to have ways of sending all flags/parameters - hence the ability to also send parameters directly to libraries separately to any functionality ffmpeg has built in.

    The advantage of ffmpeg having support itself means that the command line instructions stay the same between different codec encoder libraries - but the option to send parameters directly into a codec means you still have flexibility to do stuff that the library supports but ffmpeg might not.

    It's entirely possible you could also send libx264 parameters directly to signal two-pass first pass and two-pass second pass encoding in a similar way to libx265 - but ffmpeg has itself functionality to do that for libx264 that it may not have for libx265 (or it may be the guide you are following pre-dates that functionality - or the writer of that guide prefers that method if there is a choice between two ways of doing the same thing)

    At the end of the day - ffmpeg isn't doing the h.264 or h.265 dual pass encoding itself - it's just passing the right information to libx264 or libx265 for that code to do the two pass video encoding. How ffmpeg and the user instruct libx264 and libx265 to do that two pass encode may vary.

    With ffmpeg -pass 1 and -pass 2 ffmpeg is aware of how to inform libx264 to do two pass first and second passes. With ffmpeg -265-params pass=1 the end user is telling ffmpeg to send the pass 1 or pass 2 flag/parameter to libx265 directly (rather than ffmpeg interpreting one of its own parameters)
    Last edited by nogginvid; 8th Dec 2021 at 09:31.
    Quote Quote  
  19. Anonymous543
    Guest
    I readed this guide again

    https://trac.ffmpeg.org/wiki/Encode/H.265

    I think -x265-params is for tweaking default settings

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params pass=1 -an -f null /dev/null && \

    This code will use default settings for pass 1

    But

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params "keyint=1" pass=1 -an -f null /dev/null && \

    This will make every frame as i-frame and encode in that way
    Still
    Idk properly what -x265-params option/flag do
    Quote Quote  
  20. Again, -x265-params is for passing commands directly to the x265 encoder. That can be anything that ffmpeg doesn't handle itself.

    https://x265.readthedocs.io/en/master/cli.html
    Quote Quote  
  21. Originally Posted by kirito View Post
    I readed this guide again

    https://trac.ffmpeg.org/wiki/Encode/H.265

    I think -x265-params is for tweaking default settings

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params pass=1 -an -f null /dev/null && \

    This code will use default settings for pass 1

    But

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params "keyint=1" pass=1 -an -f null /dev/null && \

    This will make every frame as i-frame and encode in that way
    Still
    Idk properly what -x265-params option/flag do
    yes - as I said - -x265-params lets you send flags/parameters directly to the libx265 encoder, and is for use where ffmpeg doesn't handle those parameters itself, or where the ffmpeg defaults aren't what you want. For the vast majority of users the defaults are what they want - but there are cases where you may need to override ffmpeg's defaults (say if you want a particular GOP structure, I-frame only, to force a particular flag to do with colour gamut etc.)

    If you want to know what those parameters do and why you'd use them - I suggest doing a bit of background reading on x265. This is probably off topic for this thread on two pass encoding using the ffmpeg cli, as you're now more interested, it seems, in x265 encoder parameters?

    Different thread with more focused questions in a different area might be sensible.
    Quote Quote  
  22. Anonymous543
    Guest
    So if I don't specify anything with -x265-params

    Like just use -x265-params pass=1

    Then it will use its default parameters right?
    Quote Quote  
  23. Originally Posted by kirito View Post
    So if I don't specify anything with -x265-params

    Like just use -x265-params pass=1

    Then it will use its default parameters right?
    Yes - same as other encoder libraries. It will use default parameters (that's what the definition of default is after all) unless told otherwise by ffmpeg or directly by parameters sent to the library by the user (using -x265-params for libx265 for instance).
    Quote Quote  
  24. Anonymous543
    Guest
    If I specify param once for a video

    Like

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params "keyint=1" pass=1 -an -f null /dev/null && \

    Then it will not overight default keyint settings forever?

    Means for my next encode I don't specify keyint=1 then
    It will not consider each frame as i-frame right?
    Quote Quote  
  25. Anonymous543
    Guest
    If I specify param once for a video

    Like

    ffmpeg -y -i input -c:v libx265 -b:v 2600k -x265-params "keyint=1" pass=1 -an -f null /dev/null && \

    Then it will not overight default keyint settings forever?

    Means for my next encode I don't specify keyint=1 then
    It will not consider each frame as i-frame right?
    Quote Quote  
  26. Anything you do in ffmpeg will only effect that particular operation. It does not remember settings between different runs.

    And you could have easily tested that for yourself. MediaInfo will show you all the x265 parameters that were used for an encoding. Scroll right and view the "Encoding Settings" line.

    Code:
    Video
    ID                                       : 1
    Format                                   : HEVC
    Format/Info                              : High Efficiency Video Coding
    Format profile                           : Main 10@L3@Main
    Codec ID                                 : V_MPEGH/ISO/HEVC
    Duration                                 : 1 min 11 s
    Bit rate                                 : 2 314 kb/s
    Width                                    : 720 pixels
    Height                                   : 576 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Constant
    Frame rate                               : 25.000 FPS
    Standard                                 : PAL
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 10 bits
    Scan type                                : Interlaced
    Scan type, store method                  : Interleaved fields
    Scan order                               : Bottom Field First
    Bits/(Pixel*Frame)                       : 0.223
    Stream size                              : 19.6 MiB (98%)
    Writing library                          : x265 3.5+9-bf91444e0:[Windows][GCC 10.2.0][64 bit] 10bit
    Encoding settings                        : cpuid=1111039 / frame-threads=3 / numa-pools=8,--aq-mode=2,--aq-strength=1.00 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=720x576 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=3 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-eob / no-eos / no-hrd / info / hash=0 / no-temporal-layers / open-gop / min-keyint=25 / keyint=250 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=0 / scenecut=40 / hist-scenecut=0 / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=3 / limit-refs=1 / no-limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=3 / selective-sao=4 / early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=0.00 / no-rd-refine / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=18.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=2 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=255 / sar-width / : / sar-height=64:45 / overscan=0 / videoformat=5 / range=0 / colorprim=2 / transfer=2 / colormatrix=6 / chromaloc=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=1023 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / hist-threshold=0.03 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / scenecut-aware-qp=0conformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass
    Default                                  : Yes
    Forced                                   : No
    Color range                              : Limited
    Matrix coefficients                      : BT.601
    Quote Quote  
  27. Anonymous543
    Guest
    How do I get media info?

    I seen in vlc player it shows only some media/codec info
    Quote Quote  
  28. Use the program called MediaInfo. Select View -> Text to see all the details.
    Quote Quote  
  29. Anonymous543
    Guest
    Thanks
    Quote Quote  



Similar Threads

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