Multiplexing multiple single video MPEG-TS into MPTS using ffmpeg

Aleks picture Aleks · Jul 14, 2015 · Viewed 7.4k times · Source

I tried to find a solution for multiplexing different inputs (ts) into one MPTS, so that can be used as input for DVB-T modulator. Basically, what I want is to select certain TS provided by satellite receiver, repack them into one MPTS and send to the modulator. Currently, I have managed to do it with one stream, using following command:

  ~/DATVRelease/ffmpeg \
 -re -i URL_SINGLE_INPUT_TS_STREAM  -vcodec copy -acodec copy \
 -f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 \
 -mpegts_service_id 1 -mpegts_pmt_start_pid 1000 -mpegts_start_pid 1001 \
 -metadata service_provider="YOUR CALL" \
 -metadata service_name="N1 (ALEKSANDAR)" \
 ~/dvb/videots

where the videots is fifo pipe produced by mkfifo command. The following code produced the result on receiver side:

http://i.stack.imgur.com/BZugM.jpg

There is a -map function in ffmpeg where I can add multiple audio channels / or video channels, but they wont be on the receiver side detected as different services TV channels, because in my understanding the adequate PMT table must be created (iso13818)

The only open source I could find is this one http://www.scara.com/~schirmer/o/mplex13818/ , but I still wonder if ffmpeg could do this work for me?

Answer

Hs Zhang picture Hs Zhang · Sep 12, 2017

Here is the basic command to generate one MPEG2 TS file containing multiple programs.

ffmpeg -i FirstInput -i SecondInput \
-map 0:0 -map 0:1 -map 1:0 -map 1:1 \
-program title=ProgOne:st=0:st=1 -program title=ProgTwo:st=2:st=3 \
-f mpegts mpts.ts

Belowing is simple illustrations for every option.

-i FirstInput -i SecondInput 

Select the source files which contains the elementary streams you want to multiplex into the output MPTS

-map 0:0 -map 0:1 -map 1:0 -map 1:1

Select the particular elementry streams you want to multiplex into the output MPTS. The streams will be indexed from zero. Here we select the first and second streams for both files. Normally they correspond to the video and audio stream. See the Advance options chapter of FFmpeg documentation and wiki for -map.

-program title=ProgOne:st=0:st=1 -program ProgTwo:st=2:st=3

Tell FFmpeg to generate two programs in the output MPTS. Here title gives the service_name in SDT. st= specifies the streams put in the corresponding program. See the Main options chapter of FFmpeg ddocumentation

-f mpegts

Tell FFmpeg use mpegts muxer in case that it cannot be inferred from the suffix of output file.

The key options are -map and -program to multiplex several programs in one output. The enhancement was added in this commit according to issue 4734 and issue 4525.

Obviously more options can be added to tune the behaviour, such as codec type, bitrate control, quality control and etc.