-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractAudioFromVideoFiles.sh
More file actions
executable file
·82 lines (56 loc) · 2.24 KB
/
extractAudioFromVideoFiles.sh
File metadata and controls
executable file
·82 lines (56 loc) · 2.24 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/zsh
# extractAudioFromVideoFiles.sh
# Requires FFMPEG and FFPROBE
#Gets the directory to use from the first argument to this script
INPUTFILEEXTENSION="$1"
DIRECTORYTOCRAWL="$2"
USAGE="
Usage:
extractAudioFromVideoFiles.sh inputFileExtension directoryToProcess
Don't put a period before the file extensions.
* EXECUTE THIS COMMAND IN DIRECTORY WHERE THE MKV FILES ARE STORED *
This will crawl through the current directory and EXTRACT the audio track of the given
video files. Provide it with the video filename extension that you want it to search for
and process. Examples are mp4 or mkv . This command needs to be run from the directory
that the mkv files are in
NOTE: AAC audio files will be named with the extension of ".m4a" which iTunes prefers.
Dan Bowen MIT License
"
#check that the user has entered two arguments (hopefully the extension and directory),
# otherwise print the usage statement.
if [ $# -ne 2 ] ; then
echo -e $USAGE
exit 1;
fi
#Iterates through each file
for FILENAME in "$DIRECTORYTOCRAWL"/*.$INPUTFILEEXTENSION
do
#Echo filename to console
INPUTFILESIMPLENAME=`basename $FILENAME`
echo -n "$INPUTFILESIMPLENAME"
#echo -e "\n"
#Get the audio track's codec name
AUDIOTYPE=`ffprobe -v error -select_streams a -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 $FILENAME`
#Print the codec name on screen
#echo -e " ** Audio codec: $AUDIOTYPE ** \n"
#Change the file extension if it's aac for iTunes
if [ $AUDIOTYPE = 'aac' ]
then
#Change the file extension if it's aac for iTunes
OUTPUTFILEEXTENSION='m4a'
else
#Otherwise just use the audio codec name for the file extension
OUTPUTFILEEXTENSION=$AUDIOTYPE
fi
#print stuff
echo -e " ---> .$OUTPUTFILEEXTENSION"
# get the filename with whatever extension?????
TMPOUTFILE="${FILENAME%.*}"
#strip the existing extension and replace with .m4a ???
OUTFILE="$DIRECTORYTOCRAWL/${TMPOUTFILE##*/}.$OUTPUTFILEEXTENSION"
OUTPUTFILESIMPLENAME=`basename $OUTFILE`
#Echo output filename to console
# echo -n "$OUTPUTFILESIMPLENAME"
# echo -e "\n"
ffmpeg -loglevel quiet -i "${FILENAME}" -vn -acodec copy -metadata title="$INPUTFILESIMPLENAME" -n "${OUTFILE}"
done