All pastes #630345 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-23 03:18 UTC
rendered paste body
#!/bin/bash

. tovid-init

WORK_DIR=$(readlink -f todisc_work)
WORK_DIR=$(tempdir "$WORK_DIR")
LOG_FILE="$WORK_DIR/makecollage.log"
FRAME_RATE=29.970
ASPECT_RATIO="4:3"

vid_length()
{
    mencoder -nosound -mc 0 -oac pcm -ovc copy -o /dev/null "$1" 2>/dev/null |
    awk 'END{print $(NF-3)}'
}

runtime_error()
{
    # Uncomment if needed later
    #killsubprocs
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "makecollage.sh encountered an error:"
    echo "    $@"
    echo "Check the contents of $LOG_FILE to see what went wrong."
    echo "See the tovid website ($TOVID_HOME_PAGE) for what to do next."
    echo "Sorry for the inconvenience!"
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    exit 1
}

make_slice()
{
    FILE_IN="$1"
    slice=$2
    index=$3
    ffmpeg -i "$FILE_IN" -ss $slice -t 3 -s 318x212 -an \
    -padtop 104 -padbottom 164 -padleft 262 -padright 140 \
    -f mpeg2video -r $FRAME_RATE -tvstd ntsc -b 12000k -maxrate 15000k \
    -bufsize 230KiB -aspect $ASPECT_RATIO \
    -y  "$WORK_DIR/slice${index}_tmp.m2v"
}

while [ $# -gt 0 ]; do
    case "$1" in
        "-files" )
            shift
            get_listargs "$@"
            for f in  ${!ARGS_ARRAY[@]}; do
                FILES[f]="$(abspath "${ARGS_ARRAY[f]}")"
            done
            ;;
        
    esac
    shift
done

# execution starts here

ffmpeg_prefix=$(which ffmpeg)
ffmpeg_prefix=$(sed 's/bin\/ffmpeg//g' <<< "$ffmpeg_prefix")
imlib2_vhook="$ffmpeg_prefix/lib/vhook/imlib2.so"
! [[ -s "$imlib2_vhook" ]] && runtime_error "Can't find your ffmpeg's vhook's"


for v in ${!FILES[@]}; do
    file_len[v]=$(vid_length "${FILES[v]}")
done

echo "file_len indices are ${!file_len[@]}"
# get the shortest file length
for i in ${!file_len[@]}; do
    val=${file_len[i]%.*}
    echo "val is $val"
    [ -z "$MAX_VAL" ] || ((val > MAX_VAL)) && MAX_VAL=$val && max_key=$i
    [ -z "$MIN_VAL" ]  || ((val < MIN_VAL)) && MIN_VAL=$val && min_key=$i
done
echo "video lengths are:"
for i in ${!FILES[@]}; do
    echo "${FILES[i]}: ${file_len[i]}"
done
echo "MAX_VAL is $MAX_VAL from video ${FILES[max_key]}"
echo "MIN_VAL is $MIN_VAL from video ${FILES[min_key]}"

slice_size=$(( $MIN_VAL / 12 ))
(( $slice_size < 5 )) && echo "sorry, shortest video must be >= 60 seconds long" && exit 1

for ind in ${!FILES[@]}; do
    for i in {1..12}; do
        make_slice "${FILES[ind]}" $(( slice_size * i )) ${ind}-${i}
    done
done
num_slices=$(( ${#FILES[@]} * 2 ))

m2v_files=( "$WORK_DIR"/slice*.m2v )
for i in ${!m2v_files[@]}; do
    rand_date[i]=$(( $((RANDOM%37)) + 1970 ))$(printf "%02d" $((RANDOM%12 + 1)) )$(printf "%02d"  $((RANDOM%30 +1)) )
    touch -d ${rand_date[i]} ${m2v_files[i]}
done
 
unset x m2v_files ; while read line; do m2v_files[x++]="$line"; done <<<  "$(ls -t -1 "$WORK_DIR"/slice*.m2v)"
cat "${m2v_files[@]}" > final.m2v