Commit Graph

385 Commits

Author SHA1 Message Date
Andreas Rheinhardt
2cddb2f7a8 avformat/mpegtsenc: Avoid allocation of AVPacket
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-27 12:55:41 +01:00
Andreas Rheinhardt
a5ee166327 avformat/avformat: Add AVStream parameter to check_bitstream() sig
For most check_bitstream() functions this just avoids having
to dereference s->streams[pkt->stream_index] themselves; but for
meta-muxers it will allow to forward the packet to stream with
a different stream_index (belonging to a different AVFormatContext)
without using a spare packet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-27 12:55:41 +01:00
Alex Shumsky
1728127e8c avformat/mpegtsenc: do not include adaptation field in teletext TS packets
From ETSI EN 300 472 V1.3.1 (2003-05) Specification for conveying ITU-R System
B Teletext in DVB bitstreams:

4.1 Transport Stream (TS) packet format
The standard TS packet syntax and semantics are followed, noting the following
constraint:
- adaptation_field_control only the values "01" and "10" are permitted.

Some set top boxes (Motorola, Arris, Zyxel) refuse non-conforming packets.

Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-11-06 20:35:39 +01:00
Maksym Veremeyenko
a085418303 avformat/mpegtsenc: fix first_pcr initial update
Commit 6f36eb0da7 claim it fixes endless loop on
package generation if muxrate specified and copyts used. But actually it does
not work properly if -mpegts_copyts 1 is specified:

ffmpeg -y -copyts -i loewe.ts -c:v libx264 -x264opts nal-hrd=cbr:force-cfr=1 -b:v 3500k -minrate 3500k -maxrate 3500k -bufsize 1000k  -c:a mp2 -f mpegts -mpegts_copyts 1 -muxrate 4500k -vframes 1000 test.ts

ffmpeg generate huge file until it reach zero-based pcr value equal to first dts.

Attached patch fixes it.

Reviewed-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-11-06 20:35:19 +01:00
Limin Wang
44fe572371 avformat/mpegtsenc: add AVSV format_identifier for AVS standard
Listing of Registered Identifiers:
https://smpte-ra.org/registered-mpeg-ts-ids

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-20 22:47:17 +08:00
Limin Wang
5779bd5b2a avformat/mpegts: add support for stream_type 0xd4, which is AVS3
GB/T 17975.1
Information technology-Generic coding of moving pictures and associated audio
information-Part 1:Systems

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-20 22:40:13 +08:00
Limin Wang
a59f8ea2a9 avformat/mpegts: add support for stream_type 0xd2, which is AVS2
GB/T 17975.1
Information technology-Generic coding of moving pictures and associated audio
information-Part 1:Systems

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-10-19 20:15:48 +08:00
zheng qian
f38458089f avformat/mpegtsenc: enable muxing of ARIB captions
Writes a general ARIB stream identifier descriptor, as well
as a data component descriptor which also includes a
pre-defined additional_arib_caption_info structure.

Signed-off-by: zheng qian <xqq@xqq.im>
2021-06-10 23:16:55 +03:00
Ubaldo Porcheddu
36b16a30db avformat/mpegtsenc: add NIT support
With some minor changes by Marton Balint:
 - removed trailing whitespace
 - fixed network_descriptors_length
 - fixed reserved_future_use flag in the start of the section
 - removed unused program variable
 - emit first NIT after PAT
 - some other cosmetics

Signed-off-by: Ubaldo Porcheddu <ubaldo@eja.it>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-05-20 23:07:46 +02:00
zheng qian
86a71d897f avformat/mpegtsenc: Fix indentation inside if-clause in mpegts_write_pes()
Fix indentation caused by the added stream_id check.

Signed-off-by: zheng qian <xqq@xqq.im>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-28 21:35:46 +02:00
zheng qian
6ad61e30a1 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@xqq.im>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-28 21:32:22 +02:00
Marton Balint
3f27021143 avformat/mpegtsenc: factorize determining pes stream id
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-28 21:24:44 +02:00
Marton Balint
b9fff6e15e avformat/mpegtsenc: move is_dvb_subtitle/is_dvb_teletext initialization upwards
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-04-28 21:24:44 +02:00
Andreas Rheinhardt
bc70684e74 avformat: Constify all muxer/demuxers
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:06 -03:00
Andreas Rheinhardt
ef6a9e5e31 avutil/buffer: Switch AVBuffer API to size_t
Announced in 14040a1d91.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
Andreas Rheinhardt
5d06d26be3 avformat/mpegtsenc: Preserve disposition in the absence of language
Implements ticket #9113.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-05 04:04:00 +02:00
James Almer
e7f1540507 avformat/mpegtsenc: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 15:06:49 -03:00
James Almer
e07126f54a avformat: use the buffer_size_t typedef where required
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-10 20:26:36 -03:00
Limin Wang
be4ff0f1b2 avformat/mpegtsenc: check that not only first pts but also first dts is valid
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-10-30 22:41:59 +08:00
Limin Wang
27e8a6c44b avformat/mpegtsenc: first_pts_check -> first_pts_checked
change to first_pts_checked and reverse the logic.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-10-30 22:41:59 +08:00
Limin Wang
6f36eb0da7 avformat/mpegtsenc: make first_pcr sync with the first valid dts
now first_pts assume dts will start from zero, if it's not true(copyts is enable),
too many null packet will be inserted for cbr output.

Please test with below command, you'll get huge test.ts without the patch:
./ffmpeg -y -copyts -i ../fate-suite/mpegts/loewe.ts  -c:v libx264 -x264opts \
   nal-hrd=cbr:force-cfr=1 -b:v 3500k -minrate 3500k -maxrate 3500k -bufsize \
   1000k  -c:a mp2 -muxrate 4500k  -vframes 1000 test.ts

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-10-27 18:18:24 +08:00
Limin Wang
f3568a33c9 avformat/mpegtsenc: use total_size instead of avio_tell()
avio_tell() fails to get the amount of data written so far when the
underlying IO context is flushed to segments.

Please test with below command:
$ ./ffmpeg  -f lavfi -i testsrc=duration=100:size=vga -c:v libx264 -x264opts \
  nal-hrd=cbr:force-cfr=1 -b:v 500k -minrate 500k -maxrate 500k -bufsize 500k \
  -f hls -hls_time 10  -hls_ts_options "muxrate=2000000" test%d.ts

$ du -h test*.ts
Before:
2.4M    test00.ts
4.8M    test11.ts
7.2M    test22.ts
9.6M    test33.ts
12M     test44.ts
...

After apply the patch:
 2.4M   test00.ts
 2.4M   test11.ts
 2.4M   test22.ts
 2.4M   test33.ts
 2.4M   test44.ts
...

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-10-27 18:18:24 +08:00
Brad Hards
fcec7a6848 avformat/mpegts: replace magic descriptor_tag values with defines
This takes the used values from ISO/IEC 13818-1 Table 2-45 and adds
them to the mpegts.h header. No functional changes.

Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-10-16 23:31:45 +02:00
Limin Wang
9bb4707b1f avformat/mpegtsenc: reindent the code
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-08-26 14:20:10 +08:00
Limin Wang
4aa6eda76e avformat/mpegtsenc: add registration descriptor for AC-3 and EAC3
Some DVB and ATSC captures are using the official MPEG2 registration
descriptor in addition to using the correct stream type and the
AC-3_audio_stream_descriptor/AC3_descriptor. So let's add it even if it is not
strictly needed for DVB/ATSC.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-08-26 14:20:10 +08:00
Limin Wang
7e61940794 avformat/mpegtsenc: support DVB 6A descriptor for AC-3
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-08-23 07:19:11 +08:00
Limin Wang
bae2ae62ba avformat/mpegtsenc: use local variable store st->codecpar->codec_id
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-25 10:20:30 +08:00
Limin Wang
a35facfeb3 avformat/mpegtsenc: reindent the last commit
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-25 10:20:26 +08:00
Limin Wang
cf81d64282 avformat/mpegtsenc: simplify code for condition checks
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-25 10:20:18 +08:00
Brad Hards
fb819697f6 avformat/mpegts: add constants for MPEG-TS transport stream identifiers
Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-06-09 01:01:28 +02:00
Brad Hards
b8d6d9376c avformat/mpegtsenc: set stream_id correctly based on KLV profile selected
Previously we always set STREAM_TYPE_PRIVATE_DATA, and that remains
the default value.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-31 18:43:02 +02:00
Jun Zhao
ab42db9bed lavf/mpegtsenc: misc style fixes
commit 32aeba1275 missed coding style fix.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-05-28 15:56:21 +08:00
Limin Wang
0cc2d09e17 avformat/mpegtsenc: cosmetic
Merge the short lines after the last commit

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-27 21:14:27 +08:00
Limin Wang
f1035b99fa avformat/mpegtsenc: simplify code by using OFFSET() and ENC macros
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-27 21:14:26 +08:00
Andriy Gelman
0776cb7083 avformat/mpegtsenc: Remove two duplicated fields
ts->{tsid,onid} stores the values of ts->{transport_stream_id,original_network_id}

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-05-14 09:53:59 -04:00
Andriy Gelman
1dd0def976 avformat/mpegtsenc: Don't use heap allocated array to store pids
A temporary heap array currently stores pids from all streams.  It is
used to make sure there are no duplicated pids. However, this array is
not needed because the pids from past streams are stored in the
MpegTSWriteStream structs.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
2020-05-14 09:53:55 -04:00
Gyan Doshi
fc8a239e9d avformat/mpegtsenc: use av_log_once for data stream warning 2020-04-23 11:31:35 +05:30
Gyan Doshi
68d9c0be89 avformat/mpegtsenc: don't print warning for DVB text streams
They can be demuxed by ffmpeg.
2020-04-22 16:07:04 +05:30
Marton Balint
7f2649bb46 avformat/mpegtsenc: use the correct stream_types and write HDMV descriptors for m2ts
Fixes ticket #2622.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-04-21 21:28:42 +02:00
Marton Balint
3958244c91 avformat/mpegtsenc: factorize determining stream_type
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-04-21 21:28:29 +02:00
Marton Balint
bcc19933af avformat/mpegtsenc: only allow one program in m2ts mode
The standard does not allow more.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-04-21 21:28:29 +02:00
Marton Balint
422f0a6136 avformat/mpegtsenc: use standard pids for m2ts
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-04-21 21:28:29 +02:00
Gyan Doshi
f0b3b55002 avformat/mpegtsenc: warn users if codec isn't supported
The MPEG-TS muxer will mux streams with unsupported codec id
as a private data stream; this usually makes the stream
not recognizable by ffmpeg and likely other tools.
2019-12-23 21:06:37 +05:30
Andreas Rheinhardt
c1e439d7e9 avformat: Forward errors where possible
It is not uncommon to find code where the caller thinks to know better
what the return value should be than the callee. E.g. something like
"if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM);". This commit
changes several instances of this to instead forward the actual error.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Marton Balint
1e0ea36945 avformat/mpegtsenc: add padding to m2ts streams
6144 byte alignment is needed.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-03 11:00:11 +01:00
Marton Balint
998906a0a4 avformat/mpegtsenc: factorize writing packet
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-03 11:00:11 +01:00
Marton Balint
db63db3977 avformat/mpegtsenc: move around setting m2ts_mode
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-03 11:00:11 +01:00
Marton Balint
565dc3e451 avformat/mpegtsenc: set priority flag for AC3 codecs if writing BluRay
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-03 11:00:11 +01:00
Marton Balint
f5b83d5419 avformat/mpegtsenc: allow any sensible PID for elementary and PMT PIDs
This sets the range of the first automatically assigned PMT PID or elementary
stream PID parameters to [0x20, 0x1ffa]. You can still assign manually a PID
for a stream using AVStream->id in the wider [0x10, 0x1ffe] range as specified
by ISO13818-1. But since DVB and ATSC both reserves some PIDs, let's not allow
them to be automatically assigned.

Also make sure that assigned PID numbers are valid and fix the error message
for the previous PID collision checks.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-03 11:00:10 +01:00
Jun Zhao
8f7a043609 lavf/mpegtsenc: fix logic check error
fix the logic check error

fix #6751

Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-11-04 10:22:11 +08:00