line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# video::ffmpeg Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Video::Ffmpeg; |
7
|
1
|
|
|
1
|
|
633
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
475
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable audio sound record micro) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
resolution => [ qw(resolution) ], |
20
|
|
|
|
|
|
|
use_micro => [ qw(0|1) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
attributes_default => { |
23
|
|
|
|
|
|
|
resolution => '1024x768', |
24
|
|
|
|
|
|
|
use_micro => 0, |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
commands => { |
27
|
|
|
|
|
|
|
install => [ ], # Inherited |
28
|
|
|
|
|
|
|
record_desktop => [ qw(output.mkv resolution|OPTIONAL) ], |
29
|
|
|
|
|
|
|
convert_to_youtube => [ qw(input.mkv output.mp4) ], |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
require_binaries => { |
32
|
|
|
|
|
|
|
ffmpeg => [ ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
need_packages => { |
35
|
|
|
|
|
|
|
ubuntu => [ qw(ffmpeg) ], |
36
|
|
|
|
|
|
|
debian => [ qw(ffmpeg) ], |
37
|
|
|
|
|
|
|
kali => [ qw(ffmpeg) ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub record_desktop { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my ($output, $resolution) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
0
|
|
|
|
$resolution ||= $self->resolution; |
47
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('record_desktop', $output) or return; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Give 1 second to switch window if needed. |
50
|
0
|
|
|
|
|
|
my $cmd = 'sleep 1 && ffmpeg'; |
51
|
0
|
0
|
|
|
|
|
if ($self->use_micro) { |
52
|
0
|
|
|
|
|
|
$cmd .= " -f alsa -i pulse -f x11grab -r 25 -s $resolution -i :0.0 ". |
53
|
|
|
|
|
|
|
"-acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
|
$cmd .= " -f x11grab -r 25 -s $resolution -i :0.0 -vcodec libx264 ". |
57
|
|
|
|
|
|
|
"-preset ultrafast -crf 0 -threads 0"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$cmd .= " \"$output\""; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->execute($cmd); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub convert_to_youtube { |
66
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my ($input, $output) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('convert_to_youtube', $input) or return; |
70
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('convert_to_youtube', $output) or return; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $cmd = "ffmpeg -i \"$input\" -codec:v libx264 -crf 21 -bf 2 -flags +cgop ". |
73
|
|
|
|
|
|
|
"-pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart ". |
74
|
|
|
|
|
|
|
"\"$output\""; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self->execute($cmd); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |