Jindřich Makovička <[email protected]> writes:

> Hi,
>
> currently, the MPEG-TS muxer does not set the Random Access indicator
> in the TS packet adaptation field. This causes problems with some DVB
> recorders (tested on Motorola set-top boxes) which refuse to record
> streams produced by libav.
>
> This patch adds the RA indicator to the starting packet of a each key frame.
>
> -- 
> Jindrich Makovicka
>
> From 92548fcaa1219e1673f8dd33f71fd796fabe5a43 Mon Sep 17 00:00:00 2001
> From: Jindrich Makovicka <[email protected]>
> Date: Thu, 5 May 2011 14:33:32 +0200
> Subject: [PATCH] set Random Access indicator on keyframe start packets
>
> needed for some DVB recorders
>
> Signed-off-by: Jindrich Makovicka <[email protected]>
> ---
>  libavformat/mpegtsenc.c |   36 ++++++++++++++++++++----------------
>  1 files changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index bf66aa0..db2920d 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -693,7 +693,7 @@ static void write_pts(uint8_t *q, int fourbits, int64_t 
> pts)
>   */
>  static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
>                               const uint8_t *payload, int payload_size,
> -                             int64_t pts, int64_t dts)
> +                             int64_t pts, int64_t dts, int key)
>  {
>      MpegTSWriteStream *ts_st = st->priv_data;
>      MpegTSWrite *ts = s->priv_data;
> @@ -738,18 +738,21 @@ static void mpegts_write_pes(AVFormatContext *s, 
> AVStream *st,
>          *q++ = val;
>          *q++ = ts_st->pid;
>          ts_st->cc = (ts_st->cc + 1) & 0xf;
> -        *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);
> -        if (write_pcr) {
> -            // add 11, pcr references the last byte of program clock 
> reference base
> -            if (ts->mux_rate > 1)
> -                pcr = get_pcr(ts, s->pb);
> -            else
> -                pcr = (dts - delay)*300;
> -            if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
> -                av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
> -            *q++ = 7; /* AFC length */
> -            *q++ = 0x10; /* flags: PCR present */
> -            q = write_pcr_bits(q, pcr);
> +        *q++ = 0x10 | ts_st->cc | ((write_pcr || (key && is_start)) ? 0x20 : 
> 0);
> +        if (write_pcr || (key && is_start)) {
> +            *q++ = 1 + (write_pcr ? 6 : 0); /* AFC length */
> +            /* flags: PCR present, Random Access on keyframe */
> +            *q++ = (write_pcr ? 0x10 : 0) | ((key && is_start) ? 0x40 : 0);
> +            if (write_pcr) {
> +                // add 11, pcr references the last byte of program clock 
> reference base
> +                if (ts->mux_rate > 1)
> +                    pcr = get_pcr(ts, s->pb);
> +                else
> +                    pcr = (dts - delay)*300;
> +                if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
> +                    av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
> +                q = write_pcr_bits(q, pcr);
> +            }
>          }

I get the distinct feeling this could be done in a tidier way.

-- 
Måns Rullgård
[email protected]
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to