[mythtv-users] Encoding to h264 to save space

Marc drayson at net1plus.com
Tue Feb 19 12:49:52 UTC 2008


I cannot get this script to work. There must be a line feed somewhere in my
copy that shouldn't be.

Chris, can you email it to me as an attachment?

 

Marc

 

From: mythtv-users-bounces at mythtv.org
[mailto:mythtv-users-bounces at mythtv.org] On Behalf Of Chris Isip
Sent: Monday, February 18, 2008 9:30 PM
To: Discussion about mythtv
Subject: [mythtv-users] Encoding to h264 to save space

 

I am able to shrink 1 hour of video to approximately 150 MB at 200 kbit with
ffmpeg using h264.  Seems to work well except with seeking.  I wonder if
this is a keyframe issue.  When I forward or rewind, there is distortion for
a few seconds and then the video fixes itself.  If I forward or rewind
before the video is fixed, the progress bar seems to jump back.  Seeking is
more reliable when the distrotion is allowed to clear first.  Also, I cannot
jump to the very first frame of the recording.  If I exit the recording and
play it again, I start on the first frame.  Here is a copy of my latest
script.  Single pass for now (hoping to go to 2 pass).  I was wondering if
anyone could give me any ideas as to how to fix this issue. 

Thanks
Chris


#!/bin/bash
VIDEO_DIR=/mnt/VIDEO

#subq to 7 trellis to 2 threads 2
#need to clear the cutlist and generate it again




function convert-to-h264 ()
{
#argument is file only (no path)
#need to dereference a symlink
inputfile=`ls -ld $VIDEO_DIR/$1 | awk -F" " '{ print  $NF }'`

echo "Will encode $inputfile"
basedname=`echo $inputfile | sed 's,^\(.*/\)\?\([^/]*\),\2,'`
vidformat=`mplayer -vo null -ao null -frames 0 -identify "$inputfile"
2>/dev/null | grep "ID_VIDEO_FORMAT" | sed -e 's/ID_VIDEO_FORMAT=//'`



if !  [ "$vidformat" == "H264" ]; then
/usr/bin/ffmpeg -threads 2 -i  $inputfile  -acodec mp3 -ac 2 -ar 44100 -ab
128k -s 320x240 -vcodec h264 -sameq  -flags +loop -cmp +chroma -partitions
+parti4x4+partp8x8+partb8x8 -me umh -subq 7 -trellis 2 -refs 1 -coder 0
-me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 300k
-maxrate 300k -bufsize 300k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 15
-qmax 51 -qdiff 4 -level 30 -aspect 320:240  $inputfile.avi


mv $inputfile $inputfile.old
mv $inputfile.avi $inputfile


echo "Building seek table"
mythcommflag --rebuild -f "$inputfile"

echo "Clearing the cut list"
mythcommflag --clearcutlist -f $inputfile

echo "Commercial skip to cutlist"
mythcommflag --gencutlist -f $inputfile

filesize=$(wc -c $inputfile | awk '{print $1}')
echo "Updating database"
mysql -umythtv -pmythtv -hmymythtv mythconverg -se"UPDATE recorded SET
cutlist=0,filesize=$filesize WHERE basename=\"$basedname\";"
else
echo "Already an H264"

fi
}


CONVLIST=`mysql -umythtv -pmythtv -hmymythtv mythconverg -se"select basename
from recorded where title like \"%$1%\";"`

for i in ${CONVLIST[@]} ; do
  if ! test -L $VIDEO_DIR/$i ; then #its not a symnlink
     #Check if this recording is done -mmin +5
     filetoconvert=`find $VIDEO_DIR -name $i -mmin +5 | sed
's,^\(.*/\)\?\([^/]*\),\2,'`
     if [ -z "$filetoconvert" ]; then
        echo "$i is not finnished recording...Skipping"
     else
        echo "Moving $i to /mnt/VIDEO1"
        mv $VIDEO_DIR/$i /mnt/VIDEO1
        ln -sf /mnt/VIDEO1/$i $VIDEO_DIR/$i
        convert-to-h264 $i
     fi
  else
     echo "$i is already a symlink...Skipping"
     convert-to-h264 $i
  fi




done
  [root at mygamepc cmisip]# cat /usr/local/bin/RECconv2.sh
#!/bin/bash
VIDEO_DIR=/mnt/VIDEO

#subq to 7 trellis to 2 threads 2
#need to clear the cutlist and generate it again




function convert-to-h264 ()
{
#argument is file only (no path)
#need to dereference a symlink
inputfile=`ls -ld $VIDEO_DIR/$1 | awk -F" " '{ print  $NF }'`

echo "Will encode $inputfile"
basedname=`echo $inputfile | sed 's,^\(.*/\)\?\([^/]*\),\2,'`
vidformat=`mplayer -vo null -ao null -frames 0 -identify "$inputfile"
2>/dev/null | grep "ID_VIDEO_FORMAT" | sed -e 's/ID_VIDEO_FORMAT=//'`



if !  [ "$vidformat" == "H264" ]; then
/usr/bin/ffmpeg -threads 2 -i  $inputfile  -acodec mp3 -ac 2 -ar 44100 -ab
128k -s 320x240 -vcodec h264 -sameq  -flags +loop -cmp +chroma -partitions
+parti4x4+partp8x8+partb8x8 -me umh -subq 7 -trellis 2 -refs 1 -coder 0
-me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 300k
-maxrate 300k -bufsize 300k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 15
-qmax 51 -qdiff 4 -level 30 -aspect 320:240  $inputfile.avi


mv $inputfile $inputfile.old
mv $inputfile.avi $inputfile


echo "Building seek table"
mythcommflag --rebuild -f "$inputfile"

echo "Clearing the cut list"
mythcommflag --clearcutlist -f $inputfile

echo "Commercial skip to cutlist"
mythcommflag --gencutlist -f $inputfile

filesize=$(wc -c $inputfile | awk '{print $1}')
echo "Updating database"
mysql -umythtv -pmythtv -hmymythtv mythconverg -se"UPDATE recorded SET
cutlist=0,filesize=$filesize WHERE basename=\"$basedname\";"
else
echo "Already an H264"

fi
}


CONVLIST=`mysql -umythtv -pmythtv -hmymythtv mythconverg -se"select basename
from recorded where title like \"%$1%\";"`

for i in ${CONVLIST[@]} ; do
  if ! test -L $VIDEO_DIR/$i ; then #its not a symnlink
     #Check if this recording is done -mmin +5
     filetoconvert=`find $VIDEO_DIR -name $i -mmin +5 | sed
's,^\(.*/\)\?\([^/]*\),\2,'`
     if [ -z "$filetoconvert" ]; then
        echo "$i is not finnished recording...Skipping"
     else
        echo "Moving $i to /mnt/VIDEO1"
        mv $VIDEO_DIR/$i /mnt/VIDEO1
        ln -sf /mnt/VIDEO1/$i $VIDEO_DIR/$i
        convert-to-h264 $i
     fi
  else
     echo "$i is already a symlink...Skipping"
     convert-to-h264 $i
  fi




done

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mythtv.org/pipermail/mythtv-users/attachments/20080219/4e6e3149/attachment.htm 


More information about the mythtv-users mailing list