-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdavinconv
More file actions
executable file
·137 lines (117 loc) · 3.7 KB
/
davinconv
File metadata and controls
executable file
·137 lines (117 loc) · 3.7 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#! /bin/bash
VERSION=0.1.0
USERNAME=$(whoami)
VIDDIR=/home/"$USERNAME"/Videos/davinconv
WHEREAMI=$(pwd)
if [ ! -d "$VIDDIR" ]; then
mkdir -p "$VIDDIR"
mkdir -p "$VIDDIR"/converted
mkdir -p "$VIDDIR"/exported
fi
Help() {
echo ""
echo " ............................................................"
echo " . Davinconv - video converter for Davinci Resolve on Linux ."
echo " . v0.1.0 by Gohny ."
echo " ............................................................"
echo ""
echo "Usage: davinconv [-c|C|e|E|h|R]"
echo ""
echo "Options:"
echo " {-c} [file] - Convert video to ProRes codec that can be read by Davinci Resolve."
echo " {-C} - Convert all videos in current directory to ProRes codec that can be read by Davinci Resolve."
echo " {-e} [file] - Export converted video back to the H264 codec."
echo " {-E} - Export all converted videos stored in $VIDDIR/converted back to the H264 codec."
echo " {-h} - Display this message."
echo " {-R} - Remove all converted videos stored in $VIDDIR/converted."
echo ""
echo "All converted and exported videos are stored in: ~/Videos/davinconv"
echo ""
echo "It is recommended to watch https://www.youtube.com/watch?v=WLcW4UWPC5Y before using the script."
echo ""
echo "LICENSE: GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007"
echo "https://github.com/gohny/davinconv"
}
Convert() {
local i="$1"
pixfmt=$(ffprobe -v error -select_streams v:0 \
-show_entries stream=pix_fmt -of csv=p=0 "$i")
if [[ "$pixfmt" == *"yuva"* || "$pixfmt" == *"rgba"* ]]; then
if [[ "$pixfmt" == *"12"* && "$i" == *.mov ]]; then
ffmpeg -i "$i" -c:v copy -c:a copy "$VIDDIR/converted/${i%.*}.mov"
else
ffmpeg -i "$i" -c:v prores_ks -profile:v 4444 -pix_fmt yuva444p10le -c:a pcm_s16be "$VIDDIR/converted/${i%.*}.mov"
fi
else
ffmpeg -i "$i" -c:v prores_ks -profile:v 3 -pix_fmt yuv422p10le -c:a pcm_s16be "$VIDDIR/converted/${i%.*}.mov"
fi
}
ConvertOne() {
Convert "$i"
}
ConvertAll() {
shopt -s nullglob
for i in *.mp4 *.mkv *.avi *.m4v *.mov; do
Convert "$i"
done
}
Export() {
ffmpeg -i "$VIDDIR"/converted/"$i" -c:v libx264 -preset ultrafast -crf 0 "$VIDDIR"/exported/${i%.*}.mp4
}
ExportAll() {
cd "$VIDDIR"/converted
for i in *.mov; do
ffmpeg -i "$i" -c:v libx264 -preset ultrafast -crf 0 "$VIDDIR"/exported/${i%.*}.mp4
done
cd "$WHEREAMI"
}
RemoveAll() {
while true; do
echo "You are about to remove ALL converted videos stored in $VIDDIR/converted."
read -p "Do you want to continue? (y/n) " yn
case $yn in
[yY] )
echo ""
echo "please wait..."
echo ""
sleep 1
rm -rf "$VIDDIR"/converted/*
break;;
[nN] )
echo "No changes have been made."
exit;;
* )
echo "Error: please input y or n";;
esac
done
}
while getopts ":c:Ce:EhR" OPTION; do
case $OPTION in
c)
i=${OPTARG}
ConvertOne
exit;;
C)
ConvertAll
exit;;
e)
i=${OPTARG}
Export
exit;;
E)
ExportAll
exit;;
h)
Help
exit;;
R)
RemoveAll
exit;;
*)
echo "Error: Invalid option or argument not provided!"
echo "For help use: davinconv -h"
exit;;
esac
done
Help
exit