extract-thumbnail script improved
[video-handling.git] / transcode-all
1 #!/bin/bash
2 #
3 # Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com
4 #
5 # This script transcodes all input videos with a specified extension to a new
6 # format with a given resolutin and video bitrate. The audio bitrate is hard
7 # coded to 192 kb/s. The output_path parameter is optional. If not given it
8 # puts all output files in the same folder as the corresponding input.
9 #
10
11 if test $# -lt 4; then
12     echo "Usage: $0 input-path input-extension output-format resolution video-bitrate [output-suffix] [output_path]"
13     exit 1
14 fi
15
16 in_path="$1"
17 in_ext="$2"
18 out_format="$3"
19 resolution="$4"
20 bitrate="$5"
21 if [ ! -z "$6" ]; then
22     out_suffix="$6"
23 else
24     out_suffix=""
25 fi
26 if [ ! -z "$7" ]; then
27     out_path="$7"
28 fi
29
30 FFMPEG=/usr/bin/ffmpeg
31 ABITRATE=192k
32
33 (
34 IFS=$'\n'
35 for filename in $(find "$in_path" -name "*.$in_ext"); do
36     if [ ! -z "$out_path" ]; then
37         new_filename="${out_path}"$(basename "$filename" ."$in_ext")"$out_suffix"."$out_format"
38     else
39         new_filename=$(dirname "$filename")/$(basename "$filename" ."$in_ext")"$out_suffix"."$out_format"
40     fi
41
42     if [ -e $new_filename ]; then
43         echo "$0: $new_filename already exists" >&2
44         continue
45     fi
46
47     case "$out_format" in
48         "avi" )
49             $FFMPEG -i "$filename" -f avi -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename"
50             ;;
51         "flv" )
52             $FFMPEG -i "$filename" -f flv -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename"
53             ;;
54         "mp4" )
55             $FFMPEG -i "$filename" -f mp4 -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s "$resolution" -threads 0 "$new_filename"
56             ;;
57         "ogg" )
58             $FFMPEG -i "$filename" -f ogg -acodec libvorbis -ab $ABITRATE -ar 44100 -ac 2 -vcodec libtheora -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename"
59             ;;
60         "webm" )
61             $FFMPEG -i "$filename" -f webm -acodec libvorbis -ab $ABITRATE -ar 44100 -ac 2 -vcodec libvpx -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename"
62             ;;
63         "ts" )
64             $FFMPEG -i "$filename" -f mpegts -acodec libmp3lame -ab $ABITRATE -ar 44100 -ac 2 -vcodec libx264 -vpre normal -b "$bitrate" -r 25 -s $resolution -threads 0 "$new_filename"
65             ;;
66
67         * )
68             echo "Format $out_format is not implemented!" 1>&2
69             exit 1
70             ;;
71     esac
72
73 done
74 )