« blib/lib/Media/Convert/Asset/ProfileFactory.pm
↑ Summary
blib/lib/Media/Convert/Normalizer/None.pm »
| 1 | package Media::Convert::Asset::Profile::copy; | ||
| 2 | |||
| 3 | use Media::Convert::Asset::ProfileFactory; | ||
| 4 | use Media::Convert::CodecMap qw/detect_to_write/; | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | |||
| 8 | extends 'Media::Convert::Asset::Profile::Base'; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Media::Convert::Asset::Profile::copy - Profile that merely copies all data, unmodified. | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | use Media::Convert::Asset; | ||
| 17 | use Media::Convert::Asset::ProfileFactory; | ||
| 18 | use Media::Convert::Pipe; | ||
| 19 | |||
| 20 | my $input = Media::Convert::Asset->new(url => $input_filename); | ||
| 21 | my $profile = Media::Convert::Asset::ProfileFactory->create("copy", $input); | ||
| 22 | my $output = Media::Convert::Asset->new(url => "$output_basename." . $profile->exten, reference => $profile); | ||
| 23 | Media::Convert::Pipe->new(inputs => [$input], output => $output)->run(); | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | The C<copy> profile copies the input video into the output container, | ||
| 28 | without any re-encoding. | ||
| 29 | |||
| 30 | It only works in one of the following conditions: | ||
| 31 | |||
| 32 | =over | ||
| 33 | |||
| 34 | =item * | ||
| 35 | |||
| 36 | the video codec is VP9 and the audio codec is opus (the extension will | ||
| 37 | be .webm) | ||
| 38 | |||
| 39 | =item * | ||
| 40 | |||
| 41 | the video codec is VP8 and the audio codec is vorbis (the extension will | ||
| 42 | be .webm) | ||
| 43 | |||
| 44 | =item * | ||
| 45 | |||
| 46 | the video codec is H.264 and the audio codec is AAC (the extension will | ||
| 47 | be .mp4) | ||
| 48 | |||
| 49 | =back | ||
| 50 | |||
| 51 | All other cases are currently unsupported (but could be added if | ||
| 52 | required). | ||
| 53 | |||
| 54 | The C<copy> profile has the exact same effect as using the | ||
| 55 | L<Media::Convert::Pipe/vcopy> and L<Media::Convert::Pipe/acopy> options | ||
| 56 | on C<Media::Convert::Pipe>, but is expressed as a profile. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | sub _probe_exten { | ||
| 61 | my $self = shift; | ||
| 62 | my $ref = $self->reference; | ||
| 63 | my $vid = $ref->video_codec; | ||
| 64 | my $aud = $ref->audio_codec; | ||
| 65 | |||
| 66 | if (($vid eq 'vp9' && $aud eq 'opus') | ||
| 67 | or ($vid eq 'vp8' && $aud eq 'vorbis')) { | ||
| 68 | return 'webm'; | ||
| 69 | } | ||
| 70 | if ($vid eq 'h264' && $aud eq 'aac') { | ||
| 71 | return 'mp4'; | ||
| 72 | } | ||
| 73 | ... | ||
| 74 | } | ||
| 75 | |||
| 76 | sub _probe_videocodec { | ||
| 77 | return "copy"; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub _probe_audiocodec { | ||
| 81 | return "copy"; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; |