Skip to content

Instantly share code, notes, and snippets.

/gist:b17aadc9b3380a6b6f72 Secret
Created Jul 9, 2010

Embed
What would you like to do?
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
BASEDIR=/opt/media/queues
INCOMING="${BASEDIR}/preencode"
ENCODING="${BASEDIR}/working"
OUTGOING="${BASEDIR}/encoded"
COMPLETE="${BASEDIR}/done"
PREPROC="${BASEDIR}/preencode/preprocess"
# Set up our directories if needed
if [ ! -d ${INCOMING} ];then exit;fi
if [ ! -d ${OUTGOING} ];then mkdir -p ${OUTGOING};fi
if [ ! -d ${COMPLETE} ];then mkdir -p ${COMPLETE};fi
if [ ! -d ${ENCODING} ];then mkdir -p ${ENCODING};fi
if [ -f "${ENCODING}/ffmpeg2pass-0.log" ];then echo "another encoder is running"; exit; fi
if [ -f "${ENCODING}/x264_2pass.log.temp" ];then echo "another encoder is running"; exit; fi
# pre-process files that ffmpeg might choke on, but mplayer will play (ogg, some avi)
preproc_count=$(ls -1 "${PREPROC}" 2>/dev/null|wc -l)
if [ ${preproc_count} -gt 0 ];then
for file in `ls -1 "${PREPROC}"`; do
base=$(echo "${file}"|sed -e 's/\.[^\.]*//g');
ext=$(echo "${file}"|sed -e 's/.*\.\([^\.]*\)/\1/g');
PREPROCESSED=0;
FONTFILE='';
FONTLINE='';
if [ -f ${PREPROC}/${base}.srt ];then FONTFILE="${PREPROC}/${base}.srt" ;fi
if [ -f ${PREPROC}/${base}.ssa ];then FONTFILE="${PREPROC}/${base}.ssa" ;fi
if [ ! -z "${FONTFILE}" ];then
FONTLINE="-sub ${FONTFILE} -ffactor 0.5 -fontconfig -font Arial -subfont-text-scale 3 -of lavf"
fi
# Pre-encode to something ffmpeg likes (adding subtitles if necessary)
mencoder -quiet -oac pcm -ovc lavc \
-o "${PREPROC}/${base}_pp.avi" \
"${PREPROC}/${base}.${ext}" ${FONTLINE}
EXIT=$?
if [ "${EXIT}" -eq "0" ];then
if [ -f "${PREPROC}/${base}_pp.avi" ];then
mv "${PREPROC}/${base}.${ext}" "${COMPLETE}"
mv "${PREPROC}/${base}_pp.avi" "${INCOMING}/progressive/${base}.avi"
if [ ! -z "${FONTFILE}" ];then mv "${FONTFILE}" "${COMPLETE}";
FONTFILE='';
FONTLINE='';
fi
fi
fi
done
fi
# Switch to our working dir
cd ${ENCODING}
# Encode all of our progressive files
for f in `ls ${INCOMING}/progressive/*.*`; do
if [ -f ${f} ]; then
o=$(basename ${f});
n=$(echo ${o}|sed -e 's/\.[^\.]*$//g');
/bin/mv "${INCOMING}/progressive/${o}" "${ENCODING}/${o}" && \
/usr/local/bin/ipodenc.h264 ${ENCODING}/${o} ${ENCODING}/${n}.m4v && \
/bin/mv "${ENCODING}/${o}" "${COMPLETE}/${o}" && \
/bin/mv "${ENCODING}/${n}.m4v" "${OUTGOING}/${n}.m4v"
if [ -f "${ENCODING}/${o}.dmp" ]; then /bin/rm "${ENCODING}/${o}.dmp";fi
if [ -f "${ENCODING}/ffmpeg2pass-0.log" ];then /bin/rm ${ENCODING}/ffmpeg2pass-0.log; fi
if [ -f "${ENCODING}/x264_2pass.log" ];then /bin/rm ${ENCODING}/x264_2pass.log ;fi
if [ -f "${ENCODING}/x264_2pass.log.temp" ];then /bin/rm ${ENCODING}/x264_2pass.log.temp ;fi
fi
done
# Encode all of our interlaced files
for f in `ls ${INCOMING}/interlaced/*.*`; do
if [ -f ${f} ]; then
o=$(basename ${f});
n=$(echo ${o}|sed -e 's/\.[^.]*$//g');
/bin/mv "${INCOMING}/interlaced/${o}" "${ENCODING}/${o}" && \
/usr/local/bin/ipodenc.h264.di ${ENCODING}/${o} ${ENCODING}/${n}.m4v && \
/bin/mv "${ENCODING}/${o}" "${COMPLETE}/${o}" && \
/bin/mv "${ENCODING}/${n}.m4v" "${OUTGOING}/${n}.m4v"
if [ -f "${ENCODING}/${o}.dmp" ]; then /bin/rm "${ENCODING}/${o}.dmp";fi
/bin/mv "${ENCODING}/${o}.dmp" "${COMPLETE}/${o}"
if [ -f "${ENCODING}/ffmpeg2pass-0.log" ];then /bin/rm ${ENCODING}/ffmpeg2pass-0.log; fi
if [ -f "${ENCODING}/x264_2pass.log" ];then /bin/rm ${ENCODING}/x264_2pass.log ;fi
if [ -f "${ENCODING}/x264_2pass.log.temp" ];then /bin/rm ${ENCODING}/x264_2pass.log.temp ;fi
fi
done
#!/bin/bash
INFILE=$1
OUTFILE=$2
SELF=$(basename $0)
if [ $SELF == "ipodenc.h264.di" ];then
export DEINTERLACE="-deinterlace"
else
export DEINTERLACE=""
fi
usage(){
echo "$0 <infile> <outfile>"
exit 1;
}
if [ -z "${INFILE}" -o -z "${OUTFILE}" ] ;then usage; fi
ATRACKS=$(/usr/bin/tcprobe -i "${INFILE}"|/bin/grep "audio track"|/usr/bin/wc -l)
ASPECT=$(/usr/bin/tcprobe -i "${INFILE}"|/bin/grep "aspect ratio:"|\
sed -e's/.*ratio: *//' -e 's/ .*//' -e's/:/\//')
SIZE=$(/usr/bin/tcprobe -i "${INFILE}"|grep "import frame size:" | \
sed -e 's/.*-g *//' -e 's/ .*//' -e's/x/:/')
DUMPED=0;
if [ ${ATRACKS} -gt 1 ]; then
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=${SIZE},harddup -srate 48000 -af lavcresample=48000 \
-aid 128 -lavcopts \
vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=${ASPECT} -ofps 30000/1001 -o "${INFILE}.dmp" "${INFILE}"
ORIG_INFILE="${INFILE}"
INFILE="${INFILE}.dmp"
DUMPED=1;
fi
/usr/bin/ffmpeg -y -i "${INFILE}" ${DEINTERLACE} -an -v 1 -threads auto \
-vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 \
-deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 \
-me full -subq 1 -me_range 21 -chroma 1 -slice 2 -bf 0 \
-level 30 -g 300 -keyint_min 30 -sc_threshold 40 \
-rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 \
-qdiff 4 -i_qfactor 0.71428572 -maxrate 768k \
-bufsize 2M -cmp 1 -s 640x480 \
-f mp4 -pass 1 /dev/null
/usr/bin/ffmpeg -y -i "${INFILE}" ${DEINTERLACE} -v 1 -threads auto \
-vcodec h264 -b 500k -bt 175k -refs 1 -loop 1 \
-deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 \
-me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 \
-level 30 -g 300 -keyint_min 30 -sc_threshold 40 \
-rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 \
-qdiff 4 -i_qfactor 0.71428572 -maxrate 768k \
-bufsize 2M -cmp 1 -s 640x480 \
-acodec aac -ab 96 -ar 48000 -ac 2 \
-f mp4 -pass 2 "${OUTFILE}"
sleep 10
/usr/bin/MP4Box -add "${OUTFILE}" "${OUTFILE}.mp4"
/bin/mv "${OUTFILE}.mp4" "${OUTFILE}"
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
if [ ! -d /opt/local/src/FFMPEG ];then mkdir -p /opt/local/src/FFMPEG; fi
cd /opt/local/src/FFMPEG
apt-get update
apt-get install -y liblame-dev libfaad-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev libdts-dev
apt-get build-dep -y ffmpeg
rm -fr ffmpeg-* *.deb
apt-get source -y ffmpeg
cd ffmpeg-*
cat<<EOP | patch -p1
diff -ruN ffmpeg-0.cvs20070307-dist/debian/rules ffmpeg-0.cvs20070307/debian/rules
--- ffmpeg-0.cvs20070307-dist/debian/rules 2008-06-09 08:31:18.000000000 -0500
+++ ffmpeg-0.cvs20070307/debian/rules 2008-06-09 08:35:20.000000000 -0500
@@ -5,8 +5,11 @@
export DEB_BUILD_GNU_TYPE ?= \$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
LIBS = libavutil libavcodec libpostproc libavformat libswscale
-confflags += --enable-gpl --enable-pp --enable-swscaler --enable-pthreads
-confflags += --enable-libvorbis --enable-libtheora --enable-libogg --enable-libgsm
+confflags += --enable-gpl --enable-pp --enable-swscaler
+confflags += --enable-pthreads --enable-libogg --enable-liba52
+confflags += --enable-libdts --enable-dc1394 --enable-libgsm
+confflags += --disable-debug --enable-libmp3lame --enable-libfaad
+confflags += --enable-libfaac --enable-xvid --enable-x264
DEB_VERSION := \$(shell dpkg-parsechangelog | sed -ne 's/^Version: //p')
EOP
debian/rules binary
cd ..
dpkg -i *.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.