[FFmpeg-devel] [PATCH 1/6] avformat/mpegtsenc: fix incorrect PCR selection with multiple programs

Andreas Håkon andreas.hakon at protonmail.com
Fri Aug 9 10:44:50 EEST 2019


Hi Marton,

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, 8 de August de 2019 23:27, Marton Balint <cus at passwd.hu> wrote:

> The MPEG-TS muxer had a serious bug related to the use of multiple programs:
> in that case, the PCR pid selection was incomplete for all services except one.
> This patch solves this problem and selects a stream to become PCR for each
> service, preferably the video stream.
>
> This patch also moves pcr calculation attributes to MpegTSWriteStream from
> MpegTSService. PCR is a per-stream and not per-service thing, so it was
> misleading to refer to it as something that is per-service.
>
> Also remove *service from MpegTSWriteStream because a stream can belong to
> multiple services so it was misleading to select one for each stream.
>
> You can check the result with this example command:
>
> ./ffmpeg -loglevel verbose -y -f lavfi -i \
> "testsrc=s=64x64:d=10,split=2[out0][tmp1];[tmp1]vflip[out1];sine=d=10,asetnsamples=1152[out2]" \
> -flags +bitexact -fflags +bitexact -sws_flags +accurate_rnd+bitexact \
> -codec:v libx264 -codec:a mp2 -pix_fmt yuv420p \
> -map '0:v:0' \
> -map '0:v:1' \
> -map '0:a:0' \
> -program st=0:st=2 -program st=1:st=2 -program st=2 -program st=0 -f mpegts out.ts

I recommend this small change to the test:

./ffmpeg -loglevel verbose -y -f lavfi -i \
  "testsrc=s=64x64:d=10,split=2[out0][tmp1];[tmp1]vflip[out1];sine=d=10,asetnsamples=1152[out2]" \
  -flags +bitexact -fflags +bitexact -sws_flags +accurate_rnd+bitexact  \
  -codec:v libx264 -r:v:0 1 -r:v:1 25 -b:v:0 1000k -b:v:1 1500k -pix_fmt yuv420p \
  -codec:a mp2 \
  -map '0:v:0' \
  -map '0:v:1' \
  -map '0:a:0' \
  -program st=0:st=2 -program st=1:st=2 -program st=2 -program st=0 \
  -f mpegts -muxrate 1M out.ts

CBR it's required and the use of different bitrates it's desirable.

> You should now see this:
>
> [mpegts @ 0x37505c0] service 1 using PCR in pid=256
> [mpegts @ 0x37505c0] service 2 using PCR in pid=257
> [mpegts @ 0x37505c0] service 3 using PCR in pid=258
> [mpegts @ 0x37505c0] service 4 using PCR in pid=256

Updated output:

[mpegts @ 0x33473c0] service 1 using PCR in pid=256, pcr_period=20ms
[mpegts @ 0x33473c0] service 2 using PCR in pid=257, pcr_period=20ms
[mpegts @ 0x33473c0] service 3 using PCR in pid=258, pcr_period=20ms
[mpegts @ 0x33473c0] service 4 using PCR in pid=256, pcr_period=20ms
[mpegts @ 0x33473c0] muxrate 1000000, sdt every 332, pat/pmt every 66 pkts

[...]

Regards.
A.H.

---



More information about the ffmpeg-devel mailing list