blob: df59204af053fc202623d0d85571f54ae4f7a8af (
plain)
1 #!/usr/bin/env bash
2 #
3 # This script is intended for provide a "sane" video conversion and
4 # recompression. It is useful for recompressing high quality video taken with a
5 # camera so less storage is taken.
6 #
7 # Note: This does not delete the original.
8 #
9 # Requirements:
10 # ffmpeg
11 # libtheora
12
13 new_ext="ogv"
14
15 if [[ -z $1 ]]; then
16 echo "Please specify a file to compress"
17 exit 1
18 fi
19
20 orig="${1}"
21 ext_index=""
22
23 # Note that we're going backwards (right to left) here so we don't stop early
24 # on filenames with multiple periods in their name.
25 for (( i=${#orig}; i>0; i-- )); do
26 if [[ ${orig:$i:1} == "." ]]; then
27 # Set where the extension starts so we know what to replace for the new
28 # extension
29 ext_index=$i
30 break
31 fi
32 done
33
34 # Exit of an extension couldn't be determined
35 if [[ ${ext_index} == "" ]]; then
36 echo "Fatal Error: Filename could not be determined for file ${orig}."
37 exit 1
38 fi
39
40 # Set the new filename for output
41 # TODO: Make the extension a little less hard coded
42 new=${orig:0:$ext_index}.${new_ext}
43
44 echo -e "\bBeginning recompression of ${orig}...."
45 # Assume theora/vorbis for now
46 ffmpeg -i "${orig}" -loglevel error -codec:a libvorbis -codec:v libtheora -qscale:a 7 -qscale:v 7 "${new}"
|