Video/Ffmpeg.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Video/Convert.pm ↑ Summary Worker/Fork.pm »
1 #
2 # $Id$
3 #
4 # video::ffmpeg Brik
5 #
6 package Metabrik::Video::Ffmpeg;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Shell::Command Metabrik::System::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable audio sound record micro) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
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 my $self = shift;
44 my ($output, $resolution) = @_;
45  
46 $resolution ||= $self->resolution;
47 $self->brik_help_run_undef_arg('record_desktop', $output) or return;
48  
49 # Give 1 second to switch window if needed.
50 my $cmd = 'sleep 1 && ffmpeg';
51 if ($self->use_micro) {
52 $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 $cmd .= " -f x11grab -r 25 -s $resolution -i :0.0 -vcodec libx264 ".
57 "-preset ultrafast -crf 0 -threads 0";
58 }
59  
60 $cmd .= " \"$output\"";
61  
62 return $self->execute($cmd);
63 }
64  
65 sub convert_to_youtube {
66 my $self = shift;
67 my ($input, $output) = @_;
68  
69 $self->brik_help_run_undef_arg('convert_to_youtube', $input) or return;
70 $self->brik_help_run_undef_arg('convert_to_youtube', $output) or return;
71  
72 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 return $self->execute($cmd);
77 }
78  
79 1;
80  
81 __END__
« Video/Convert.pm ↑ Summary Worker/Fork.pm »