User:Jebba/Video

Contents

[edit] Video

[edit] Encoding Video

I had some video which played way too slow on the N900, so I re-encoded with this pile of cruft:

#!/bin/sh

mencoder $1 -oac mp3lame -ovc lavc \
       -lavcopts vcodec=mpeg4:mbd=1:vbitrate=300 -vf scale=352:208 \
       -ffourcc DIVX -o $1-out.avi

Run thusly:

burger-encode ralf.mov

And it will give you "ralf-out.mov.avi"...Uh, I will have the output file get a reasonable name, of course... Works for now. This does not work on the N900 at the moment because the mencoder in the mplayer package is compiled without mp3lame support. Bah.

See also (where I got above from): Manual_video_encoding.

Ok, here's a far better script than the above that I took and slightly modified to work with gpac instead of mp4creator.

#!/bin/bash
# n900-encode
# Encode videos for N900...
#
# On Fedora 12 (rpmfusion.org) needs packages:
# gpac, mplayer, mencoder, x264, faac
# Run thusly:
# n900-encode [in video] [out video] [options]
# Example:
# n900-encode cabezon.mp4 cabezon.avi
#
# Largely taken from:
# http://www.seiichiro0185.org/doku.php/n800:mp4encoding

_INFILE="$1"
_OUTFILE="$2"
_MPOPTS="$3"

identifySource()
{
  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 ]]
  then
    WS=2
  fi
  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"
      ;;
  esac
}

encode()
{
  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}"

  MP4Box -new -add "$PWD/n800-encode.$$/video.264" -add "$PWD/n800-encode.$$/audio.aac" -fps ${FPS} "${_OUTFILE}"
}

prepareTemp()
{
  mkdir -p "$PWD/n800-encode.$$"
  mkfifo "$PWD/n800-encode.$$/video.y4m"
  mkfifo "$PWD/n800-encode.$$/audio.wav"
}

cleanupTemp()
{
  rm -Rf "$PWD/n800-encode.$$"
  rm -f /tmp/n800-encode.$$.ident
}

trap cleanupTemp SIGINT SIGTERM

identifySource
prepareTemp
encode
cleanupTemp

[edit] mplayer

Play video from main "good" back camera:

mplayer tv:// -tv device=/dev/video0

Play video from front camera (next to screen):

mplayer tv:// -tv device=/dev/video1

Note, the front camera looks absolutely terrible like there is far too much gain or something and has a huge band across the right side. I'm hoping this is just a kernel driver issue and it will contain less suck in the future.

More extensive scriptlet:

mplayer \
        -fs \
        -v \
        -nosound \
        -ao null \
        -nojoystick \
        -nolirc \
        -ontop \
        -framedrop \
        -stop-xscreensaver \
        -nocache \
        -noslices \
        -vo xv \
        -tv device=/dev/video0 \
        tv://

The -tv option can take many more options, like:

-tv brightness=50:contrast=50:hue=0:saturation=-0:gain=0:device=/dev/video0

If your camera settings get weird (e.g. like everybody looks like a green monster), just quit mplayer, close the camera and re-open it. The default/stock program will reset it.

[edit] See also

use cam as desktop webcam with gstreamer