[mythtv-users] FFMPeg Commercial cutting puts audio out of sync
Justin Alcorn
justin at jalcorn.net
Sun Sep 14 05:14:45 UTC 2014
One last update. In case the video does not start with a cut, you'll
want to add this after the CUTLIST:
if [[ $CUTLIST =~ ^0, ]];then
CUTLIST=`echo $CUTLIST | sed 's/^0,//'`
AWKCMD='NR%2==1'
else
AWKCMD='NR%2!=1'
fi
and change the awk to
awk $AWKCMD
--
Justin B. Alcorn
PGP Fingerprint A36D D691 C5B0 BE15 5A2A AF49 AA1C 372C
On Sun, Sep 14, 2014 at 12:21 AM, Justin Alcorn <justin at jalcorn.net> wrote:
> On Sat, Sep 13, 2014 at 10:19 PM, Justin Alcorn <justin at jalcorn.net> wrote:
>> That's exactly what I was thinking. Thanks for the example.
>
>
> Thanks for all the help. This works perfectly to losslessly cut the
> H.264 Encoded recording, and put it in a mp4 container for mythroku.
> It also takes just seconds on a medium powered machine.
>
> Run as UserJob /usr/local/bin/rokuencode.sh %DIR% %FILE%
> =================================================
> #!/bin/bash
>
> logfile=/home/mythtv/save/$$.log
> # Close STDOUT file descriptor
> exec 1<&-
> # Close STDERR FD
> exec 2<&-
>
> # Open STDOUT as $LOG_FILE file for read and write.
> exec 1<>$logfile
>
> # Redirect STDERR to STDOUT
> exec 2>&1
>
> INPUTFILE="${1}/${2}"
>
> workdir="/tmp/$$"
> mkdir -p ${workdir}
>
> if [ ! -f $INPUTFILE ]; then
> echo "file doesn't exist, aborting."
> exit 1
> fi
>
> #see if we have the DB info
> test -f /etc/mythtv/mysql.txt && . /etc/mythtv/mysql.txt
> test -f ~/.mythtv/mysql.txt && . ~/.mythtv/mysql.txt
>
> #let's make sure we have a sane environment
> if [ -z "`which ffmpeg`" ]; then
> echo "FFMpeg not present in the path. Adjust environment or install ffmpeg"
> exit 1
> fi
>
> mysqlconnect="mysql -N -hlocalhost -umythtv -ppassword mythconverg"
> export mysqlconnect
>
> #deteremine directory and filename
> RECDIR=`dirname $INPUTFILE`
> BASENAME=`basename $INPUTFILE`
> tmp=`basename $BASENAME .mpg`
>
> chanid=`echo "select chanid from recorded where
> basename=\"$BASENAME\";" | $mysqlconnect`
> starttime=`echo "select starttime from recorded where
> basename=\"$BASENAME\";" | $mysqlconnect`
> if [ -z "$chanid" -o -z "$starttime" ];then
> echo "Info not found for select chanid from recorded where
> basename=\"$BASENAME\""
> exit 1;
> fi
>
> #lets make sure we have a cutlist before we proceed
> if [ -z "`mythutil --getcutlist --chanid $chanid --starttime
> "$starttime" | grep Cutlist | sed 's/Cutlist: $//'`" ]; then
> echo "no cutlist found....generating new cutlist"
> mythutil --chanid $chanid --starttime "$starttime" --gencutlist
> #&>${logfile}
> fi
>
> CUTLIST=`mythutil --chanid $chanid --starttime "$starttime"
> --getcutlist | grep Cutlist | sed 's/Cutlist: //' | sed 's/-/,/g' |
> sed 's/^0,//'`
>
> echo $CUTLIST
>
> echo "ffmpeg -i ${RECDIR}/${BASENAME} -map 0 -c copy -f ssegment
> -segment_list ${workdir}/out.ffconcat -segment_frames $CUTLIST
> ${workdir}/out%03d.mp4"
> ffmpeg -i ${RECDIR}/${BASENAME} -map 0 -c copy -f ssegment
> -segment_list ${workdir}/out.ffconcat -segment_frames $CUTLIST
> ${workdir}/out%03d.mp4
> cat ${workdir}/out.ffconcat | awk 'NR%2==1' > ${workdir}/in.ffconcat
> echo "ffmpeg -f concat -i ${workdir}/in.ffconcat -c copy ${RECDIR}/${tmp}.mp4"
> ffmpeg -y -f concat -safe 0 -i ${workdir}/in.ffconcat -c copy
> ${RECDIR}/${tmp}.mp4
>
> #well need a new filesize to update the db with
> filesize=$(du -b ${RECDIR}/${tmp}.mp4 | awk '{print $1}')
>
> #update db with new filesize and filename
> cat <<EOF | $mysqlconnect
> UPDATE
> recorded
> SET
> filesize = ${filesize},
> cutlist = 0,
> basename = "${tmp}.mp4"
> WHERE
> chanid = ${chanid} AND
> starttime = "${starttime}";
> EOF
>
> #delete the old commercial skip info
> cat <<EOF | $mysqlconnect
> DELETE FROM
> recordedmarkup
> WHERE
> chanid = ${chanid} AND
> starttime = "${starttime}" AND
> (type = 4 OR type = 5);
> EOF
>
> cat <<EOF | $mysqlconnect
> DELETE FROM
> recordedseek
> WHERE
> chanid = ${chanid} AND
> starttime = "${starttime}";
>
> EOF
>
> #cleanup $workdir
> rm -rf ${workdir}/*${tmp}*
> =========================================================================
> --
> Justin B. Alcorn
> PGP Fingerprint A36D D691 C5B0 BE15 5A2A AF49 AA1C 372C
More information about the mythtv-users
mailing list