Created
October 5, 2014 11:58
-
-
Save a-c-t-i-n-i-u-m/3f539722a80871a62b55 to your computer and use it in GitHub Desktop.
EPGrec + comskip + h.264 encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detect_method=198 | |
min_show_segment_length=125 | |
max_volume=15 | |
min_silence=20 | |
subtitles=0 | |
logo_threshold=0.22 | |
logo_filter=4 | |
volume_slip=30 | |
output_vdr=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... 略 ... | |
// 録画モード(option) | |
$RECORD_MODE = array( | |
0 => array( | |
'name' => 'Full TS', | |
'suffix' => '.ts', | |
), | |
1 => array( | |
'name' => 'Minimum TS', | |
'suffix' => '_tss.ts', | |
), | |
2 => array( | |
'name' => 'AutoEncode: h.264', | |
'suffix' => '.ts', | |
), | |
3 => array( | |
'name' => 'AutoEncode: h.264, comskip', | |
'suffix' => '.ts', | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RECORDER=/usr/local/bin/recpt1 | |
ENCODER=/var/www/epgrec/encoder.sh | |
# fix SID | |
case $CHANNEL in | |
101|102|191|192|193) | |
if [ $SID == "hd" ]; then | |
SID=$CHANNEL | |
fi ;; | |
esac | |
if [ -z $SID ]; then | |
SID="hd" | |
fi | |
# set LNB | |
LNB="" | |
if [ `echo $CHANNEL | grep "CS"` ] || [ $CHANNEL -ge 101 ]; then | |
LNB="--lnb 15" | |
fi | |
# Mode.0 Raw | |
if [ ${MODE} == 0 ]; then | |
$RECORDER --b25 --strip $LNB $CHANNEL $DURATION $OUTPUT > /dev/null 2>&1 | |
# Mode.1 Minimum TS | |
elif [ ${MODE} == 1 ]; then | |
$RECORDER --b25 --strip --sid $SID $LNB $CHANNEL $DURATION $OUTPUT > /dev/null 2>&1 | |
# Mode.n>=2 AutoEncode | |
elif [ ${MODE} -ge 2 ]; then | |
$RECORDER --b25 --strip --sid $SID $LNB $CHANNEL $DURATION $OUTPUT > /dev/null 2>&1 | |
echo "$ENCODER $OUTPUT $MODE" | batch > /dev/null 2>&1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# TS Encoder | |
# usage: | |
# ./encoder.sh INPUT_TS_FILE MODE | |
# | |
time2msec () { | |
read -r h m s ms <<< $(echo $1 | tr '.:' ' ' ) | |
echo $(((h*60*60*1000)+(m*60*1000)+(s*1000)+ms)) | |
} | |
timediff () { | |
start=$(time2msec $1) | |
end=$(time2msec $2) | |
diff=$((end-start)) | |
hour=$((diff/(60*60*1000))) | |
min=$(((diff%(60*60*1000))/(60*1000))) | |
sec=$(((diff%(60*1000))/1000)) | |
ms=$(((diff%(60*1000))%1000)) | |
echo "${hour}:${min}:${sec}.${ms}" | |
} | |
FFMPEG=/usr/bin/ffmpeg | |
FFMPEG_VOPT="-aspect 16:9 -r 30000/1001 -f mp4 -vcodec libx264 -crf 24 -refs 4 -bf 8 -b_strategy 2 -flags +ilme+ildct -top -1 -weightp 0" | |
FFMPEG_AOPT="-bsf:a aac_adtstoasc -acodec aac -strict -2 -ac 2 -ar 48000 -ab 192k" | |
COMSKIP=/usr/local/bin/comskip | |
COMSKIP_INI=comskip.ini | |
# option detect | |
TS=$1 | |
FFMPEG_INPUT=${TS} | |
BASE=${TS%.*} | |
LOG=${BASE}-encode.log | |
MODE=$2 | |
echo "Start: `date`" > ${LOG} | |
# Run Comskip | |
if [ ${MODE} == 3 ]; then | |
echo "Comskip: Enable" >> ${LOG} | |
if [ ! -f ${BASE}.vdr ]; then | |
${COMSKIP} --ini=${COMSKIP_INI} -v 0 -t ${TS} >> ${LOG} 2>&1 | |
fi | |
COMSKIP_TIMES=($(cat ${BASE}.vdr | cut -d " " -f 1)) | |
if [ $(time2msec ${COMSKIP_TIMES[0]}) -gt 60000 ]; then | |
COMSKIP_TIMES=("0:00:00.00" "${COMSKIP_TIMES[@]}") | |
else | |
unset COMSKIP_TIMES[0] | |
TIMES=("${COMSKIP_TIMES[@]}") | |
fi | |
COMSKIP_START=() | |
COMSKIP_END=() | |
COUNT=0 | |
for L in ${COMSKIP_TIMES[@]} | |
do | |
if [ `expr ${COUNT} % 2` -eq 0 ]; then | |
COMSKIP_START+=(${L}) | |
else | |
COMSKIP_END+=(${L}) | |
fi | |
COUNT=$((${COUNT}+1)) | |
done | |
# Split | |
if [ ${COUNT} -ne 0 ]; then | |
_COUNT=`expr ${#COMSKIP_END[@]} - 1` | |
_FILES=() | |
for N in `seq 0 ${_COUNT}` | |
do | |
LEN=`timediff ${COMSKIP_START[$N]} ${COMSKIP_END[$N]}` | |
if [ $(time2msec ${LEN}) -gt 16000 ]; then | |
echo "${N}: START=${COMSKIP_START[$N]}, END=${COMSKIP_END[$N]}. LENGTH=${LEN}" >> ${LOG} | |
${FFMPEG} -y -i ${TS} ${FFMPEG_AOPT} -vcodec copy -ss ${COMSKIP_START[$N]} -t ${LEN} ${BASE}-split${N}.ts >> ${LOG} 2>&1 | |
_FILES+=(${BASE}-split${N}.ts) | |
fi | |
done | |
FFMPEG_INPUT="concat:$(IFS="|"; echo "${_FILES[*]}")" | |
fi | |
rm -f ${BASE}.{txt,log,logo.txt,vdr} >> ${LOG} 2>&1 | |
fi | |
# Merge/Encode | |
${FFMPEG} -y -i "${FFMPEG_INPUT}" ${FFMPEG_AOPT} ${FFMPEG_VOPT} ${BASE}.mp4 >> ${LOG} 2>&1 | |
# Clean Up | |
rm -f ${BASE}-split*.ts >> ${LOG} 2>&1 | |
# ts backup | |
BACKUPDIR=${TS%/*} | |
BUCKUPNAME=${TS##*/} | |
mv ${TS} ${BACKUPDIR}/backup/${BUCKUPNAME} >> ${LOG} 2>&1 | |
echo "Finish: `date`" >> ${LOG} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment