Video encoding

Mencoder

  • this command encodes a directory of mpg to divx avis - audio encoded to mp3s.
ls  *.mpg | xargs  -I {}  mencoder -oac mp3lame -ovc lavc -lavcopts  vcodec=mpeg4:vbitrate=1000:mbd=2:v4mv:autoaspect {} -o {}.avi
  • this skips the audio track - useful for saving space on video only files.
ls  *.mpg | xargs  -I {}  mencoder -nosound -ovc lavc -lavcopts  vcodec=mpeg4:vbitrate=1000:mbd=2:v4mv:autoaspect {} -o {}.avi

Bitrate of 1000 is ok for 400x300 videos but for 640x480 or 720x480 bitrate of 2000 is better (Video quality isnt good at 1000 for these).

  • to generate a list of file videos filenames with fullpath in a directory use:-
ls -1 * | xargs -I {} echo \"`pwd`/{}\",
  • to rotate a video
-vf rotate=1  <-- right
-vf rotate=2  <-- left

Encoding for android / iphone

The following script andenc.sh can be used to encode videos for android - not sure if it is the same for iphone but i guess it should be. the example is from the android mailing list here
Usgae is

andenc.sh [low|high] input.video

#!/bin/bash

# filename=andvidenc

#USAGE:
#  andvidenc low "input.video"
#  andvidenc high "input.video"
#
#   --output: "input.video.mp4"
#
# Note 1: if input video is INTERLACED, add "kerndeint" to -vf,
# i.e. ... -vf kerndeint,dsize....
#
# Note 2: if 2-pass encoding is not desired, comment out the FIRST mencoder line
# from each case and remove "-passlogfile "$2.log"" and ":pass=2" from remaining
# mencoder lines.
#
# Note 3: for testing purposes, I have verified that HTC dream is able to play high
# bitrate files without trouble. Tested with bitrate up to 1024.  Visual difference
# between 512 and 1024 is minimal. Up to you to choose a bitrate that balances
# quality with size.

# yes, this script is really stupid and has a lot of room for enhancement. Feel free
# to improve it.

#EITHER:

if [ $1 = "low" ]; then
        mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -passlogfile "$2.log" -x264encopts nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:turbo=1:pass=1
        mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -passlogfile "$2.log" -x264encopts nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:pass=2


#OR:

else
        mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -passlogfile "$2.log" -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:turbo=1:pass=1:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
        mencoder "$2" -o "$2.tmp.mp4" -vf dsize=480:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -passlogfile "$2.log" -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:pass=2:global_header:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh
fi

#THEN:

ffmpeg -i "$2.tmp.mp4" -vcodec copy -acodec copy "$2.mp4"
rm -f "$2.tmp.mp4" "$2.log"

FFmpeg - encoding flash videos to MPEG

There is a problem with the standard ubuntu (8.10) ffmpeg when encoding flvs, we have to compile from source

cd ==compile_dir==
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure && make
Then encode with:
ls  *.flv | xargs  -I {} ==compile_dir==/ffmpeg/ffmpeg -i {} -ab 56 -ar 22050 -b 1200 -s 640x480 {}.mpg

Strip audio with mencoder

For some reason the pcm outout doesnt play mp3lame works for me though. not the start(ss) and endpos params

mencoder -o bingos.mp3 -oac mp3lame bingo.avi -ovc copy -of rawaudio -ss 00:00:00 -endpos 00:03:46
this fixes the wave hedaer as can be corrupt from mencoder
mplayer  -quiet  -vo null  -vc dummy  -ao pcm:waveheader:file="/home/robm/bings.wav" "/mnt/sda6/robm/patch/OpenNight15Apr10/bingos.wav"

MPEG For GEM and Table of contents

For GEM MPEG-1 files play the best by far - need to generate toc for the mpeg files to index them. this is done with mpeg3toc which is part of cinnerella? or mpeg3io? not sure

ffmpeg -i bingo.avi -target vcd bingo2.mpg -t 50 -ss 00:03:46
mpeg3toc /mnt/sda6/robm/patch/OpenNight15Apr10/bingo1.mpg /mnt/sda6/robm/patch/OpenNight15Apr10/bingo1.mpgt


This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 1.6.1.13621 - Documentation