Media::Convert::Pipe(3pm) | User Contributed Perl Documentation | Media::Convert::Pipe(3pm) |
Media::Convert::Pipe - class to generate ffmpeg command lines with Media::Convert::Asset
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();
"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.
The following attributes are supported by "Media::Convert::Pipe".
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.
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.
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".
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.
The same as "vcopy", but for audio rather than video.
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.
The same as "vskip", but for audio rather than video.
Boolean. If true, the "run" method performs a two-pass encode, rather than a single-pass encode.
Two-pass encodes will generate a better end result, but require more time to perform.
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:
Run the ffmpeg command.
If this method is not run at least once, the object's destructor will issue a warning.
Hey! The above document had some coding errors, which are explained below:
2023-03-07 | perl v5.36.0 |