Updated for Ubuntu 22.04. Also fixed merge videos cmin check
[videoscripts/.git] / avchd2h264
1 #!/bin/bash
2
3 # Command line options
4 INPUT=$1
5 OUTPUT_DIR=$2
6
7 # Recommended min quality for 1080p HD = 22
8 # Quality 17 ~ 30% of the original size
9 # Quality 18 ~ 25% of the original size
10 # Quality 20 ~ 15% of the original size
11 # Quality 25 ~ 75% of the original size (for 1080p/60fps content)
12 # Quality 26 ~ 60% of the original size (for 1080p/60fps content)
13 # Quality 27 ~ 50% of the original size (for 1080p/60fps content)
14 QUALITY=18
15
16 if [ -z "$INPUT" ]; then
17   echo "Usage: $0 input outputdir"
18   exit 1
19 fi
20
21 if [ -z "$OUTPUT_DIR" ]; then
22     OUTPUT_DIR="."
23 fi
24
25 FILENAME=`basename "${INPUT%.*}"`
26 OUTPUT="$OUTPUT_DIR/$FILENAME.mkv"
27
28 # We want our audio to be pass-through, so detect what the audio of the input is encoded with, and tell handbrake to make the output match
29 AUDIO_CODEC=`avconv -i "$INPUT" 2>&1 | grep "Audio" | sed -r -e 's/.*?Audio: (\S+),.*?/\1/'`
30 if [ -z "$AUDIO_CODEC" ]; then
31   echo "-E- Unable to determine audio codec to use for the input video: $INPUT"
32   exit 1
33 fi
34 AUDIO_ENC="copy:$AUDIO_CODEC"
35
36 echo "-> Converting \"$INPUT\" to 1080p compressed \"$OUTPUT\" file using audio codec $AUDIO_CODEC"
37
38 if [[ -e "$OUTPUT" ]]; then
39   echo "-E- Output file $OUTPUT already exists. Aborting..."
40   exit 1
41 fi
42
43 # --deblock
44 # --decomb
45 # --denoise="weak" 
46 # deblock=1,1
47 # subme=10:trellis=2
48
49 # 1080i
50 #QUALITY=18
51 #HandBrakeCLI -i "$INPUT" -o "$OUTPUT" -f mkv --denoise="weak" -e x264 -q $QUALITY -x b-adapt=2:rc-lookahead=120 -v 2 -E $AUDIO_ENC -a 1 -6 dpl2 --strict-anamorphic --crop 0:0:0:0 --preset="High Profile" --decomb 
52
53 # 1080p
54 QUALITY=25
55 HandBrakeCLI -i "$INPUT" -o "$OUTPUT" -f mkv --denoise="weak" --deblock -e x264 -q $QUALITY -x b-adapt=2:rc-lookahead=120:deblock=1,1:subme=10:trellis=2 -v 2 -E $AUDIO_ENC -a 1 -6 dpl2 --auto-anamorphic --crop 0:0:0:0 --preset="Very Fast 1080p30" --decomb
56