-
Notifications
You must be signed in to change notification settings - Fork 0
/
rewrap-video.sh
executable file
·28 lines (25 loc) · 1.02 KB
/
rewrap-video.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#! /usr/bin/env bash
file=$(/usr/local/opt/coreutils/libexec/gnubin/readlink -f "$1");
_f=$(/usr/local/opt/coreutils/libexec/gnubin/basename "$file");
_d=$(/usr/local/opt/coreutils/libexec/gnubin/dirname "$file");
_e="$(echo ${_f##*.} | /usr/local/opt/coreutils/libexec/gnubin/tr '[:upper:]' '[:lower:]')"
echo "Processing $file...";
case $_e in
mkv)
echo "mkv";
data="$(mkvinfo "$file")"
aac="$(echo -n "$data" | /usr/bin/grep "Codec ID:" | /usr/bin/grep "AAC" | /usr/local/opt/coreutils/libexec/gnubin/wc -l)";
;;
mp4|m4v)
echo "mp4";
data="$(mp4info "$file")"
aac=$(echo -n "$data" | /usr/bin/grep "MPEG-4 AAC" | /usr/local/opt/coreutils/libexec/gnubin/wc -l);
;;
esac
if [ "$aac" -eq 0 ]; then
echo "No AAC format detected. Converting audio to AAC.";
ffmpeg -i "$file" -c:v copy -c:a aac -movflags +faststart "$file".mp4
else
echo "Converting container to MP4 and/or optimizing atoms.";
ffmpeg -i "$file" -c copy -movflags +faststart "$file".mp4
fi;