[FFmpeg-devel] [PATCH] * mpegts demuxer should recognize private streams
Wolfgang Lorenz
wl-chmw at gmx.de
Fri May 29 22:45:47 CEST 2015
The patch addresses this problem:
https://lists.ffmpeg.org/pipermail/libav-user/2014-September/007475.html
What it does is this:
* Except stream type 0x06 as a private stream. (AVMEDIA_TYPE_DATA, AV_CODEC_ID_NONE)
(It was necessary to convince mpegts_set_stream_info(), that AV_CODEC_ID_NONE
might be a valid codec id.)
* Handle stream id 0xbd (private_stream_1). This stream uses PES headers, but needs
no further parsing (as there is no codec defined).
---
libavformat/mpegts.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index aeb2335..4025bcf 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -689,6 +689,7 @@ static const StreamType ISO_types[] = {
{ 0x02, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO },
{ 0x03, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
{ 0x04, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
+ { 0x06, AVMEDIA_TYPE_DATA, AV_CODEC_ID_NONE },
{ 0x0f, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC },
{ 0x10, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG4 },
/* Makito encoder sets stream type 0x11 for AAC,
@@ -756,13 +757,13 @@ static const StreamType DESC_types[] = {
{ 0 },
};
-static void mpegts_find_stream_type(AVStream *st,
- uint32_t stream_type,
- const StreamType *types)
+static int mpegts_find_stream_type(AVStream *st,
+ uint32_t stream_type,
+ const StreamType *types)
{
if (avcodec_is_open(st->codec)) {
av_log(NULL, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");
- return;
+ return 0;
}
for (; types->stream_type; types++)
@@ -770,8 +771,10 @@ static void mpegts_find_stream_type(AVStream *st,
st->codec->codec_type = types->codec_type;
st->codec->codec_id = types->codec_id;
st->request_probe = 0;
- return;
+ return 1;
}
+
+ return 0;
}
static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
@@ -779,6 +782,7 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
{
int old_codec_type = st->codec->codec_type;
int old_codec_id = st->codec->codec_id;
+ int new_codec_found;
if (avcodec_is_open(st->codec)) {
av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");
@@ -799,11 +803,12 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
st->codec->codec_tag = pes->stream_type;
- mpegts_find_stream_type(st, pes->stream_type, ISO_types);
+ new_codec_found = mpegts_find_stream_type(st, pes->stream_type, ISO_types);
if ((prog_reg_desc == AV_RL32("HDMV") ||
prog_reg_desc == AV_RL32("HDPR")) &&
- st->codec->codec_id == AV_CODEC_ID_NONE) {
- mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
+ st->codec->codec_id == AV_CODEC_ID_NONE &&
+ !new_codec_found) {
+ new_codec_found = mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
if (pes->stream_type == 0x83) {
// HDMV TrueHD streams also contain an AC3 coded version of the
// audio track - add a second stream for this
@@ -829,13 +834,19 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
sub_pes->sub_st = pes->sub_st = sub_st;
}
}
- if (st->codec->codec_id == AV_CODEC_ID_NONE)
- mpegts_find_stream_type(st, pes->stream_type, MISC_types);
- if (st->codec->codec_id == AV_CODEC_ID_NONE) {
+ if (st->codec->codec_id == AV_CODEC_ID_NONE &&
+ !new_codec_found)
+ new_codec_found = mpegts_find_stream_type(st, pes->stream_type, MISC_types);
+ if (st->codec->codec_id == AV_CODEC_ID_NONE &&
+ !new_codec_found) {
st->codec->codec_id = old_codec_id;
st->codec->codec_type = old_codec_type;
}
-
+ if (new_codec_found &&
+ st->codec->codec_id == AV_CODEC_ID_NONE &&
+ st->codec->codec_type == AVMEDIA_TYPE_DATA) {
+ st->need_parsing = 0;
+ }
return 0;
}
@@ -1036,7 +1047,9 @@ static int mpegts_push_data(MpegTSFilter *filter,
code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */
code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */
pes->state = MPEGTS_PESHEADER;
- if (pes->st->codec->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) {
+ if (code == 0x1bd) { /* private_stream_1 */
+ pes->st->need_parsing = 0;
+ } else if (pes->st->codec->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) {
av_log(pes->stream, AV_LOG_TRACE,
"pid=%x stream_type=%x probing\n",
pes->pid,
--
1.9.1
More information about the ffmpeg-devel
mailing list