VideoHelp Forum
+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 38
Thread
  1. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    I'm trying to learn how to use x264's command line, rather than the GUIs, for various reasons. I have read up on x264 options and believe I know the ones that I want to use, but I am experiencing difficulty actually making the encoder work. I downloaded x264 (the 64bit version) from videohelp, and all that I receive is a file that says x264.exe, so I assume that this is all I need.

    When I try to write a script for x264 using my settings nothing happens, which usually means that there is an error in the command line. When I try to write a very simple script, a box flashes before my eyes too quickly for me to read. In programs such eac3to, I look in the directory for the logfile, which tells me what was in the box, but, as there is no directory for the x264.exe, I don't know where the logfile is, or even if there is one.

    Any help would be appreciated.
    Quote Quote  
  2. Member
    Join Date: Aug 2001
    Location: UK
    Search Comp PM
    Simply use "pause" on the end of your script to make the x264 window stay open.

    For example, below is a script I use regularly to convert a directory full of AVI files to H.264/AAC. (needs x264, ffmpeg and mp4box)

    Code:
    F:
    
    chdir F:\Conversion\
    
    for %%i in (*.avi) do (
    
    "D:\Working Directory\x264\x264.exe" --ref 3 --bframes 3 --partitions p8x8,b8x8,i4x4,i8x8 --me umh --trellis 1 --subme 7 --merange 16 --keyint 250 --min-keyint 25 --b-adapt 1 --direct auto --weightb --mixed-refs --b-pyramid none --8x8dct --no-fast-pskip --level 3.1 --crf 19 --video-filter resize:624,352,1:1:lanczos --threads auto --output "D:\Working Directory\%%~ni.264" "%%i"
    
    "D:\Working Directory\x264\ffmpeg.exe"  -y -i "%%i" -vn -acodec libfaac -ab 192k -ac 2 "D:\Working Directory\%%~ni.m4a"
    
    "D:\Working Directory\x264\mp4box.exe" -fps 23.976 -par 1=1:1 -add "D:\Working Directory\%%~ni.264" -add "D:\Working Directory\%%~ni.m4a" -new "D:\Working Directory\%%~ni.mp4" -tmp "D:\Temp"
    
    del "D:\Working Directory\%%~ni.m4a"
    del "D:\Working Directory\%%~ni.264"
    
    )
    
    pause
    Quote Quote  
  3. I put batch files in my SendTo folder so I can right click on a video or AviSynth script and select Send To -> x264yadayada.bat

    x264.exe --crf 18 --ref 3 --bframes 2 --subme 3 --keyint 100 --sar 1:1 --output %1.mkv %1
    pause
    Make sure x264.exe is in your search path.
    Quote Quote  
  4. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Thanks! It seems that it is necessary to put inverted commas round the location of x264.exe, not just the input and output locations.

    "x264.exe" --pass 1 --qp 16 --ref 3 --bframes 3 --b-pyramid --weightb --b-rdo --bime --scenecut 45 --direct auto --filter --analyse all --8x8dct --subme 9 --trellis 0 --me umh --sar 1:1 --mixed-refs --no-fast-pskip --progress --no-psnr --threads 8 --output "output.mkv" "input.avs"
    pause

    What's wrong? Do the parameters have to come in a particular order?

    The "pause" option doesn't seem to work, so I'm probably doing something wrong here too.

    EDIT: I actually can't even make a simple command line work.
    Last edited by Richard1485; 13th Dec 2011 at 18:05.
    Quote Quote  
  5. It's not necessary to put quotes around x264.exe unless you are using a path name with spaces in it.

    The order of the parameters doesn't matter -- in terms of the program running or not. In some cases the order makes a difference in the settings. For example, presets will override parameters before them.

    Open a CLI window to run your batch files. That way it won't close when the batch file completes or fails.
    Quote Quote  
  6. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Thank you. Is a CLI window the same as using Run rather than using the search box that appears when you click start? When I type commands into Run, the window still closes after I input the command.
    Quote Quote  
  7. CLI: Start -> All Programs -> Accessories -> Command Prompt

    You can also run it by typing COMMAND into the Run dialog.
    Quote Quote  
  8. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Thanks. That works. Now I can read the message. It says: failed to load avisynth and could not open input file. My input file is an Avisynth script.

    EDIT: It's a shame that one cannot cut and paste into the CLI Window.
    Quote Quote  
  9. Originally Posted by Jeff B View Post
    Thanks. That works. Now I can read the message. It says: failed to load avisynth and could not open input file. My input file is an Avisynth script.
    Is the AVS script in the current working directory? If not, CD there, or use the full path name of the script.

    Originally Posted by Jeff B View Post
    EDIT: It's a shame that one cannot cut and paste into the CLI Window.
    You can via the pulldown menu in the top left corner.
    Quote Quote  
  10. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Originally Posted by jagabo View Post
    Is the AVS script in the current working directory? If not, CD there, or use the full path name of the script
    I always type the full path name of the script, and I copy and paste it from properties-->security-->object name, so I know it's correct. I'm not sure what the problem is. I'm using the 64bit version of x264 and the 32 bit version of Avisynth. Could that be the problem?

    You can via the pulldown menu in the top left corner.
    Thanks. That will save time lol.
    Quote Quote  
  11. Originally Posted by Jeff B View Post
    I'm using the 64bit version of x264 and the 32 bit version of Avisynth. Could that be the problem?
    That's the problem. 32 bit and 64 bit software run in completely different subsystems. The two cannot communicate with each other. It's as if they are running on separate computers.
    Quote Quote  
  12. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Ah! I suppose I need either the 32 bit version of x264 or the 64 bit Avisynth. I'll try the 32 bit version of x264 first. Thanks!

    EDIT: It's working. Thanks for all your help.
    Last edited by Richard1485; 13th Dec 2011 at 19:37.
    Quote Quote  
  13. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    So, I fed x264 with the following command line:

    x264.exe --level 4.1 --pass 1 --qp 16 --ref 3 --bframes 3 --analyse all --me umh --trellis 1 --subme 9 --merange 16 --keyint 250 --min-keyint 25 --b-adapt 2 --direct auto --weightb --mixed-refs --b-pyramid strict --8x8dct --no-fast-pskip --threads 8 --output "whatever.mkv" "whatever.avs"

    and it encoded the avs to mkv successfully; however, according to mediainfo a number of commands were ignored.

    cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x1:0 / me=dia / subme=2 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=8 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=1 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc=cqp / mbtree=0 / qp=16 / ip_ratio=1.40 / pb_ratio=1.30 / aq=0
    Any idea why the subme shows as 2 and me, as diamond, when I specified 9 and umh respectively? Obviously something is wrong with the syntax, but I cannot see any errors and appear to be following online guides for the encoder settings. It's odd because some of these values are below what I understand the default values to be, so even if I entered the values incorrectly they should still be higher.

    EDIT: Removing --pass 1 seems to make the encoder respond to the commands that I input. Evidently, it should only be specified when performing multiple passes. One problem that still remains is that mediainfo reads aq=0; I thought aq was on by default. Even if I try to use the switch to turn it on manually, it still reads as aq=0.

    EDIT AGAIN: It seems --qp disables aq. Is this correct?

    Moreover, I would appreciate it if someone who knows what they are doing would post the settings that they use for a high quality re-encode of HD material. I understand crf/qp but would like recommendations for the finer settings that give high quality, but are not needlessly high, such as placebo.
    Last edited by Richard1485; 14th Dec 2011 at 06:35.
    Quote Quote  
  14. Pass one is normally a "fast" pass. It intentionally skips a lot of slow settings which have very little effect on the second pass. If you want to run a full quality first pass there is a setting for that. I forget what it is but if you look at the docs it's there. But there's no reason to run a full quality first pass. It's just used to get information about each frame for use during the second pass where the real encoding is done.
    Quote Quote  
  15. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Yes, sorry, I only meant to run one pass in total. I thought that I needed to specify, but if you're performing a CRF/QP encoding it doesn't seem necessary. That's why the encoder didn't respond to inputs.

    What settings do you use, jagabo? e.g. subme, me etc. The higher settings really do slow things down. I had to reduce them considerably. I'm currently using:

    --level 4.1 --profile high --crf 18 --preset medium --tune grain --bframes 3 --ref 3
    Quote Quote  
  16. I use x264 mostly to compress DVDs into watchable files on my server. I'm not looking for archival quality. I use create an AVS script with Mpeg2Source() then:

    x264.exe --preset=veryfast --crf 18 --ref 3 --bframes 2 --subme 3 --keyint 100 --sar 32:27 --output %1.mkv %1

    sar varies depending on the source, obviously. I have several BAT files in my Send To folder so I can right click on an AVS files and Send To one of those batch files.
    Quote Quote  
  17. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    I see. Thanks for posting those settings. It seems "%1" is short hand for "whatever". They seem more or less straightforward apart from the fact that --keyint seems significantly lower than the default. Is this because you are streaming? Thanks again.
    Quote Quote  
  18. That is from my batch file. The %1 is the filename passed on the command line, the name of the AVS script.

    I prefer to use shorter key frame intervals for easier seeking, and better ff and rw performance. The difference in file size (compared to the default of 250) is insignificant.

    I use 2 bframes because bframes are encoded at lower quality. Too many of them in a row produces visible strobing between low quality and higher quality frames. 3 is ok but the difference in compression is very small so I stick with 2.

    If you encode a video with 8 ref frames then look at the report at the end, you'll find that the encoder hardly ever uses more than 4. And even 4 is only used a few percent of the time. The file size difference between 3 and 4 is very small so I stick with 3.

    Subme is the biggest factor in terms of speed here. The default with the veryfast preset is 2 but I found that bumping it up to 3 doesn't take too much longer and delivers slightly better image quality. The difference between subme 3 and higher values shows up as slightly more jagged edges on moving objects and a little more blocking in dark areas.
    Quote Quote  
  19. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    The difference in file size (compared to the default of 250) is insignificant.
    I see. So the file becomes ever so slightly bigger, but ff and rw are better. That seems like a fair trade off, as I often find ff and rw to be sluggish.

    Thanks for the explanation about bframes are ref frames. I always wondered why scene releases used such high figures when there didn't seem to be much benefit.

    Yes, I quickly discovered that subme makes a big difference in terms of speed. I used 7 for the last encoding and that was slow enough. Is there much quality gain in going higher? Motion estimation seems to make a significant difference too.
    Quote Quote  
  20. Originally Posted by Jeff B View Post
    Thanks for the explanation about bframes are ref frames. I always wondered why scene releases used such high figures when there didn't seem to be much benefit.
    I think it's mostly a "bigger is better" mentality. But anime is different than real world video. It may benefit a bit more from more reference frames.

    Originally Posted by Jeff B View Post
    Yes, I quickly discovered that subme makes a big difference in terms of speed. I used 7 for the last encoding and that was slow enough. Is there much quality gain in going higher?
    I find the video looks a little different as you go higher but it's not clear whether it looks better or worse. And with CRF encoding the difference in file size is tiny.

    Originally Posted by Jeff B View Post
    Motion estimation seems to make a significant difference too.
    Yes. But again, I don't see the additional quality as worth the time. If you want to squeeze every last bit out of the video and get the absolute best quality you can use the high settings. But the settings I use give maybe 97 percent of the quality in 1/2 the encoding time of the medium preset and, and maybe 95 percent of the quality in 1/10 the encoding time of the placebo preset.
    Quote Quote  
  21. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Thanks for the info, jagabo.
    Quote Quote  
  22. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    I have a YUY2 source and would like to know if I should convert it to Rec.709 or Rec.601 before feeding it to x264. I assume that it depends on whether the resolution is SD or HD; if so, does anyone know the cut off point for SD?
    Quote Quote  
  23. Originally Posted by Jeff B View Post
    I have a YUY2 source and would like to know if I should convert it to Rec.709 or Rec.601 before feeding it to x264. I assume that it depends on whether the resolution is SD or HD;
    Yes. Or you can specify the colormatrix to remove the ambiguity (though you may find that not all players pay attention to the flag):

    http://mewiki.project357.com/wiki/X264_Settings#colormatrix

    Originally Posted by Jeff B View Post
    if so, does anyone know the cut off point for SD?
    There's the question. Some players assume anything over 576 lines tall is HD (square pixel encodings of 16:9 DVD sources are often stretched to 1024x576). Others may assume anything 1280 pixels wide or wider is HD.
    Quote Quote  
  24. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    (square pixel encodings of 16:9 DVD sources are often stretched to 1024x576)
    Yes, that's how I do it. I think I'll flag anything smaller than 1024x576 as Rec.601 and anything bigger as Rec.709. Thanks, jagabo.
    Quote Quote  
  25. Originally Posted by Jeff B View Post
    (square pixel encodings of 16:9 DVD sources are often stretched to 1024x576)
    Yes, that's how I do it. I think I'll flag anything smaller than 1024x576 as Rec.601 and anything bigger as Rec.709.
    You should flag the video with the colorspace it is -- so it is converted to RGB correctly when displayed. DVD sources are normally rec.601. High def sources are usually rec.709. If you shrink a rec.709 HD video down to to SD sizes it should be flagged as rec.709. If you convert it to rec.601 (eg, ColorMatrix(mode="Rec.709->Rec.601")) it should be flagged as rec.601.
    Quote Quote  
  26. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    Originally Posted by Jeff B View Post
    I have a YUY2 source and would like to know if I should convert it to Rec.709 or Rec.601 before feeding it to x264. I assume that it depends on whether the resolution is SD or HD; if so, does anyone know the cut off point for SD?

    You don't convert it, because YUY2 => YV12 doesn't involve any matrix conversion . Rec.709/601 only applies if you are doing YUV<=>RGB conversions

    The VUI paramaters that you flag in x264 are only metadata, the actual video YUV data is unchanged. It's up to the particular software or hardware player to see if they accept the flag and convert to RGB for display using those flags . But it certain doesn't hurt to flag it properly
    Quote Quote  
  27. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Originally Posted by jagabo View Post
    You should flag the video with the colorspace it is -- so it is converted to RGB correctly when displayed.
    Sorry, jagabo. In my mind, I assumed all of that and my attention was simply on the output resolution; I should have been more precise in my typing.

    Originally Posted by poisondeathray View Post
    You don't convert it, because YUY2 => YV12 doesn't involve any matrix conversion . Rec.709/601 only applies if you are doing YUV<=>RGB conversions
    You're of course right. You explained this to me before. I can't believe that I forgot it. I'm kicking myself.

    Yeah, I know the VUI parameters are just metadata. I just like to do things properly. Thanks, poisondeathray!
    Quote Quote  
  28. Member
    Join Date: Jul 2009
    Location: Spain
    Search Comp PM
    Originally Posted by poisondeathray View Post
    You don't convert it, because YUY2 => YV12 doesn't involve any matrix conversion . Rec.709/601 only applies if you are doing YUV<=>RGB conversions
    Right, but you might still need to convert it (staying in the YUV domain, eg via ColorMatrix) if you intend using a player that ignores the metadata and makes the wrong assumptions about your video.
    Quote Quote  
  29. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    Originally Posted by Gavino View Post
    Originally Posted by poisondeathray View Post
    You don't convert it, because YUY2 => YV12 doesn't involve any matrix conversion . Rec.709/601 only applies if you are doing YUV<=>RGB conversions
    Right, but you might still need to convert it (staying in the YUV domain, eg via ColorMatrix) if you intend using a player that ignores the metadata and makes the wrong assumptions about your video.

    Yes , and another example for that scenario might be a HD YUV source like blu-ray and you're going to SD blu-ray with x264
    Last edited by poisondeathray; 20th Dec 2011 at 13:07.
    Quote Quote  
  30. Member
    Join Date: Feb 2010
    Location: England
    Search PM
    Are there are generalizations about playback devices that might influence one's decision to convert YUV to either Rec.601 or Rec.709? I'm thinking of generalizations along the lines of: Most media players always expect Rec.709 when playing H.264 regardless of resolution or the PS3 always does X or the Xbox 360 always does Y etc.
    Quote Quote  



Similar Threads