[FFmpeg-devel] requested change for mpegts.enc

Hill, Scott SHill at camber.com
Fri Apr 1 21:06:04 CEST 2011


I would like to request a change to the write_pmt function to output the
codec_tag for data streams.  This is necessary for transport streams
conforming to SMPTE RP 217

 

 

static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)

{

    //    MpegTSWrite *ts = s->priv_data;

    uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;

    int val, stream_type, i;

 

    q = data;

    put16(&q, 0xe000 | service->pcr_pid);

 

    program_info_length_ptr = q;

    q += 2; /* patched after */

 

    /* put program info here */

 

    val = 0xf000 | (q - program_info_length_ptr - 2);

    program_info_length_ptr[0] = val >> 8;

    program_info_length_ptr[1] = val;

 

    for(i = 0; i < s->nb_streams; i++) {

        AVStream *st = s->streams[i];

        MpegTSWriteStream *ts_st = (MpegTSWriteStream *)st->priv_data;

        AVMetadataTag *lang = av_metadata_get(st->metadata, "language",
NULL,0);

        switch(st->codec->codec_id) {

        case CODEC_ID_MPEG1VIDEO:

        case CODEC_ID_MPEG2VIDEO:

            stream_type = STREAM_TYPE_VIDEO_MPEG2;

            break;

        case CODEC_ID_MPEG4:

            stream_type = STREAM_TYPE_VIDEO_MPEG4;

            break;

        case CODEC_ID_H264:

            stream_type = STREAM_TYPE_VIDEO_H264;

            break;

        case CODEC_ID_DIRAC:

            stream_type = STREAM_TYPE_VIDEO_DIRAC;

            break;

        case CODEC_ID_MP2:

        case CODEC_ID_MP3:

            stream_type = STREAM_TYPE_AUDIO_MPEG1;

            break;

        case CODEC_ID_AAC:

            stream_type = STREAM_TYPE_AUDIO_AAC;

            break;

        case CODEC_ID_AC3:

            stream_type = STREAM_TYPE_AUDIO_AC3;

            break;

        default:

            stream_type = STREAM_TYPE_PRIVATE_DATA;

            break;

        }

        *q++ = stream_type;

        put16(&q, 0xe000 | ts_st->pid);

        desc_length_ptr = q;

        q += 2; /* patched after */

 

        /* write optional descriptors here */

        switch(st->codec->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            if (lang && strlen(lang->value) == 3) {

                *q++ = 0x0a; /* ISO 639 language descriptor */

                *q++ = 4;

                *q++ = lang->value[0];

                *q++ = lang->value[1];

                *q++ = lang->value[2];

                *q++ = 0; /* undefined type */

            }

            break;

        case AVMEDIA_TYPE_SUBTITLE:

            {

                const char *language;

                language = lang && strlen(lang->value)==3 ? lang->value
: "eng";

                *q++ = 0x59;

                *q++ = 8;

                *q++ = language[0];

                *q++ = language[1];

                *q++ = language[2];

                *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb)
*/

                put16(&q, 1); /* page id */

                put16(&q, 1); /* ancillary page id */

            }

            break;

        case AVMEDIA_TYPE_VIDEO:

            if (stream_type == STREAM_TYPE_VIDEO_DIRAC) {

                *q++ = 0x05; /*MPEG-2 registration descriptor*/

                *q++ = 4;

                *q++ = 'd';

                *q++ = 'r';

                *q++ = 'a';

                *q++ = 'c';

            }

            break;

 

 

            //////////////////////////////////////smh

        case AVMEDIA_TYPE_DATA:

                *q++ = 0x05; /*MPEG-2 registration descriptor*/

                *q++ = 4;

                        *q++ = (st->codec->codec_tag & 0x000000ff);

                        *q++ = (st->codec->codec_tag & 0x0000ff00) >> 8;

                        *q++ = (st->codec->codec_tag & 0x00ff0000) >>
16;

                        *q++ = (st->codec->codec_tag & 0xff000000) >>
24;

                  break;

            ////////////////////////////////////////////////

 

        }

 

 

        val = 0xf000 | (q - desc_length_ptr - 2);

        desc_length_ptr[0] = val >> 8;

        desc_length_ptr[1] = val;

    }

    mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0,

                          data, q - data);

}

 



More information about the ffmpeg-devel mailing list