From c38fab4a8e55a2c0ca625675213aaa29cd62b768 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 24 Oct 2013 21:52:34 +0200 Subject: [PATCH] tc-video-generic: croping image preview! --- .scripts/.tc-video-custom.in | 4 ++-- .scripts/tc-audio-transcode | 6 +++--- .scripts/tc-video-generic | 39 +++++++++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.scripts/.tc-video-custom.in b/.scripts/.tc-video-custom.in index 5a4db61e..50f437d7 100644 --- a/.scripts/.tc-video-custom.in +++ b/.scripts/.tc-video-custom.in @@ -63,13 +63,13 @@ _transcode () ## You can choose here to process all files at the same time. Useful if you ## need to remux streams or to concatenate. # ffmpeg -i ###FILELIST \ - ffmpeg -i "$@" \ + ffmpeg -nostdin -i "$@" \ -c:v libx264 -preset slow -crf 20 \ -c:a libvorbis -b:a 192k -ac 2 \ -c:s copy \ -map 0 \ $SAMPLE \ - "${1%.*}-$(date '+%F-%H%M%S').mkv" &1 &1 | awk '/Duration/ {split($2, time, /:|\./); print time[1]*60*60 + time[2]*60 + time[3]}' } _highfreq() @@ -123,10 +130,20 @@ _cropvalue() ## sample the crop values. We keep the values with highest frequency. STEP=$(($(_duration "$1")/6)) for i in $(seq $STEP $STEP $((5*$STEP))); do - ffmpeg -ss $i -t 10 -i "$1" -vf "cropdetect=24:2:0" -f null - 2>&1 &1 done | _highfreq } +_croppreview() +{ + STEP=$(($(_duration "$1")/6)) + for i in $(seq $STEP $STEP $((5*$STEP))); do + ffmpeg -nostdin -v warning -y -ss $i -i "$1" \ + -f image2 -vframes 1 $VIDEO_FILTER "${1%.*}-preview-$i-cropped.png" \ + -f image2 -vframes 1 "${1%.*}-preview-$i-uncropped.png" + done +} + _audiobitrate() { ## As of 2013-10-23, ffmpeg sucks at retrieving audio bitrate. Therefore we @@ -140,7 +157,7 @@ _audiobitrate() if [ ! -n "$(command -v mediainfo)" ]; then mediainfo "$1" | awk 'BEGIN {id=0} /^Audio/ { getline; while(getline && ! index($0,"Bit rate ")); if($4) res=$4; else res=0; print id, res; id++}' else - ffmpeg -i "$1" 2>&1 &1 | awk 'BEGIN {id=0} /^ *Stream.*Audio/ {match($0, / [^ ]+ kb\/s/); res=substr($0, RSTART+1, RLENGTH-6); print id, res; id++}' fi | awk -v codec="$AUDIO_CODEC" -v bitrate="$AUDIO_DEFAULT_RATE" \ '{if($2 || bitrate) {if($2) bitrate=$2; if(bitrate+0 > 500) bitrate=500; printf "-c:a:" $1 " " codec " -b:a:" $1 " " bitrate "k "} else printf "-c:a:" $1 " copy "} END {print ""}' } @@ -152,7 +169,7 @@ _tc_transcode() STREAM_TITLE="" if $OPT_REMOVE_TITLE; then - STREAM_NUM=$(ffmpeg -i "$1" 2>&1 &1 | grep -c 'Stream') for i in $(seq 0 $STREAM_NUM); do STREAM_TITLE="${STREAM_TITLE}-metadata:s:$i title= " done @@ -161,6 +178,10 @@ _tc_transcode() if $OPT_CROP; then echo "Computing crop values... " VIDEO_FILTER="-vf $(_cropvalue "$1") $VIDEO_FILTER" + if $OPT_CROPPREVIEW; then + echo "Generating preview... " + _croppreview "$1" + fi fi ## Only if AUDIO_PARAM not already set. @@ -194,12 +215,12 @@ EOF STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')" [ "$STATUS" = "off" ] && set -o shwordsplit - ffmpeg $OVERWRITE -i "$1" \ + ffmpeg -nostdin $OVERWRITE -i "$1" \ $VIDEO_PARAM $VIDEO_FILTER \ $AUDIO_PARAM \ -c:s copy \ -map 0 $STREAM_TITLE \ - $SAMPLE $TC_VIDEO_OPT "$OUTPUT"