Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPEG-TS Encoding

I have a file that i need to convert to MPEG-TS so that it fits the below specification:

Elementary stream bitrate [kbit/s] video: 2575 audio: 2 x 192 subtitle: - PAT/PMT: - Stuffing: -

Component TS bitrate [kbit/s] video: 2652 audio: 395 subtitle: 45 PAT/PMT: 45 Stuffing: 62 Total: 3200 CBR

Additional required components: PAT PMT Null packets

Components that might pop up: NIT, SDT, EIT, etc.

vcodec="h264"
acodec="mpga"
bitrate="2500"
arate="192"
samplerate=48000
ext="mpg"
mux="ts"
vlc="/usr/bin/vlc"
fmt="mpg"
dst="/home/adam/test/"

for a in *$fmt; do
$vlc -I dummy -vvv "/home/adam/test/" --sout "#transcode{vcodec=$vcodec,venc=x264{profile=main,level=3.0,hrd=cbr,bframes=2},vb=$bitrate,acodec=$acodec,ab=$arate,samplerate=$samplerate,channels=2}:standard{mux=$mux,dst=\"$dst$a.$ext\",ac$
done

After encoding with the above script everything seems to be ok (for both video and audio bitrate codec is constant) apart from two things: Bitrate of the container should also remain CBR but this is not the case. Also, stuffing component (0x1 ffff) - null packet is missing. Is it possible for you to correct the script to make null packet as well as bitrate of the container constant (3,2 Mbps CBR) ?

The second option is encoding with ffmpeg:

ffmpeg -i video_input.mpg -i audio_input.mp2 -acodec copy -tune zerolatency -x264opts bitrate=2600:vbv-maxrate=2600:vbv-bufsize=166:nal_hrd=cbr -vpre libx264-iptv -vcodec libx264 -f mpegts -muxrate 3200K -y output.ts

but how to unset/disable/remove SDT table?

like image 225
adismsc Avatar asked Nov 25 '11 13:11

adismsc


People also ask

What is MPEG TS file format?

MPEG transport stream (transport stream, MPEG-TS, MTS or TS) is a standard digital container format for transmission and storage of audio, video, and Program and System Information Protocol (PSIP) data. It is used in broadcast systems such as DVB, ATSC and IPTV.

How do I Configure my MPEG-TS encoder for live streaming?

Note: Consult your MPEG-TS encoder documentation for information about how to configure an outgoing live stream. In Wowza Streaming Engine Manager, click Server in the menu bar and then click Stream Files in the contents panel. Click Add Stream File. In the Add Stream File dialog box, enter a name for the stream file, for example, mpegts.stream .

Where can I find the documentation on MPEG encoding?

Documentation on MPEG encoding in general can be found in the MJPEG Howto and on the various available parameters in the documentation of the mpeg2enc tool in particular, which shares options with this element. This example pipeline will encode a test video source to a an MPEG1 elementary stream (with Generic MPEG1 profile).

What is the encoding standard for video files?

Video encoding standard. MPEG-2 is used in Digital Video Broadcast and DVDs. The MPEG transport stream, TS, and MPEG program stream, PS, are container formats. MPEG-2 (a.k.a. H.222/H.262 as was defined by the ITU) is a standard for "the generic coding of moving pictures and associated audio information".


1 Answers

Given that you are aware of the concept of NULL packets, you might have been working with commercial grade software or hardware in this area.

There is a difference between CBR (of video) and system rate (or multiplexer rate). When video is encoded as CBR, say at 3.2 Mbps, it is quite ok that it fluctuate by a few hundred kbps around that margin. So peak bitrate, could be say 3.3 Mbps. This is quite ok. Adding another 100 kbps of Audio, the total maximum bitrate can be 3.4. Usually, one would set the System rate above 3.6 Mbps or more in that case; where balance are NULL packets.

The system rate 3.5 Mbps CANNOT fluctuate at all. If it does, the PCR based synchronization wont work and basically, things wont work in live environment. So basically, you can think of 3.5 Mbps (about 240 packets in 100 milisecond) can be thought of as a BUS. every seat must be filled up to ensure that transportation is continuous. Usually, it is done such a way that few seats will remain empty.

The sad part is, neither VLC nor any other tool in open source will do it for you.

The hack we used to use was, that we used to send such VLC produced stream over IP (where sending TS stream without NULL packets is ok - and receive that via the output from a Muxer with ASI or such interface, which would have added muxer.

Alternatively you can use Manzanita muxer to convert your Non-null TS stream to proper TS stream.

EDIT:
Based on the comment - if all you need to do is to disable SDT - there are two things needs to be done.

  1. Remove all packets from the PID that corresponds to SDT table. If you are not fully demuxing and re-muxing - a quick way to do that could be to re-stamp the 13 bit PID number by a NULL packet PID number.

  2. Remove the reference of SDT PID value in PAT table. This essentially means that you produce a 3 to 4 packets which is corrected PAT; and replace all PAT packet sequences in the stream by these corrected packets.

like image 70
Dipan Mehta Avatar answered Oct 18 '22 05:10

Dipan Mehta