-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvenc_thread.pl
executable file
·87 lines (69 loc) · 1.74 KB
/
nvenc_thread.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
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Printer;
use Getopt::Long;
use Parallel::ForkManager;
use Pod::Usage;
use FFmpeg::Transcoder;
my %queue;
# options
my $input_dir;
my @inputs;
my $outdir = './outdir';
my $debug = 0;
my $nthread = 3;
my @ndevices = $ENV{CUDA_VISIBLE_DEVICES}
? split( /,/, $ENV{CUDA_VISIBLE_DEVICES} )
: (0,1);
GetOptions(
'debug' => \$debug,
'nthread=i' => \$nthread,
'outdir=s' => \$outdir,
'input=s{1,}' => \@inputs,
'input_dir=s' => sub{ @inputs = <$_[1]/*> }
);
if ( @inputs ) {
build_queue();
if ( $debug ) {
p %queue;
exit
}
transcode();
}
sub build_queue {
while ( @inputs ) {
for my $gpu ( @ndevices ) {
@inputs
? push $queue{$gpu}->@*,
FFmpeg::Transcoder->new(
input => shift @inputs,
device => $gpu,
outdir => $outdir,
log_level => 0,
stats => 0,
overwrite => 1
)->cmd
: next
}
}
}
sub transcode {
mkdir $outdir unless -d $outdir;
my $ngpus = keys %queue;
my $device = Parallel::ForkManager->new( $ngpus );
DEVICE:
for my $gpu ( sort keys %queue ) {
$device->start and next DEVICE;
my $ffmpeg = Parallel::ForkManager->new($nthread);
CUDA:
for my $cmd ( $queue{$gpu}->@* ) {
$ffmpeg->start and next CUDA;
system($cmd);
$ffmpeg->finish;
}
$ffmpeg->wait_all_children;
$device->finish;
}
$device->wait_all_children;
}