-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvidTranscode
executable file
·71 lines (63 loc) · 1.97 KB
/
vidTranscode
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
#!/usr/bin/env bash
#
# vidTranscode
# Version: 2017-03-06
# By: DrSlony
# Licence: CC0
#
# This Bash script transcodes the specificed video files (wildcards supported) to lossy h.264 format in an MP4 container.
#
# Usage:
# ./vidTranscode <video/files/with/path.ext>
#
# Examples:
# /home/you/scripts/vidTranscode /home/you/videos/foo.avi
# /home/you/scripts/vidTranscode /home/you/videos/*.avi
# /home/you/scripts/vidTranscode /home/you/videos/*
#
# Or create the .desktop file as shown below, select a bunch of files in your file manager and open them with this script.
# Sample .desktop file in $HOME/.local/share/applications/vidTranscode.desktop
#
# [Desktop Entry]
# Categories=AudioVideo;Video;
# Comment=Batch video transcode Bash script
# Exec="\\$HOME/scripts/vidTranscode" %F
# GenericName=vidTranscode
# MimeType=video/avi;video/mpeg;video/x-motion-jpeg;video/quicktime;video/mkv;video/mp4;
# Name=vidTranscode
# NoDisplay=false
# StartupNotify=true
# Terminal=true
# Type=Application
# Version=1.0
# Parameters:
cv="libx264"
crf="23"
preset="slow"
ca="libfdk_aac"
ba="192k"
# Do not edit below this line.
# Formatting
fNormal="$(tput sgr0)"
fBold="$(tput bold)"
# Keep junk files in /tmp
pushd /tmp || exit 1
# Test input files for validity, abort if invalid.
for f in "$@"; do
ffprobe -v error "${f}" 1>/dev/null
if [[ $? -ne 0 ]]; then
printf '%s\n' "The file is invalid:" "${f}" "Aborting."
exit 1
fi
done
# Do the conversion.
count="1"
for f in "$@"; do
printf '%s\n' "" "${fBold}Converting file ${count}/${#@}${fNormal}" "${f}"
#printf '%s\n' "ffmpeg -i \"${f}\" -y -f mp4 -c:a \"${ca}\" -b:a \"${ba}\" -c:v \"${cv}\" -crf \"${crf}\" -preset \"${preset}\" -map_metadata 0 \"${f%.*}_${cv}_${crf}_${preset}.mp4\""
ffmpeg -i "${f}" -y -f mp4 -c:a "${ca}" -b:a "${ba}" -c:v "${cv}" -crf "${crf}" -preset "${preset}" -map_metadata 0 "${f%.*}_${cv}_${crf}_${preset}.mp4" || exit 1
((count++))
done
# Done
popd
printf '%s\n' "" "Transcoding finished." ""