[FFmpeg-cvslog] avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

zheng qian git at videolan.org
Wed Apr 28 22:39:33 EEST 2021


ffmpeg | branch: master | zheng qian <xqq at xqq.im> | Sun Apr 25 11:52:20 2021 +0900| [6ad61e30a16d338eab23b649365813fb150066ef] | committer: Marton Balint

avformat/mpegtsenc: Fix mpegts_write_pes() for private_stream_2 and other types

According to the PES packet definition defined in Table 2-17 of ISO_IEC_13818-1
specification, some fields like PTS/DTS or pes_extension could only appears if
the stream_id meets the condition:

if (stream_id != 0xBC &&  // program_stream_map
    stream_id != 0xBE &&  // padding_stream
    stream_id != 0xBF &&  // private_stream_2
    stream_id != 0xF0 &&  // ECM
    stream_id != 0xF1 &&  // EMM
    stream_id != 0xFF &&  // program_stream_directory
    stream_id != 0xF2 &&  // DSMCC_stream
    stream_id != 0xF8)    // ITU-T Rec. H.222.1 type E stream

And the following stream_id types don't have fields like PTS/DTS:

else if ( stream_id == program_stream_map
|| stream_id == private_stream_2
|| stream_id == ECM
|| stream_id == EMM
|| stream_id == program_stream_directory
|| stream_id == DSMCC_stream
|| stream_id == ITU-T Rec. H.222.1 type E stream ) {
    for (i = 0; i < PES_packet_length; i++) {
        PES_packet_data_byte
    }
}

Current implementation skipped the check of stream_id causing some kind of
streams like private_stream_2 to be incorrectly written with actually a
private_stream_1-like PES header with PTS/DTS field. For example, Japan DTV
transmits news and alerts through ARIB superimpose that utilizes
private_stream_2 still could not be remuxed correctly for now.

This patch set fixes the remuxing for private_stream_2 and
other stream_id types.

Signed-off-by: zheng qian <xqq at xqq.im>
Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6ad61e30a16d338eab23b649365813fb150066ef
---

 libavformat/mpegtsenc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index bf93204a5d..969c222f7b 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1450,6 +1450,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                 pts = dts = AV_NOPTS_VALUE;
 
             header_len = 0;
+
+            if (stream_id != STREAM_ID_PROGRAM_STREAM_MAP &&
+                stream_id != STREAM_ID_PADDING_STREAM &&
+                stream_id != STREAM_ID_PRIVATE_STREAM_2 &&
+                stream_id != STREAM_ID_ECM_STREAM &&
+                stream_id != STREAM_ID_EMM_STREAM &&
+                stream_id != STREAM_ID_PROGRAM_STREAM_DIRECTORY &&
+                stream_id != STREAM_ID_DSMCC_STREAM &&
+                stream_id != STREAM_ID_TYPE_E_STREAM) {
+
             flags      = 0;
             if (pts != AV_NOPTS_VALUE) {
                 header_len += 5;
@@ -1543,6 +1553,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
                 memset(q, 0xff, pes_header_stuffing_bytes);
                 q += pes_header_stuffing_bytes;
             }
+            } else {
+                len = payload_size;
+                *q++ = len >> 8;
+                *q++ = len;
+            }
             is_start = 0;
         }
         /* header size */



More information about the ffmpeg-cvslog mailing list