[PATCH] mpegts: Replace defines in with AVOptions

Georgi Chorbadzhiyski gf
Tue Jan 25 12:09:17 CET 2011


This patch adds support for setting transport_stream_id,
original_network_id, service_id, pmt_start_pid and start_pid
in mpegts muxer.

Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
(cherry picked from commit 445996aa51f4f1d9a26456a8511988291a720ba0)

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

 doc/muxers.texi         |   41 +++++++++++++++++++++++++++++++++++++++++
 libavformat/mpegtsenc.c |   47 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 76 insertions(+), 12 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 969051a..d98abef 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -68,4 +68,45 @@ Note also that the pattern must not necessarily contain "%d" or
 ffmpeg -i in.avi -f image2 -vframes 1 img.jpeg
 @end example
 
+ at section mpegts
+
+MPEG transport stream muxer.
+
+This muxer implements ISO 13818-1 and part of ETSI EN 300 468.
+
+The muxer options are:
+
+ at table @option
+ at item -mpegts_original_network_id @var{number}
+Set the original_network_id (default 0x0001). This is unique identifier
+of a network in DVB. Its main use is in the unique identification of a
+service through the path Original_Network_ID, Transport_Stream_ID.
+ at item -mpegts_transport_stream_id @var{number}
+Set the transport_stream_id (default 0x0001). This identifies a
+transponder in DVB.
+ at item -mpegts_service_id @var{number}
+Set the service_id (default 0x0001) also known as program in DVB.
+ at item -mpegts_pmt_start_pid @var{number}
+Set the first PID for PMT (default 0x1000, max 0x1f00).
+ at item -mpegts_start_pid @var{number}
+Set the first PID for data packets (default 0x0100, max 0x0f00).
+ at end table
+
+The recognized metadata settings in mpegts muxer are @code{service_provider}
+and @code{service_name}. If they are not set the default for
+ at code{service_provider} is "FFmpeg" and the default for
+ at code{service_name} is "Service01".
+
+ at example
+ffmpeg -i file.mpg -acodec copy -vcodec copy \
+     -mpegts_original_network_id 0x1122 \
+     -mpegts_transport_stream_id 0x3344 \
+     -mpegts_service_id 0x5566 \
+     -mpegts_pmt_start_pid 0x1500 \
+     -mpegts_start_pid 0x150 \
+     -metadata service_provider="Some provider" \
+     -metadata service_name="Some Channel" \
+     -y out.ts
+ at end example
+
 @c man end MUXERS
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index b58e84b..a1bd14c 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/bswap.h"
 #include "libavutil/crc.h"
+#include "libavutil/opt.h"
 #include "libavcodec/mpegvideo.h"
 #include "avformat.h"
 #include "internal.h"
@@ -64,8 +65,36 @@ typedef struct MpegTSWrite {
     int tsid;
     int64_t first_pcr;
     int mux_rate; ///< set to 1 when VBR
+
+    int transport_stream_id;
+    int original_network_id;
+    int service_id;
+
+    int pmt_start_pid;
+    int start_pid;
 } MpegTSWrite;
 
+static const AVOption options[] = {
+    { "mpegts_transport_stream_id", "Set transport_stream_id field.",
+      offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_original_network_id", "Set original_network_id field.",
+      offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_service_id", "Set service_id field.",
+      offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
+      offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, 0x1000, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM},
+    { "mpegts_start_pid", "Set the first pid.",
+      offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, 0x0100, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM},
+    { NULL },
+};
+
+static const AVClass mpegts_muxer_class = {
+    "MPEGTS muxer",
+    av_default_item_name,
+    options,
+    LIBAVUTIL_VERSION_INT,
+};
+
 /* NOTE: 4 bytes must be left at the end for the crc32 */
 static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
 {
@@ -152,16 +181,9 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
 /*********************************************/
 /* mpegts writer */
 
-#define DEFAULT_PMT_START_PID   0x1000
-#define DEFAULT_START_PID       0x0100
 #define DEFAULT_PROVIDER_NAME   "FFmpeg"
 #define DEFAULT_SERVICE_NAME    "Service01"
 
-/* default network id, transport stream and service identifiers */
-#define DEFAULT_ONID            0x0001
-#define DEFAULT_TSID            0x0001
-#define DEFAULT_SID             0x0001
-
 /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
 #define DEFAULT_PES_HEADER_FREQ 16
 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
@@ -374,7 +396,7 @@ static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
     service = av_mallocz(sizeof(MpegTSService));
     if (!service)
         return NULL;
-    service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1;
+    service->pmt.pid = ts->pmt_start_pid + ts->nb_services;
     service->sid = sid;
     service->provider_name = av_strdup(provider_name);
     service->name = av_strdup(name);
@@ -401,8 +423,8 @@ static int mpegts_write_header(AVFormatContext *s)
     const char *provider_name;
     int *pids;
 
-    ts->tsid = DEFAULT_TSID;
-    ts->onid = DEFAULT_ONID;
+    ts->tsid = ts->transport_stream_id;
+    ts->onid = ts->original_network_id;
     /* allocate a single DVB service */
     title = av_metadata_get(s->metadata, "service_name", NULL, 0);
     if (!title)
@@ -410,7 +432,7 @@ static int mpegts_write_header(AVFormatContext *s)
     service_name = title ? title->value : DEFAULT_SERVICE_NAME;
     provider = av_metadata_get(s->metadata, "service_provider", NULL, 0);
     provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME;
-    service = mpegts_add_service(ts, DEFAULT_SID, provider_name, service_name);
+    service = mpegts_add_service(ts, ts->service_id, provider_name, service_name);
     service->pmt.write_packet = section_write_packet;
     service->pmt.opaque = s;
     service->pmt.cc = 15;
@@ -440,7 +462,7 @@ static int mpegts_write_header(AVFormatContext *s)
         /* MPEG pid values < 16 are reserved. Applications which set st->id in
          * this range are assigned a calculated pid. */
         if (st->id < 16) {
-            ts_st->pid = DEFAULT_START_PID + i;
+            ts_st->pid = ts->start_pid + i;
         } else if (st->id < 0x1FFF) {
             ts_st->pid = st->id;
         } else {
@@ -964,4 +986,5 @@ AVOutputFormat ff_mpegts_muxer = {
     mpegts_write_header,
     mpegts_write_packet,
     mpegts_write_end,
+    .priv_class = &mpegts_muxer_class,
 };




More information about the ffmpeg-cvslog mailing list