diff mbox

[FFmpeg-devel] avformat/mpegts: fix teletext PTS when selecting teletext streams only

Message ID 20190823230433.15055-1-cus@passwd.hu
State Accepted
Commit 765c56bfa9037060e36250090880b2961c88f27d
Headers show

Commit Message

Marton Balint Aug. 23, 2019, 11:04 p.m. UTC
After a1b4f120c031e6697bac9fd8c725d9c37ee36d13 the teletext PTS values were set
to AV_NOPTS_VALUE if the stream of the PCR pid was discarded.

What actually matters is that if we parse the PCR of the PCR PID or not, so
let's use the cached discard value of the actual PCR PID instead of the stream
discard value, which may be different.

Also fixes ticket #7567, which was caused by the fact that teletext PTS values
were not touched if the PCR pid was discarded even before
a1b4f120c031e6697bac9fd8c725d9c37ee36d13.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mpegts.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jan Ekström Aug. 28, 2019, 4:43 p.m. UTC | #1
On Sat, Aug 24, 2019 at 2:04 AM Marton Balint <cus@passwd.hu> wrote:
>
> After a1b4f120c031e6697bac9fd8c725d9c37ee36d13 the teletext PTS values were set
> to AV_NOPTS_VALUE if the stream of the PCR pid was discarded.
>
> What actually matters is that if we parse the PCR of the PCR PID or not, so
> let's use the cached discard value of the actual PCR PID instead of the stream
> discard value, which may be different.
>
> Also fixes ticket #7567, which was caused by the fact that teletext PTS values
> were not touched if the PCR pid was discarded even before
> a1b4f120c031e6697bac9fd8c725d9c37ee36d13.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---

I just hit this myself, and this seems to indeed fix the case where
you f.ex. -map only the teletext stream with ffmpeg.c and output f.ex.
SRT. So in that sense this seems like a sensible change.

Would be much obliged if someone could run this through FATE? I will
attempt during this week to create a minimal sample so we could get a
FATE test for this behavior :) (as this is demux-only).

Best regards,
Jan
Marton Balint Aug. 31, 2019, 4:22 p.m. UTC | #2
On Wed, 28 Aug 2019, Jan Ekström wrote:

> On Sat, Aug 24, 2019 at 2:04 AM Marton Balint <cus@passwd.hu> wrote:
>>
>> After a1b4f120c031e6697bac9fd8c725d9c37ee36d13 the teletext PTS values were set
>> to AV_NOPTS_VALUE if the stream of the PCR pid was discarded.
>>
>> What actually matters is that if we parse the PCR of the PCR PID or not, so
>> let's use the cached discard value of the actual PCR PID instead of the stream
>> discard value, which may be different.
>>
>> Also fixes ticket #7567, which was caused by the fact that teletext PTS values
>> were not touched if the PCR pid was discarded even before
>> a1b4f120c031e6697bac9fd8c725d9c37ee36d13.
>>
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>
> I just hit this myself, and this seems to indeed fix the case where
> you f.ex. -map only the teletext stream with ffmpeg.c and output f.ex.
> SRT. So in that sense this seems like a sensible change.

Thanks, applied.

> Would be much obliged if someone could run this through FATE? I will
> attempt during this week to create a minimal sample so we could get a
> FATE test for this behavior :) (as this is demux-only).

Yeah, seems useful.

Regards,
Marton
diff mbox

Patch

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 47d8d5f877..58902527c5 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1303,15 +1303,17 @@  skip:
                                             st = pst;
                                     }
                                 }
-                                if (f->last_pcr != -1 && st && st->discard != AVDISCARD_ALL) {
+                                if (f->last_pcr != -1 && !f->discard) {
                                     // teletext packets do not always have correct timestamps,
                                     // the standard says they should be handled after 40.6 ms at most,
                                     // and the pcr error to this packet should be no more than 100 ms.
                                     // TODO: we should interpolate the PCR, not just use the last one
                                     int64_t pcr = f->last_pcr / 300;
                                     pcr_found = 1;
-                                    pes->st->pts_wrap_reference = st->pts_wrap_reference;
-                                    pes->st->pts_wrap_behavior = st->pts_wrap_behavior;
+                                    if (st) {
+                                        pes->st->pts_wrap_reference = st->pts_wrap_reference;
+                                        pes->st->pts_wrap_behavior = st->pts_wrap_behavior;
+                                    }
                                     if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) {
                                         pes->pts = pes->dts = pcr;
                                     } else if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT &&