| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # video::convert Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Video::Convert; | ||
| 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 avi jpg) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | attributes => { | ||
| 19 | datadir => [ qw(directory) ], | ||
| 20 | output_pattern => [ qw(file_pattern) ], | ||
| 21 | keep_only_first => [ qw(0|1) ], | ||
| 22 | }, | ||
| 23 | attributes_default => { | ||
| 24 | output_pattern => 'image_%04d.jpg', | ||
| 25 | keep_only_first => 0, | ||
| 26 | }, | ||
| 27 | commands => { | ||
| 28 | install => [ ], # Inherited | ||
| 29 | to_jpg => [ qw(input) ], | ||
| 30 | }, | ||
| 31 | require_modules => { | ||
| 32 | 'Metabrik::File::Find' => [ ], | ||
| 33 | 'Metabrik::System::File' => [ ], | ||
| 34 | }, | ||
| 35 | require_binaries => { | ||
| 36 | 'ffmpeg' => [ ], | ||
| 37 | }, | ||
| 38 | need_packages => { | ||
| 39 | ubuntu => [ qw(ffmpeg) ], | ||
| 40 | debian => [ qw(ffmpeg) ], | ||
| 41 | kali => [ qw(ffmpeg) ], | ||
| 42 | }, | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub to_jpg { | ||
| 47 | my $self = shift; | ||
| 48 | my ($input) = @_; | ||
| 49 | |||
| 50 | my $datadir = $self->datadir; | ||
| 51 | my $output_pattern = $self->output_pattern; | ||
| 52 | my $keep_only_first = $self->keep_only_first; | ||
| 53 | $self->brik_help_run_undef_arg('to_jpg', $input) or return; | ||
| 54 | $self->brik_help_run_file_not_found('to_jpg', $input) or return; | ||
| 55 | |||
| 56 | my $ff = Metabrik::File::Find->new_from_brik_init($self) or return; | ||
| 57 | my $sf = Metabrik::System::File->new_from_brik_init($self) or return; | ||
| 58 | |||
| 59 | # This program is only provided for compatibility and will be removed in a future release. | ||
| 60 | # Please use avconv instead. | ||
| 61 | my $cmd = "ffmpeg -i $input $datadir/".$output_pattern; | ||
| 62 | |||
| 63 | $self->execute($cmd) or return; | ||
| 64 | |||
| 65 | (my $find = $output_pattern) =~ s/^(.*)%.*$/$1/; | ||
| 66 | my $found = $ff->files($datadir, "$find.*") or return; | ||
| 67 | |||
| 68 | if ($keep_only_first) { | ||
| 69 | my $keep = shift @$found; | ||
| 70 | $sf->remove($found); | ||
| 71 | $found = $keep; | ||
| 72 | } | ||
| 73 | |||
| 74 | return $found; | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; | ||
| 78 | |||
| 79 | __END__ | ||