X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmpegtsenc.c;h=f4cb862bb9f50bee7dbe1ee05846d359e86fb7dd;hb=6372c9dc9972318e75a5889ad6c52500b8294099;hp=765672067a3c43f9e2665aa3f3cf0d027d9f5f7a;hpb=06278265239fe1aa6ef0f70d5e7db72ea5af844a;p=ffmpeg diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 765672067a3..f4cb862bb9f 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -56,6 +56,7 @@ typedef struct MpegTSService { int pcr_pid; int pcr_packet_count; int pcr_packet_period; + AVProgram *program; } MpegTSService; // service_type values as defined in ETSI 300 468 @@ -275,15 +276,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); if (s->nb_programs) { - int j, k, found = 0; - - for (j = 0; j < s->nb_programs; j++) - if (s->programs[j]->id == service->sid) { - for (k = 0; k < s->programs[j]->nb_stream_indexes; k++) - if (s->programs[j]->stream_index[k] == i) { - found = 1; - break; - } + int k, found = 0; + AVProgram *program = service->program; + + for (k = 0; k < program->nb_stream_indexes; k++) + if (program->stream_index[k] == i) { + found = 1; break; } @@ -295,7 +293,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) err = 1; break; } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: stream_type = STREAM_TYPE_VIDEO_MPEG2; @@ -360,19 +358,19 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) q += 2; /* patched after */ /* write optional descriptors here */ - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (st->codec->codec_id==AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { + if (st->codecpar->codec_id==AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { *q++=0x6a; // AC3 descriptor see A038 DVB SI *q++=1; // 1 byte, all flags sets to 0 *q++=0; // omit all fields... } - if (st->codec->codec_id==AV_CODEC_ID_EAC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { + if (st->codecpar->codec_id==AV_CODEC_ID_EAC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { *q++=0x7a; // EAC3 descriptor see A038 DVB SI *q++=1; // 1 byte, all flags sets to 0 *q++=0; // omit all fields... } - if (st->codec->codec_id==AV_CODEC_ID_S302M) { + if (st->codecpar->codec_id==AV_CODEC_ID_S302M) { *q++ = 0x05; /* MPEG-2 registration descriptor*/ *q++ = 4; *q++ = 'B'; @@ -380,7 +378,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 'S'; *q++ = 'D'; } - if (st->codec->codec_id==AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id==AV_CODEC_ID_OPUS) { /* 6 bytes registration descriptor, 4 bytes Opus audio descriptor */ if (q - data > SECTION_LENGTH - 6 - 4) { err = 1; @@ -398,12 +396,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 2; *q++ = 0x80; - if (st->codec->extradata && st->codec->extradata_size >= 19) { - if (st->codec->extradata[18] == 0 && st->codec->channels <= 2) { + if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) { + if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) { /* RTP mapping family */ - *q++ = st->codec->channels; - } else if (st->codec->extradata[18] == 1 && st->codec->channels <= 8 && - st->codec->extradata_size >= 21 + st->codec->channels) { + *q++ = st->codecpar->channels; + } else if (st->codecpar->extradata[18] == 1 && st->codecpar->channels <= 8 && + st->codecpar->extradata_size >= 21 + st->codecpar->channels) { static const uint8_t coupled_stream_counts[9] = { 1, 0, 1, 1, 2, 2, 2, 3, 3 }; @@ -429,14 +427,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) }; /* Vorbis mapping family */ - if (st->codec->extradata[19] == st->codec->channels - coupled_stream_counts[st->codec->channels] && - st->codec->extradata[20] == coupled_stream_counts[st->codec->channels] && - memcmp(&st->codec->extradata[21], channel_map_a[st->codec->channels-1], st->codec->channels) == 0) { - *q++ = st->codec->channels; - } else if (st->codec->channels >= 2 && st->codec->extradata[19] == st->codec->channels && - st->codec->extradata[20] == 0 && - memcmp(&st->codec->extradata[21], channel_map_b[st->codec->channels-1], st->codec->channels) == 0) { - *q++ = st->codec->channels | 0x80; + if (st->codecpar->extradata[19] == st->codecpar->channels - coupled_stream_counts[st->codecpar->channels] && + st->codecpar->extradata[20] == coupled_stream_counts[st->codecpar->channels] && + memcmp(&st->codecpar->extradata[21], channel_map_a[st->codecpar->channels-1], st->codecpar->channels) == 0) { + *q++ = st->codecpar->channels; + } else if (st->codecpar->channels >= 2 && st->codecpar->extradata[19] == st->codecpar->channels && + st->codecpar->extradata[20] == 0 && + memcmp(&st->codecpar->extradata[21], channel_map_b[st->codecpar->channels-1], st->codecpar->channels) == 0) { + *q++ = st->codecpar->channels | 0x80; } else { /* Unsupported, could write an extended descriptor here */ av_log(s, AV_LOG_ERROR, "Unsupported Opus Vorbis-style channel mapping"); @@ -444,12 +442,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } } else { /* Unsupported */ - av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codec->extradata[18]); + av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]); *q++ = 0xff; } - } else if (st->codec->channels <= 2) { + } else if (st->codecpar->channels <= 2) { /* Assume RTP mapping family */ - *q++ = st->codec->channels; + *q++ = st->codecpar->channels; } else { /* Unsupported */ av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping"); @@ -500,7 +498,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) const char default_language[] = "und"; const char *language = lang && strlen(lang->value) >= 3 ? lang->value : default_language; - if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { uint8_t *len_ptr; int extradata_copied = 0; @@ -519,9 +517,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) if (*language != '\0') language++; - if (st->codec->extradata_size - extradata_copied >= 5) { - *q++ = st->codec->extradata[extradata_copied + 4]; /* subtitling_type */ - memcpy(q, st->codec->extradata + extradata_copied, 4); /* composition_page_id and ancillary_page_id */ + if (st->codecpar->extradata_size - extradata_copied >= 5) { + *q++ = st->codecpar->extradata[extradata_copied + 4]; /* subtitling_type */ + memcpy(q, st->codecpar->extradata + extradata_copied, 4); /* composition_page_id and ancillary_page_id */ extradata_copied += 5; q += 4; } else { @@ -529,9 +527,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) * 0x10 - normal with no monitor aspect ratio criticality * 0x20 - for the hard of hearing with no monitor aspect ratio criticality */ *q++ = (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) ? 0x20 : 0x10; - if ((st->codec->extradata_size == 4) && (extradata_copied == 0)) { + if ((st->codecpar->extradata_size == 4) && (extradata_copied == 0)) { /* support of old 4-byte extradata format */ - memcpy(q, st->codec->extradata, 4); /* composition_page_id and ancillary_page_id */ + memcpy(q, st->codecpar->extradata, 4); /* composition_page_id and ancillary_page_id */ extradata_copied += 4; q += 4; } else { @@ -542,7 +540,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } *len_ptr = q - len_ptr - 1; - } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { uint8_t *len_ptr = NULL; int extradata_copied = 0; @@ -558,8 +556,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) if (*language != '\0') language++; - if (st->codec->extradata_size - 1 > extradata_copied) { - memcpy(q, st->codec->extradata + extradata_copied, 2); + if (st->codecpar->extradata_size - 1 > extradata_copied) { + memcpy(q, st->codecpar->extradata + extradata_copied, 2); extradata_copied += 2; q += 2; } else { @@ -594,7 +592,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } break; case AVMEDIA_TYPE_DATA: - if (st->codec->codec_id == AV_CODEC_ID_SMPTE_KLV) { + if (st->codecpar->codec_id == AV_CODEC_ID_SMPTE_KLV) { *q++ = 0x05; /* MPEG-2 registration descriptor */ *q++ = 4; *q++ = 'K'; @@ -784,6 +782,7 @@ static int mpegts_init(AVFormatContext *s) service->pmt.write_packet = section_write_packet; service->pmt.opaque = s; service->pmt.cc = 15; + service->program = program; } } @@ -807,6 +806,7 @@ static int mpegts_init(AVFormatContext *s) /* assign pids to each stream */ for (i = 0; i < s->nb_streams; i++) { + AVProgram *program; st = s->streams[i]; ts_st = av_mallocz(sizeof(MpegTSWriteStream)); @@ -824,6 +824,17 @@ static int mpegts_init(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } + + program = av_find_program_from_stream(s, NULL, i); + if (program) { + for (j = 0; j < ts->nb_services; j++) { + if (ts->services[j]->program == program) { + service = ts->services[j]; + break; + } + } + } + ts_st->service = service; /* MPEG pid values < 16 are reserved. Applications which set st->id in * this range are assigned a calculated pid. */ @@ -855,13 +866,13 @@ static int mpegts_init(AVFormatContext *s) ts_st->first_pts_check = 1; ts_st->cc = 15; /* update PCR pid by using the first video stream */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && service->pcr_pid == 0x1fff) { service->pcr_pid = ts_st->pid; pcr_st = st; } - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) { AVStream *ast; ts_st->amux = avformat_alloc_context(); if (!ts_st->amux) { @@ -879,7 +890,7 @@ static int mpegts_init(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - ret = avcodec_copy_context(ast->codec, st->codec); + ret = avcodec_parameters_copy(ast->codecpar, st->codecpar); if (ret != 0) goto fail; ast->time_base = st->time_base; @@ -887,8 +898,8 @@ static int mpegts_init(AVFormatContext *s) if (ret < 0) goto fail; } - if (st->codec->codec_id == AV_CODEC_ID_OPUS) { - ts_st->opus_pending_trim_start = st->codec->initial_padding * 48000 / st->codec->sample_rate; + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { + ts_st->opus_pending_trim_start = st->codecpar->initial_padding * 48000 / st->codecpar->sample_rate; } } @@ -916,14 +927,15 @@ static int mpegts_init(AVFormatContext *s) /* Arbitrary values, PAT/PMT will also be written on video key frames */ ts->sdt_packet_period = 200; ts->pat_packet_period = 40; - if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (!pcr_st->codec->frame_size) { + if (pcr_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int frame_size = av_get_audio_frame_duration2(pcr_st->codecpar, 0); + if (!frame_size) { av_log(s, AV_LOG_WARNING, "frame size not set\n"); service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * 512); + pcr_st->codecpar->sample_rate / (10 * 512); } else { service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * pcr_st->codec->frame_size); + pcr_st->codecpar->sample_rate / (10 * frame_size); } } else { // max delta PCR 0.1s @@ -1111,7 +1123,7 @@ static uint8_t *get_ts_payload_start(uint8_t *pkt) * NOTE: 'payload' contains a complete PES payload. */ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, - int64_t pts, int64_t dts, int key) + int64_t pts, int64_t dts, int key, int stream_id) { MpegTSWriteStream *ts_st = st->priv_data; MpegTSWrite *ts = s->priv_data; @@ -1121,10 +1133,10 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); - int force_pat = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; + int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; - av_assert0(ts_st->payload != buf || st->codec->codec_type != AVMEDIA_TYPE_VIDEO); - if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO); + if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { force_pat = 1; } @@ -1194,26 +1206,31 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = 0x01; is_dvb_subtitle = 0; is_dvb_teletext = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if (st->codec->codec_id == AV_CODEC_ID_DIRAC) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) *q++ = 0xfd; else *q++ = 0xe0; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - (st->codec->codec_id == AV_CODEC_ID_MP2 || - st->codec->codec_id == AV_CODEC_ID_MP3 || - st->codec->codec_id == AV_CODEC_ID_AAC)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codecpar->codec_id == AV_CODEC_ID_MP2 || + st->codecpar->codec_id == AV_CODEC_ID_MP3 || + st->codecpar->codec_id == AV_CODEC_ID_AAC)) { *q++ = 0xc0; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->codec_id == AV_CODEC_ID_AC3 && + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->codec_id == AV_CODEC_ID_AC3 && ts->m2ts_mode) { *q++ = 0xfd; + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { + *q++ = stream_id != -1 ? stream_id : 0xfc; + + if (stream_id == 0xbd) /* asynchronous KLV */ + pts = dts = AV_NOPTS_VALUE; } else { *q++ = 0xbd; - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { - if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { is_dvb_subtitle = 1; - } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { is_dvb_teletext = 1; } } @@ -1228,8 +1245,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, header_len += 5; flags |= 0x40; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && - st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; @@ -1243,8 +1260,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, * otherwise it will not play sound on blu-ray */ if (ts->m2ts_mode && - st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->codec_id == AV_CODEC_ID_AC3) { + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->codec_id == AV_CODEC_ID_AC3) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; @@ -1262,14 +1279,14 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } if (len > 0xffff) len = 0; - if (ts->omit_video_pes_length && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (ts->omit_video_pes_length && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { len = 0; } *q++ = len >> 8; *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle and data streams */ - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codec->codec_type == AVMEDIA_TYPE_DATA) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA) val |= 0x04; *q++ = val; *q++ = flags; @@ -1282,7 +1299,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pts(q, 1, dts); q += 5; } - if (pes_extension && st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ @@ -1293,7 +1310,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, /* For Blu-ray AC3 Audio Setting extended flags */ if (ts->m2ts_mode && pes_extension && - st->codec->codec_id == AV_CODEC_ID_AC3) { + st->codecpar->codec_id == AV_CODEC_ID_AC3) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ @@ -1451,6 +1468,15 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2; int64_t dts = pkt->dts, pts = pkt->pts; int opus_samples = 0; + int side_data_size; + char *side_data = NULL; + int stream_id = -1; + + side_data = av_packet_get_side_data(pkt, + AV_PKT_DATA_MPEGTS_STREAM_ID, + &side_data_size); + if (side_data) + stream_id = side_data[0]; if (ts->reemit_pat_pmt) { av_log(s, AV_LOG_WARNING, @@ -1478,15 +1504,15 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } ts_st->first_pts_check = 0; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { const uint8_t *p = buf, *buf_end = p + size; uint32_t state = -1; - int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codec->extradata_size : 0; + int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codecpar->extradata_size : 0; int ret = ff_check_h264_startcode(s, st, pkt); if (ret < 0) return ret; - if (extradd && AV_RB24(st->codec->extradata) > 1) + if (extradd && AV_RB24(st->codecpar->extradata) > 1) extradd = 0; do { @@ -1503,7 +1529,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) data = av_malloc(pkt->size + 6 + extradd); if (!data) return AVERROR(ENOMEM); - memcpy(data + 6, st->codec->extradata, extradd); + memcpy(data + 6, st->codecpar->extradata, extradd); memcpy(data + 6 + extradd, pkt->data, pkt->size); AV_WB32(data, 0x00000001); data[4] = 0x09; @@ -1511,7 +1537,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) buf = data; size = pkt->size + 6 + extradd; } - } else if (st->codec->codec_id == AV_CODEC_ID_AAC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "AAC packet too short\n"); return AVERROR_INVALIDDATA; @@ -1544,11 +1570,11 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) buf = data; } } - } else if (st->codec->codec_id == AV_CODEC_ID_HEVC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { int ret = check_hevc_startcode(s, st, pkt); if (ret < 0) return ret; - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "Opus packet too short\n"); return AVERROR_INVALIDDATA; @@ -1569,7 +1595,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) &side_data_size); if (side_data && side_data_size >= 10) { - trim_end = AV_RL32(side_data + 4) * 48000 / st->codec->sample_rate; + trim_end = AV_RL32(side_data + 4) * 48000 / st->codecpar->sample_rate; } ctrl_header_size = pkt->size + 2 + pkt->size / 255 + 1; @@ -1629,8 +1655,8 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) if ( ts_st2->payload_size && (ts_st2->payload_dts == AV_NOPTS_VALUE || dts - ts_st2->payload_dts > delay/2)) { mpegts_write_pes(s, st2, ts_st2->payload, ts_st2->payload_size, - ts_st2->payload_pts, ts_st2->payload_dts, - ts_st2->payload_flags & AV_PKT_FLAG_KEY); + ts_st2->payload_pts, ts_st2->payload_dts, + ts_st2->payload_flags & AV_PKT_FLAG_KEY, stream_id); ts_st2->payload_size = 0; } } @@ -1643,16 +1669,16 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) ts_st->opus_queued_samples + opus_samples >= 5760 /* 120ms */)) { mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size, ts_st->payload_pts, ts_st->payload_dts, - ts_st->payload_flags & AV_PKT_FLAG_KEY); + ts_st->payload_flags & AV_PKT_FLAG_KEY, stream_id); ts_st->payload_size = 0; ts_st->opus_queued_samples = 0; } - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { av_assert0(!ts_st->payload_size); // for video and subtitle, write a single pes packet mpegts_write_pes(s, st, buf, size, pts, dts, - pkt->flags & AV_PKT_FLAG_KEY); + pkt->flags & AV_PKT_FLAG_KEY, stream_id); ts_st->opus_queued_samples = 0; av_free(data); return 0; @@ -1684,7 +1710,7 @@ static void mpegts_write_flush(AVFormatContext *s) if (ts_st->payload_size > 0) { mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size, ts_st->payload_pts, ts_st->payload_dts, - ts_st->payload_flags & AV_PKT_FLAG_KEY); + ts_st->payload_flags & AV_PKT_FLAG_KEY, -1); ts_st->payload_size = 0; ts_st->opus_queued_samples = 0; } @@ -1741,11 +1767,11 @@ static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && AV_RB24(pkt->data) != 0x000001) ret = ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL); - } else if (st->codec->codec_id == AV_CODEC_ID_HEVC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && AV_RB24(pkt->data) != 0x000001) ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);