The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Media::Convert::Pipe - class to generate ffmpeg command lines with Media::Convert::Asset

SYNOPSIS

  use Media::Convert::Asset;
  use Media::Convert::Pipe;

  my $input_audio = Media::Convert::Asset->new(url => $input_filename_audio);
  my $input_video = Media::Convert::Asset->new(url => $input_filename_video);
  my $output = Media::Convert::Asset->new(url => $output_filename);
  my $map_audio = Media::Convert::Map->new(input => $input_audio, type => "stream", choice => "audio");
  my $map_video = Media::Convert::Map->new(input => $input_video, type => "stream", choice => "video");
  my $pipe = Media::Convert::Pipe->new(inputs => [$input_audio, $input_video], map => [ $map_audio, $map_video ], output => $output);
  $pipe->run();

  # Or, if progress information is wanted:
  sub print_progress {
    my $percentage = shift;
    print "Transcoding progress: $percentage\r";
  }
  $pipe->progress(\&print_progress);
  $pipe->run();

DESCRIPTION

Media::Convert::Pipe is the class in the Media::Convert package which does most of the hard work inside Media::Convert. It generates and runs the ffmpeg command line, capturing the output where required.

Media::Convert::Pipe will compare the properties of the input Media::Convert::Asset objects against those of the output Media::Convert::Asset object, and will add the necessary parameters to the ffmpeg command line to convert the audio/video material in the input file to the format required by the output file.

ATTRIBUTES

The following attributes are supported by Media::Convert::Pipe.

inputs

The objects to read from. Must be Media::Convert::Asset objects. If more than one object is passed, a value for the map attribute may be required to tell ffmpeg which audio/video stream to read from which file.

More input objects can be added using the add_input method, and they can all be removed using the clear_inputs object.

output

The object to write to. Must be a Media::Convert::Asset object. Required.

If any properties differ between the input objects and the output object (e.g., the codec, pixel format, audio sample frequency, video resolution, etc etc etc), Media::Convert::Pipe will add the necessary command-line options to the ffmpeg command line to convert the video from the input file to the output file.

map

Array of Media::Convert::Map objects, used to manipulate which audio and video streams exactly will be written to the output file (and in which order, etc).

For more info: see Media::Convert::Map.

Maps can be cleared with clear_map and added to with add_map.

vcopy

Boolean. If true, explicitly tell Media::Convert to copy video without transcoding it.

Normally, Media::Convert should not request a transcode if all attributes of the input file and the output file are exactly the same. Getting this right may sometimes be problematic, however. In such cases, it can be good to explicitly say that the video should not be transcoded. That's what this property is for.

acopy

The same as vcopy, but for audio rather than video.

vskip

Tell Media::Convert that the output file should not contain any video (i.e., that it should skip handling of any video). This is implied if the output container does not support video streams (e.g., the .wav format), but is required if it does.

askip

The same as vskip, but for audio rather than video.

multipass

Boolean. If true, the run method performs a two-pass encode, rather than a single-pass encode.

Two-pass encodes may generate a better end result, but require more time to perform.

progress

Normally, Media::Convert::Pipe shows (and runs) the ffmpeg command. Any output of the ffmpeg command is shown on stdout.

If this attribute is set to a coderef, then the following happens:

The ffmpeg command line that is executed gains "-progress /dev/stdout" parameters
The output of the ffmpeg command is parsed, and the completion percentage calculated (and all other output suppressed),
The coderef that was passed to this attribute is executed with the completion percentage as the only parameter whenever the percentage changes.

METHODS

run

Run the ffmpeg command.

If this method is not run at least once, the object's destructor will issue a warning.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 196:

=over should be: '=over' or '=over positive_number'