Encoding to h264/aac mp4 for N8x0 with Linux

Updated script available since 02.08.2008!

I tried a while and searched through internettablettalk forums but now I have a solution for converting almost any video source to h264/aac mp4 playable with n8x0s default Media Player (OS2008) using linux tools. I have written a little script to make it easier to convert stuff for the Tablet.

Necessary Tools

These are the tools used:

  • mplayer
  • faac
  • x264
  • mp4creator

The Script

save this code into a file, e.g. n800-encode.sh and make it executable (do chmod +x n800-encode.sh on a shell).
You can also download the script here: n800-encode_02082008.zip



  mplayer -identify -ao null -vo null -endpos 2 ${_MPOPTS} "${_INFILE}" | grep ID_ > /tmp/n800-encode.$$.ident
  FPS=$(cat /tmp/n800-encode.$$.ident | grep ID_VIDEO_FPS | uniq | cut -d '=' -f 2)
  ASPECT=$(cat /tmp/n800-encode.$$.ident | grep ID_VIDEO_ASPECT | tail -n 1 | cut -d '=' -f 2 | cut -d ' ' -f 2)

  WS=`expr $ASPECT \> 1.6 \& $ASPECT \< 1.9`
  if [[ `expr $ASPECT \> 2.0` -eq 1 ]]

  case ${WS} in
    0) SCALE="320:240"
      echo "encoding for standard"
    1) SCALE="400:224"
      echo "encoding for widescreen"
    2) SCALE="400:192"
      echo "encoding for extra-widescreen"

  x264 -o "$PWD/n800-encode.$$/video.264" "$PWD/n800-encode.$$/video.y4m" --threads 3 --no-cabac --bitrate 250 -A i4x4,p4x4,p8x8,b8x8 --level 1.2 >/dev/null 2>/dev/null &
  faac -b 96 --mpeg-vers 4 -o "$PWD/n800-encode.$$/audio.aac" "$PWD/n800-encode.$$/audio.wav" 2>/dev/null >/dev/null&
  sleep 1
  mplayer -vf scale=${SCALE},unsharp=c4x4:0.3:l5x5:0.5 -ao pcm:file="$PWD/n800-encode.$$/audio.wav" -vo yuv4mpeg:file="$PWD/n800-encode.$$/video.y4m" -ass -embeddedfonts -noframedrop ${_MPOPTS} "${_INFILE}"
  rm -f "${_OUTFILE}"

  mp4creator -create "$PWD/n800-encode.$$/audio.aac" "${_OUTFILE}"
  mp4creator -create "$PWD/n800-encode.$$/video.264" -r ${FPS} "${_OUTFILE}"

  mkdir -p "$PWD/n800-encode.$$"
  mkfifo "$PWD/n800-encode.$$/video.y4m"
  mkfifo "$PWD/n800-encode.$$/audio.wav"

  rm -Rf "$PWD/n800-encode.$$"
  rm -f /tmp/n800-encode.$$.ident

trap cleanupTemp SIGINT SIGTERM


Using it

Usage is simple, The script accepts 3 options: first the input, second the output and third any additional options for mplayer. Some examples:

  • encode test.avi into test.mp4:
n800-encode.sh test.avi test.mp4
  • encode test.avi into test.mp4 telling mplayer to render the first subtitle track and the second audio track:
n800-encode.sh test.avi test.mp4 "-sid 0 -aid 1"

Note: all options for mplayer have to be enclosed into one pair of “

n800/mp4encoding.txt · Last modified: 28.09.2010 16:12 by Seiichiro
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Hosted by Linode Recent changes RSS feed Valid XHTML 1.0