Set PAT/PMT period using ffmpeg

6,285

Solution 1

Ffmpeg's mpegts muxer defaults to 100 ms between PAT/PMT tables anyway but you can set it explicitly with -pat_period 0.1.

Any value over 0.4 is likely to cause your analyzer to throw priotity 1 PAT errors as defined in ETSI TR 101 290, p. 17.

Solution 2

I am also trying to change the -pat_period. However i have been unsuccessful so far. But would like to share my research. I have checked in source file of mpegtsenc.c following code explains how it works as shown below: Note this is for reference to the code.

if (ts->mux_rate > 1) {
   service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME)
               (TS_PACKET_SIZE * 8 * 1000);
   ts->sdt_packet_period      = (ts->mux_rate * SDT_RETRANS_TIME)
               (TS_PACKET_SIZE * 8 * 1000);
   ts->pat_packet_period      = (ts->mux_rate * PAT_RETRANS_TIME)
               (TS_PACKET_SIZE * 8 * 1000);

define values are as follow:

#define SDT_RETRANS_TIME 500
#define PAT_RETRANS_TIME 100
#define PCR_RETRANS_TIME 20
#define TS_PACKET_SIZE 188

if you calculate the values you will get pcr value correct according to expression. In this example i provided 7 value to -pat_period, -sdt_period, -pcr_period and muxrate 6500000. You get value for PCR but whatever value you try for SDT or PAT it transmits after every 2147483647 pkts.

Example for PCR

6500000 * 7 / 188 * 8 * 1000 = 45500000 / 1504000 = 30.25265957446809

As you can see the debug line of ffmpeg shows PCR is transmitted after evey 30 pkts. But this is not the case for SDT/PAT.

> [mpegts @ 0x22862c0] muxrate 6500000, pcr every 30 pkts, sdt every
> 2147483647, pat/pmt every 2147483647 pkts

For PAT / SDT we should have similar but actual value is different not what is expected. I am still working on it. Thought to share my findings. I will appreciate if experts can help.

Also would like to know if you can suggest how you achieved 78 for PAT? How did you verify that it is after every 78 pkts?

Workaround are:

1) You can define your desired value in source code, compile and keep testing until you get result. 2) Increase the muxrate unless you get desired result, but it costs a lot bandwidth consumption. increasing will bring down the number of packets after which PAT shall be transmit

Update: My bad no it does not make any difference to TS actually it increases to PAT/PMT duration to 483ms which peaks above 500ms and generates alarm on analyser.

Solution 3

Due to reputations I am unable to comment that is why I am adding as answer to your reply. Glad you have find the solution but I can see some parameters are not necessary in your command line for instance you do not need argument '-f mpegts' time as highlighted below:

-f mpegts -threads 8 -f mpegts -sn -mpegts_start_pid 0x150

should be enough like this

-threads 8 -sn -f mpegts -mpegts_start_pid 0x150

This -mpegts_start_pid 0x150 should not make any difference I guess it can be PMT pid value you may want to look into. also check I have updated my findings.

Share:
6,285

Related videos on Youtube

elbatron
Author by

elbatron

Updated on September 18, 2022

Comments

  • elbatron
    elbatron over 1 year

    According to the ffmpeg documentation using -pat_period sets the maximal time in seconds between PAT/PMT tables.

    I'd like to set the value to 100ms, however I'm not getting the desired value.

    The code I'm using:

    -map 0:0 -map 0:1 -c:a ac3 -ab 384k -ar 48000 -ac 6 -async 1 -streamid 1:0x102 -streamid 0:0x101 -c:v libx264 -pat_period 100 -crf 20 -b:v 7800k -minrate 7800k -maxrate 7800k -muxrate 8250K -bufsize 700k -r 25 -force_fps -s 1920x1080 -aspect 16:9 -profile:v high422 -level 40 -partitions default -b-pyramid 1 -weightb 0 -8x8dct 0 -fast-pskip 0 -rc-lookahead 40 -x264-params force-cfr=1 -trellis 1 -me_method hex -sws_flags fast_bilinear -sc_threshold 40 -keyint_min 25  -g 50 -bf 3 -qmin 3 -qmax 51 -f mpegts  -copyts -threads 8 -f mpegts -sn
    

    I experimented with different values instead of using 100 (which results 78) without getting 100.

    Could somebody please point me in the right direction? I assume I miss something or I'm not converting the values right.

  • elbatron
    elbatron over 7 years
    Thanks for sharing your findings. I'm using MPEG-2 Transport Stream analyser (Win) to calculate the actual occurrences (or rather the distance between 2) in a given file.
  • elbatron
    elbatron over 7 years
    You're right, -f mpegts is not necessary. Note, that bufsize, muxrate, CBR bitrate for both video and audio are strictly specified (along with many other aspects) in my case, so I could not play with those. Using -pat_period didn't make any difference. (I got 78 for a 2 min testfile), while adding -mpegts_start_pid 0x150 yielded the required 100ms PAT/PMT.
  • Sherry
    Sherry over 7 years
    @elbatron have you tired the -mpegts_flags with resend_headers or pat_pmt_at_frames
  • elbatron
    elbatron over 7 years
    No, actually as soon as I ended up with 100 or close to 100 PAT/PMT my files were accepted and I encoded and transferred all the films. I haven't bothered with the problem since then.
  • drake7
    drake7 about 3 years
    This is not correct, mpegts_start_pid has nothing to do with that. The reason why you get 100 ms is because Ffmpeg defaults to this value. The OP made a mistake. 100 ms can be set with -pat_period 0.1.