Help with x264 options

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Help with x264 options

Post by Kebast »

I'm trying to use 2 pass encoding in order to cap the maximum bitrate for online streaming. I have a 3Mbit upload, and am trying to get the highest quality file possible within that limit. I have a command string that fails to encode for some reason. Could someone tell me which -x option below is killing my encode?

Code: Select all

HandBrakeCLI -i "$1" -o "/var/lib/mythtv/videos/Web-$2.mp4" --preset="High Profile" -2 -T -b 1500 -O -a 1 -E faac -X 960 -B 192 -6 6ch -x me=umh:vbv-maxrate=1800:vbv-bufsize=6000 &> /dev/null < /dev/null &

# :ref=8:deblock=-1,-1:psy-rd=1|0.15:subme=9:me=umh:trellis=2:merange=24:partitions=all
The command as is runs and encodes correctly. When I include the rest of the -x options after the # the encode fails. I'll post a log later if needed (typing this from my phone). I was hoping someone could just tell me if I had conflicting options causing the problem.
thompson
Bright Spark User
Posts: 356
Joined: Sat Dec 12, 2009 8:04 pm

Re: Help with x264 options

Post by thompson »

Log would be helpful.
TedJ
Veteran User
Posts: 5388
Joined: Wed Feb 20, 2008 11:25 pm

Re: Help with x264 options

Post by TedJ »

Code: Select all

psy-rd=1|0.15
Don't use the pipe character to separate psy-rd and psy-trellis... try using a comma instead.
Deleted User 11865

Re: Help with x264 options

Post by Deleted User 11865 »

TedJ wrote:

Code: Select all

psy-rd=1|0.15
Don't use the pipe character to separate psy-rd and psy-trellis... try using a comma instead.
The pipe character is a working delimiter to separate psy RDO from psy trellis, and has the benefit of being locale-agnostic. I can't remember which of the WinGUI or LinGUI uses it in its advanced panel code.
TedJ
Veteran User
Posts: 5388
Joined: Wed Feb 20, 2008 11:25 pm

Re: Help with x264 options

Post by TedJ »

OK, I don't use HandbrakeCLI all that often and as locale agnostic as the pipe character may be, it is used as a command separator in every *nix shell I've ever used. At the very least it would need to be quoted or escaped to stop the shell from interpreting it.
Deleted User 11865

Re: Help with x264 options

Post by Deleted User 11865 »

TedJ wrote:OK, I don't use HandbrakeCLI all that often and as locale agnostic as the pipe character may be, it is used as a command separator in every *nix shell I've ever used. At the very least it would need to be quoted or escaped to stop the shell from interpreting it.
Oh, I hadn't though of that. And you are correct - it doesn't work if it's not escaped.
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Re: Help with x264 options

Post by Kebast »

Just got back in for the night. I pasted the failed log at the bottom of this post. I changed the script to a comma between the psy-rd and psy-trellis and it worked. The very odd thing is that the following script also works just fine:

Code: Select all

HandBrakeCLI -i "$1.tmp" -o "/var/lib/mythtv/videos/$3/$2.mp4" --preset="High Profile" -a 1 -E copy -Y 720 
-x ref=8:deblock=-1,-1:psy-rd=1|0.15:subme=9:me=umh:trellis=2:merange=24:partitions=all &> /dev/null < /dev/null &
Any idea why it works as above, but not with the script in the original post? In any case, a comma works for this one, so problem solved! Thanks!

Code: Select all

/var/lib/mythtv/recordings$ /home/mythtv/Web-encode.sh 1014_20110113131300.mpg Web-Test-7
/home/mythtv/Web-encode.sh: line 6: 0.15:subme=9:me=umh:trellis=2:merange=24:partitions=all:vbv-maxrate=1800:vbv-bufsize=6000: command not found
[23:46:05] hb_init: checking cpu count
[23:46:05] hb_init: starting libhb thread
HandBrake svn3743 (2011011401) - Linux x86_64 - http://handbrake.fr
2 CPUs detected
Opening 1014_20110113131300.mpg...
[23:46:05] hb_scan: path=1014_20110113131300.mpg, title_index=1
libbluray/bdnav/index_parse.c:157: indx_parse(): error opening 1014_20110113131300.mpg/BDMV/index.bdmv
libbluray/bluray.c:960: nav_get_title_list(1014_20110113131300.mpg) failed (0x2c99be0)
[23:46:05] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Using libdvdcss version 1.2.10 for DVD access
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[23:46:05] dvd: not a dvd - trying as a stream/file instead
[23:46:05] file is MPEG Transport Stream with 188 byte packets offset 0 bytes
[23:46:05] hb_ts_stream_find_pids - found the following PIDS
[23:46:05]     Video PIDS :
[23:46:05]       0x840 type MPEG2 (0x2)
[23:46:05]     Audio PIDS :
[23:46:05]       0x841 type AC-3 (0x81)
[23:46:05]       0x842 type AC-3 (0x81)
[23:46:05] transport stream pid 0x841 (type 0x81) may be AC-3 audio (id 0x841)
[23:46:05] transport stream pid 0x842 (type 0x81) may be AC-3 audio (id 0x842)
[23:46:05] scan: decoding previews for title 1
[23:46:05] scan: audio 0x841: AC-3, rate=48000Hz, bitrate=384000 English (AC3) (5.1 ch)
[23:46:05] scan: audio 0x842: AC-3, rate=48000Hz, bitrate=384000 Espanol (AC3) (2.0 ch)
Scanning title 1...
[23:46:06] scan: 10 previews, 1920x1088, 29.970 fps, autocrop = 0/8/0/0, aspect 1.76:1, PAR 1:1
[23:46:06] scan: title (0) job->width:1920, job->height:1072
[23:46:06] stream: 6 good frames, 0 errors (0%)
[23:46:06] libhb: scan thread found 1 valid title(s)
+ title 1:
  + stream: 1014_20110113131300.mpg
  + duration: 00:04:53
  + size: 1920x1088, pixel aspect: 1/1, display aspect: 1.76, 29.970 fps
  + autocrop: 0/8/0/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:04:53
  + audio tracks:
    + 1, English (AC3) (5.1 ch) (iso639-2: eng), 48000Hz, 384000bps
    + 2, Espanol (AC3) (2.0 ch) (iso639-2: spa), 48000Hz, 384000bps
  + subtitle tracks:
    + 1, Closed Captions (iso639-2: eng) (Text)(CC)
+ Using preset: High ProfileModified x264 options for pass 1 to append turbo options: ref=8:deblock=-1,-1:psy-rd=1:ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0
[23:46:06] 2 job(s) to process
[23:46:06] starting job
[23:46:06] sync: expecting 8839 video frames
[23:46:06] work: only 1 chapter, disabling chapter markers
[23:46:06] job configuration:
[23:46:06]  * source
[23:46:06]    + 1014_20110113131300.mpg
[23:46:06]    + title 1, chapter(s) 1 to 1
[23:46:06]  * destination
[23:46:06]    + /var/lib/mythtv/videos/Web-Web-Test-7.mp4
[23:46:06]    + container: MPEG-4 (.mp4 and .m4v)
[23:46:06]      + optimized for progressive web downloads
[23:46:06]  * video track
[23:46:06]    + decoder: mpeg2
[23:46:06]      + bitrate 25000 kbps
[23:46:06]    + frame rate: same as source (around 29.970 fps)
[23:46:06]    + loose anamorphic
[23:46:06]      + storage dimensions: 1920 * 1088 -> 960 * 544, crop 0/8/0/0, mod 0
[23:46:06]      + pixel aspect ratio: 136 / 135
[23:46:06]      + display dimensions: 967 * 544
[23:46:06]    + filters
[23:46:06]      + Detelecine (pullup) (default settings)
[23:46:06]      + Decomb (default settings)
[23:46:06]    + encoder: x264
[23:46:06]      + options: ref=8:deblock=-1,-1:psy-rd=1:ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0
[23:46:06]      + bitrate: 1500 kbps, pass: 1
[23:46:06]  * audio track 0
[23:46:06]    + decoder: English (AC3) (5.1 ch) (track 1, id 841)
[23:46:06]      + bitrate: 384 kbps, samplerate: 48000 Hz
[23:46:06]    + mixdown: 6-channel discrete
[23:46:06]    + encoder: faac
[23:46:06]      + bitrate: 192 kbps, samplerate: 48000 Hz
[23:46:06] reader: first SCR 3906904682 id 2112 DTS 3906932046
[23:46:06] encx264: min-keyint: auto (29), keyint: 300
[23:46:06] encx264: encoding with stored aspect 136/135
x264 [info]: using SAR=136/135
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[23:46:06] decomb thread started for segment 1
[23:46:06] yadif thread started for segment 1
[23:46:06] decomb thread started for segment 0
[23:46:06] yadif thread started for segment 0
[23:46:06] mpeg2: "" (1) at frame 0 time 21021
x264 [info]: profile Main, level 3.1
No accelerated IMDCT transform found
[23:46:06] sync: first pts is 21021
Deleted User 11865

Re: Help with x264 options

Post by Deleted User 11865 »

Kebast wrote:

Code: Select all

[23:46:06]      + options: ref=8:deblock=-1,-1:psy-rd=1:ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0
It's not working properly. Options following the pipe character are gone (the other options are the Turbo first pass options).
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Re: Help with x264 options

Post by Kebast »

So do you think this is a new bug, or a recent change? I just checked my other scripts that were working, and they do not now. I changed all back to a comma instead of the pipe and all is well. I'm using svn 3743.
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Re: Help with x264 options

Post by Kebast »

Forgot one important (maybe) factor. Previous to finding this problem, I was calling the script that had the pipe (psy-rd=1|0.15) from within MythTV. That might be why it works for me there, and not if I just run the script from the command line.
Deleted User 11865

Re: Help with x264 options

Post by Deleted User 11865 »

Kebast wrote:Forgot one important (maybe) factor. Previous to finding this problem, I was calling the script that had the pipe (psy-rd=1|0.15) from within MythTV. That might be why it works for me there, and not if I just run the script from the command line.
Of course it is. MythTV != command line shell. It's the shell that's interpreting the pipe character before HandBrake.

Also, it's not an issue per se. That's how it's supposed to work (command line interpreting the pipe character first is normal behavior). You need to either use another character, or escape the pipe character.
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Re: Help with x264 options

Post by Kebast »

Ah, I understand. Comma works for me, so I changed all my scripts back to psy-rd=1,0.15. Linux is still somewhat new to me, so my coding knowledge is limited. Just to make sure I'm getting the picture, this would work under any usage?

Code: Select all

psy-rd=1\|0.15
Thanks for all your help!
TedJ
Veteran User
Posts: 5388
Joined: Wed Feb 20, 2008 11:25 pm

Re: Help with x264 options

Post by TedJ »

That might cause an issue in your script, but is a common way of escaping the pipe character from the command line.
tlindgren
Bright Spark User
Posts: 260
Joined: Sun May 03, 2009 2:14 pm

Re: Help with x264 options

Post by tlindgren »

Kebast wrote:Ah, I understand. Comma works for me, so I changed all my scripts back to psy-rd=1,0.15. Linux is still somewhat new to me, so my coding knowledge is limited. Just to make sure I'm getting the picture, this would work under any usage?

Code: Select all

psy-rd=1\|0.15
Thanks for all your help!
I presume x264 won't like additional escape characters which means that you need to get exactly the right amount of escaping and that depends on the context.

It's possible that what you're doing is simple enough that it'll always work but we don't have enough information to be able to tell and even if it is it could change later (obvious example, if you run it distributed to additional machine you may or may NOT need to use \\\| instead of it to work, it depends on exactly how you get to the other machines!).

Unless you know exactly what you're doing, use psy-rd=1,0.15 and avoid the following characters in scripting unless they're used for specific purposes: |"\'?`()#$![]<>:,;
Even experts can sometimes get caught out by this so I really don't recommend voluntarily choosing to complicate the script that way.
Kebast
Posts: 33
Joined: Wed Jul 28, 2010 2:44 pm

Re: Help with x264 options

Post by Kebast »

Thanks for the explanation!
Post Reply