View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Steve Price > Linux-DVB-DVBT-2.18 > Linux::DVB::DVBT::Ffmpeg



Annotate this POD


New  3
Open  0
View/Report Bugs
Module Version: 2.10   Source   Latest Release: Linux-DVB-DVBT-2.20


Linux::DVB::DVBT::Ffmpeg - Helper module for transcoding recorded streams


        use Linux::DVB::DVBT::Ffmpeg ;


Module provides a set of useful routines used for transcoding the recorded .ts transport stream file into mpeg/mp4 etc. Use of these routines is entirely optional and does not form part of the base DVBT functionality.

Currently supported file formats are:

.mpeg - mpeg2 video / audio / subtitles
.mp4 - mpeg4 video / audio

The mp4 settings are configured to ensure that the file is compatible with playback on the PS3 (server by Twonky media server).

Note: if you use this then be prepared for a long wait! On my system, a 2 hour film can take 13 hours to transcode.

.m2v - mpeg2 video
.mp2 - mpeg2 audio
.mp3 - mpeg3 audio

You may notice ffmpeg reports the error:

        lame: output buffer too small

Apparently (accoriding to the ffmpeg developers) this is perfectly fine. For further details see (

Obviously, ffmpeg must be installed on your machine to run these functions.


I don't intend to support every possible option in ffmpeg! These routines are provided as being helpful, but you can ignore them if you don't like them.

Helpful suggestions/requests may result in my adding functionality, but I don't promise anything!


ts_transcode($srcfile, $destfile, $multiplex_info_href, [$written_files_href])

Transcode the recorded transport stream file into the required format, as specified by $multiplex_info_href.

(Called by Linux::DVB::DVBT::multiplex_transcode()).

Multiplex info HASH ref is of the form:

                'pids'  => [
                                'pid'   => Stream PID
                                'pidtype'       => pid type (video, audio, subtitle)
                'errors' => [],
                'warnings' => [],
                'lines' => [],

                'destfile'      => final written file name (set by this function)

$written_files_href is an optional HASH that may be provided by the calling routine to track which files have been written. Since the file type (extension) can be adjusted by the routine to match it's supported formats/codecs, there is the chance that a file may be accidently over written. The tracking HASH ensures that, if a file was previously written with the same filename, then the new file is written with a unique filename.

The 'errors' and 'warnings' ARRAY refs are filled with any error/warning messages as the routine is run. Also, the 'lines' ARRAY ref is filled with the ffmpeg output.

If $destfile is undefined, then the routine just checks that $srcfile duration is as expected; setting the errors array if not.

When $destfile is defined, it's file type is checked to ensure that the number of streams (pids) and the stream types are supported for this file. If not, then the next preferred file type is used and the destination file adjusted accordingly. The final written destination filename is written into the HASH as 'destfile'.

The routine returns 0 on success; non-zero for any error.

sanitise_options($destfile_ref, $out_ref, $lang_ref)

Processes the destination file, the requested output spec (if any), and the language spec (if any) to ensure they are set to a valid combination of settings which will result in a supported file format being written. Adjusts/sets the values accordingly.

If defined, the output spec (and language) always has precedence over the specified file format and the file format (i.e. extension) will be adjusted to match the required output.

This is used when scheduling recording of multiple channels in the multiplex. This routine ensures that the correct streams are added to the recording.


Uses ffmpeg to determine the video file duration. Returns the duration in seconds.


Uses ffmpeg to determine the video file contents. Returns a HASH containing:

        'input' => Input number
        'duration' => video duration in seconds
        'pids'  => {
                $pid    => {
                        'input'         => input number that this pid is part of
                        'stream'        => stream number
                        'lang'          => audio language
                        'pidtype'               => pid type (video, audio, subtitle)
run_transcoder($args[, $lines_aref])

Run the transcoder command with the provided arguments. If the $lines_aref ARRAY ref is supplied, then the output lines from ffmpeg are returned in that array (one entry per line).

Returns the exit status from ffmpeg.

syntax highlighting: