transcode 1080p --> 480p

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

transcode 1080p --> 480p

Post by graysky »

Can someone please check my proposed cli to transcode a bunch of 1080p --> 480p?

Code: Select all

HandBrakeCLI -i input.mov -o transcoded-480p.mkv -e x264 -q 22 bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct=0:me=umh:direct=temporal:trellis=0:b-adapt=2 --aencoder faac -B 96 -Y 480 --loose-anamorphic
Suggestions are welcomed.
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

direct=temporal is a bad idea. For most sources, direct=spatial is better 90% of the time. Set it to spatial or auto.

Unless your device only supports Main Profile, disabling 8x8dct is a bad idea (having it enabled has a fairly low speed cost, but improves compression efficiency a lot).

faac is not a very good encoder; 96 Kbps might sound like crap, especially for "difficult" sources.
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

Rodeo wrote:direct=temporal is a bad idea. For most sources, direct=spatial is better 90% of the time. Set it to spatial or auto.

Unless your device only supports Main Profile, disabling 8x8dct is a bad idea (having it enabled has a fairly low speed cost, but improves compression efficiency a lot).

faac is not a very good encoder; 96 Kbps might sound like crap, especially for "difficult" sources.
Thanks for the advice. Playback is not for any specific device -- for these sources, 1920x1080 is just overkill. Which audio codec would you recommend?
Last edited by graysky on Fri Dec 16, 2011 12:07 pm, edited 1 time in total.
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

ca_aac is a much better AAC encoder (but only available under OS X). Otherwise there's lame (MP3) - hopefully anything that plays MKV should also support MP3 decoding, and vorbis (also a good encoder, but less compatible).
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

Thanks again for the suggestion. Think I'll go with vorbis. Any other modifications you would recommended?

Code: Select all

HandBrakeCLI -i "$input" -o "$out".mkv -e x264 -q 21 bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct:me=umh:direct=spatial:trellis=0:b-adapt=2 -Y 480 --loose-anamorphic -E vorbis -Q 0.2
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

I've been happily using this line to transcode 1080p stuff down to 480p but recently, the code fails to keep the source aspect ratio and goes all 2.35:1 on me. What am I doing wrong?

Code: Select all

HandBrakeCLI -i "$input" -o "$out".mkv -e x264 -q 21 bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct:me=umh:direct=spatial:trellis=0:b-adapt=2 -Y 480 --loose-anamorphic -E vorbis -Q 0.2
Source video:

Code: Select all

Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Transcoded video:

Code: Select all

Width                                    : 1 120 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 2.35:1
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

Activity Log?
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

Rodeo wrote:Activity Log?
Ack... assumed it was my error with the switches, not with the HB so I omitted it. :oops:
Attached here for your kind review:

Code: Select all

[17:46:12] hb_init: starting libhb thread
HandBrake svn4428 (2012013101) - Linux x86_64 - http://handbrake.fr
4 CPUs detected
Opening 20120131.mov...
[17:46:12] hb_scan: path=20120131.mov, title_index=1
libbluray/bdnav/index_parse.c:157: indx_parse(): error opening 20120131.mov/BDMV/index.bdmv
libbluray/bluray.c:1471: nav_get_title_list(20120131.mov) failed (0x7f6e98000900)
[17:46:12] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Using libdvdcss version 1.2.11 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
[17:46:12] dvd: not a dvd - trying as a stream/file instead
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20120131.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-01-27 21:42:44
  Duration: 00:08:26.64, start: 0.000000, bitrate: 8758 kb/s
    Stream #0.0(eng): Audio: aac, 48000 Hz, stereo, s16, 114 kb/s
    Metadata:
      creation_time   : 2012-01-27 21:42:44
    Stream #0.1(eng): Video: h264 (Main), yuv420p, 1920x1080, 8639 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc
    Metadata:
      creation_time   : 2012-01-27 21:42:44
[17:46:12] scan: decoding previews for title 1
[17:46:12] scan: 10 previews, 1920x1080, 23.976 fps, autocrop = 130/130/0/0, aspect 16:9, PAR 1:1
[17:46:12] scan: title (0) job->width:1920, job->height:816
Scanning title 1...
[17:46:12] libhb: scan thread found 1 valid title(s)
+ title 1:
  + stream: 20120131.mov
  + duration: 00:08:26
  + size: 1920x1080, pixel aspect: 1/1, display aspect: 1.78, 23.976 fps
  + autocrop: 130/130/0/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:08:26
  + audio tracks:
    + 1, English (aac) (2.0 ch) (iso639-2: eng)
  + subtitle tracks:
[17:46:13] 1 job(s) to process
[17:46:13] starting job
[17:46:13] work: mixdown not specified, track 1 setting mixdown Stereo
[17:46:13] sync: expecting 12171 video frames
[17:46:13] job configuration:
[17:46:13]  * source
[17:46:13]    + 20120131.mov
[17:46:13]    + title 1, chapter(s) 1 to 1
[17:46:13]    + container: mov,mp4,m4a,3gp,3g2,mj2
[17:46:13]    + data rate: 8758 kbps
[17:46:13]  * destination
[17:46:13]    + 20120131.mkv
[17:46:13]    + container: Matroska (.mkv)
[17:46:13]  * video track
[17:46:13]    + decoder: h264
[17:46:13]      + bitrate 8639 kbps
[17:46:13]    + frame rate: same as source (around 23.976 fps)
[17:46:13]    + dimensions: 1920 * 1080 -> 1120 * 480, crop 130/130/0/0, mod 0
[17:46:13]    + encoder: H.264 (x264)
[17:46:13]      + quality: 21.00 (RF)
[17:46:13]  * audio track 1
[17:46:13]    + decoder: English (aac) (2.0 ch) (track 1, id 0x0)
[17:46:13]    + mixdown: Stereo
[17:46:13]    + encoder: Vorbis (vorbis)
[17:46:13]      + quality: 0.20, samplerate: 48000 Hz
[17:46:13] reader: first SCR 0 id 0x0 DTS 0
[17:46:13] encx264: min-keyint: 24, keyint: 240
[17:46:13] encx264: Encoding at constant RF 21.000000
x264 [warning]: --psnr used with psy on: results will be invalid!
x264 [warning]: --tune psnr should be used if attempting to benchmark psnr!
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
x264 [info]: profile High, level 3.1
[17:46:13] encvorbis: opening libvorbis
[17:49:48] reader: done. 1 scr changes
[17:49:49] work: average encoding speed for job is 56.025986 fps
[17:49:49] sync: got 12147 frames, 12171 expected
[17:49:49] h264-decoder done: 12147 frames, 0 decoder errors, 0 drops
[17:49:49] render: lost time: 0 (0 frames)
[17:49:49] render: gained time: 0 (0 frames) (0 not accounted for)
x264 [info]: frame I:91    Avg QP:16.64  size: 28503  PSNR Mean Y:49.93 U:55.07 V:54.63 Avg:50.96 Global:49.71
x264 [info]: frame P:5120  Avg QP:20.58  size:  7473  PSNR Mean Y:46.86 U:52.33 V:51.81 Avg:47.95 Global:47.35
x264 [info]: frame B:6936  Avg QP:23.43  size:  1790  PSNR Mean Y:45.87 U:52.04 V:51.63 Avg:47.08 Global:46.50
x264 [info]: consecutive B-frames: 15.3% 23.7%  6.1% 54.9%
x264 [info]: mb I  I16..4: 24.0% 56.3% 19.7%
x264 [info]: mb P  I16..4:  2.6%  3.8%  0.4%  P16..4: 42.3% 13.3%  6.7%  0.0%  0.0%    skip:30.9%
x264 [info]: mb B  I16..4:  0.1%  0.1%  0.0%  B16..8: 32.9%  2.5%  0.4%  direct: 0.9%  skip:63.0%  L0:38.1% L1:56.4% BI: 5.5%
x264 [info]: 8x8 transform intra:55.5% inter:81.3%
x264 [info]: coded y,uvDC,uvAC intra: 41.4% 54.2% 12.4% inter: 10.9% 15.1% 0.0%
x264 [info]: i16 v,h,dc,p: 36% 19%  7% 38%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 18% 23%  7%  7%  6%  8%  8%  8%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 25% 15%  7%  9%  6% 10%  5%  7%
x264 [info]: i8c dc,h,v,p: 59% 21% 15%  5%
x264 [info]: Weighted P-Frames: Y:5.4% UV:2.3%
x264 [info]: ref P L0: 64.6% 11.0% 17.2%  7.1%  0.0%
x264 [info]: ref B L0: 89.4%  9.1%  1.5%
x264 [info]: ref B L1: 96.4%  3.6%
x264 [info]: SSIM Mean Y:0.9883103 (19.322db)
x264 [info]: PSNR Mean Y:46.318 U:52.185 V:51.728 Avg:47.475 Global:46.858 kb/s:841.16
[17:49:49] aac-decoder done: 0 frames, 0 decoder errors, 0 drops
[17:49:49] mux: track 0, 12147 frames, 53266379 bytes, 841.11 kbps, fifo 4096
[17:49:49] mux: track 1, 27267 frames, 4856812 bytes, 76.69 kbps, fifo 8192
[17:49:49] libhb: work result = 0

Encode done!
HandBrake has exited.
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

Actually:
graysky wrote:

Code: Select all

HandBrakeCLI -i "$input" -o "$out".mkv -e x264 -q 21 bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct:me=umh:direct=spatial:trellis=0:b-adapt=2 -Y 480 --loose-anamorphic -E vorbis -Q 0.2
Where's your -x (--encopts)? Advanced encoder options are the arguments to a CLI option.

Your log doesn't match your command - it doesn't use Loose anamorphic.

Regarding your issue - your source is ~2.35:1 (after cropping), which explains the output resolution. If you don't want to exceed a certain width, you need to specify a --maxWidth (-X) in addition to your --maxHeight (-Y). Or disable cropping (set it all to zero).

Edit: Vorbis quality now uses the same scale as oggenc (-2.0 to 10.0, instead of -0.2 to 1.0). So -Q 0.2 is the same as -Q 0.02 when the option was first introduced in HandBrake.

https://trac.handbrake.fr/changeset/4385
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

@Rodeo - I used a wrapper script for the encoding, but I don't think that should affect it? Anyway, thanks for the explanation. Makes sense!

Code: Select all

#!/bin/bash
doit() {
  HandBrakeCLI -i "$input" -o "$out".mkv -e x264 -q 21 bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct:me=umh:direct=spatial:trellis=0:b-adapt=2 -Y 480 --loose-anamorphic -E vorbis -Q 2.0 2> log.txt
}

timeit() {
  tn="$(date +%s)"
  telapsed="$(expr $tn - $tzero)"
  tremainder="$(expr $telapsed % 3600)"
  thours="$(expr $(expr $telapsed - $tremainder) / 3600)"
  tseconds="$(expr $tremainder % 60)"
  tminutes="$(expr $(expr $tremainder - $tseconds) / 60)"
  echo "$out.mkv encoded in $(date -d $thours:$tminutes:$tseconds +%H:%M:%S)"
  echo "$out.mkv encoded in $(date -d $thours:$tminutes:$tseconds +%H:%M:%S)" >> /scratch/transcode.txt
}

testit() {
  echo "$input" && sleep 1s
}

here="$(pwd)"
for input in *.{avi,mov,mp4,wmv}; do
  out="$(echo "$input" | sed 's/.\{4\}$//')"
  if [[ "$out" != "*" ]]; then
    cp "$input" /scratch
    tzero="$(date +%s)"
    #   cd /scratch && testit && timeit
    cd /scratch && doit && timeit
    cd "$here"
  fi
done
Last edited by graysky on Wed Feb 01, 2012 12:23 am, edited 1 time in total.
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

You're still not passing your advanced x264 opts properly :P
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

Rodeo wrote:You're still not passing your advanced x264 opts properly :P
So I need the -x in between like this?

Code: Select all

HandBrakeCLI -i "$input" -o "$out".mkv -e x264 -q 21 -x bframes=2:subme=6:mixed-refs=0:weightb=0:ref=5:8x8dct:me=umh:direct=spatial:trellis=0:b-adapt=2 -Y 480 --loose-anamorphic -E vorbis -Q 2.0 2> log.txt
Deleted User 11865

Re: transcode 1080p --> 480p

Post by Deleted User 11865 »

Yes.
graysky
Experienced
Posts: 79
Joined: Wed Nov 26, 2008 9:55 pm

Re: transcode 1080p --> 480p

Post by graysky »

thx!
Post Reply