-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENCODE_csv.pl
executable file
·127 lines (119 loc) · 3.22 KB
/
ENCODE_csv.pl
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
#!/usr/bin/perl
use Cwd;
use Env;
use Term::ANSIColor qw(:constants);
use Image::Magick;
#http://www.imagemagick.org/script/command-line-options.php
$script = $0;
print BOLD BLUE "script : $script\n";print RESET;
@tmp=split(/\//,$script);
$scriptname=$tmp[$#tmp];
@tmp=split(/\./,$scriptname);
$scriptname=lc $tmp[0];
$CWD=getcwd;
#get project name
@tmp=split(/\//,$CWD);
$PROJECT=$tmp[$#tmp];
print BOLD BLUE "project : $PROJECT\n";print RESET;
#-vf "scale=w=5400:h=1920" -sws_flags bicubic -c:v hap -chunks 16
#defaults
$INDIR="./originales";
$OUTDIR="./";
$ZEROPAD=1;
$EXT="png";
$FORMAT="csv";
$PRORESCODEC="-c:v prores_ks -profile:v 3";
$H264CODEC="-c:v libx264 -crf 10 -pix_fmt yuv420p";
$H264CODEC="-c:v libx264 -crf 10";
$DNXCODEC="-c:v dnxhd -b:v 120M -pix_fmt yuv422p";
$HAPCODEC="-c:v hap -chunks 16";
$EXECUTE=0;
$VERBOSE=1;
if ($#ARGV == -1) {
print "usage: $scriptname.pl \n";
print "-idir dirin [$INDIR]\n";
print "-odir dirout [$OUTDIR]\n";
print "-ext image extension [$EXT]\n";
print "-format [$FORMAT] prores h264 dnx_120 hap\n";
print "-exec : execute command (ffmpeg only) [$EXECUTE]\n";
exit;
}
for ($arg=0;$arg <= $#ARGV;$arg++)
{
if (@ARGV[$arg] eq "-idir")
{
$INDIR=@ARGV[$arg+1];
print "in dir : $INDIR\n";
}
if (@ARGV[$arg] eq "-odir")
{
$OUTDIR=@ARGV[$arg+1];
print "out dir : $OUTDIR\n";
}
if (@ARGV[$arg] eq "-ext")
{
$EXT=@ARGV[$arg+1];
print "image extension : $EXT\n";
}
if (@ARGV[$arg] eq "-format")
{
$FORMAT=@ARGV[$arg+1];
print "output format : $FORMAT\n";
}
if (@ARGV[$arg] eq "-exec")
{
$EXECUTE=1;
print "execute command\n";
}
if (@ARGV[$arg] eq "-csv")
{
$CSVFILE=@ARGV[$arg+1];
print "csv file: $CSV\n";
}
}
#$OUTDIR="$INDIR\_dnx120";
#$OUTDIR="$INDIR\_prores";
#$OUTDIR="$INDIR\_hap";
open (CSV , "$CSVFILE");
while ($line=<CSV>)
{
chop $line;
@line=split(/,/,$line);
$SHOT=@line[0];
$FSTART=@line[3];
$FEND=@line[4];
$LENGTH=@line[5];
$process=@line[6];
if ($process)
{
encode();
}
}
sub encode {
if ($FORMAT eq "hap")
{
print "encoding $FORMAT\n";
$RESIZEFILTER="scale=w=5400:h=1920";
$FILTER="-sws_flags bicubic";
$cmd="ffmpeg -i $INDIR/$SHOT.%04d.png -vf \"$RESIZEFILTER\" $FILTER $HAPCODEC $OUTDIR/$SHOT\_hap.mov";
}
if ($FORMAT eq "prores")
{
print "encoding $FORMAT\n";
$cmd="ffmpeg -i $INDIR/$SHOT.%04d.png $PRORESCODEC $OUTDIR/$SHOT\_prores.mov";
}
if ($FORMAT eq "h264")
{
print "encoding $FORMAT\n";
$cmd="ffmpeg -i $INDIR/$SHOT.%04d.png $H264CODEC $OUTDIR/$SHOT\_h264.mov";
}
if ($FORMAT eq "dnx_120")
{
print "encoding $FORMAT\n";
$RESIZEFILTER="scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2";
$STAMPFILTER="drawtext=fontfile=/usr/share/fonts/truetype/tlwg/Sawasdee.ttf: text='$SHOT.mov \%{frame_num}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: fontsize=40: alpha=.5";
$cmd="ffmpeg -i $INDIR/$SHOT.%04d.png -vf \"$RESIZEFILTER,$STAMPFILTER\" $DNXCODEC $OUTDIR/$SHOT\_dnx120.mov";
}
print "$cmd\n";
if ($EXECUTE) {system $cmd;}
}