Around 01/28/11 18:56, Ronald S. Bultje scribbled:
> That patch is now merged, can you submit the update to muxers.texi?
> Then we'll apply the whole thing.
See attached. I hope the documentation is enough.
--
Georgi Chorbadzhiyski
http://georgi.unixsol.org/
From c236024b8254f5c2c45934c30fff390cb0e55a5e Mon Sep 17 00:00:00 2001
From: Georgi Chorbadzhiyski <gf@unixsol.org>
Date: Tue, 25 Jan 2011 13:09:17 +0200
Subject: [PATCH] mpegts: Replace defines in with AVOptions
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@gmail.com>
... | ... |
@@ -68,4 +68,45 @@ Note also that the pattern must not necessarily contain "%d" or |
68 | 68 |
ffmpeg -i in.avi -f image2 -vframes 1 img.jpeg |
69 | 69 |
@end example |
70 | 70 |
|
71 |
+@section mpegts |
|
72 |
+ |
|
73 |
+MPEG transport stream muxer. |
|
74 |
+ |
|
75 |
+This muxer implements ISO 13818-1 and part of ETSI EN 300 468. |
|
76 |
+ |
|
77 |
+The muxer options are: |
|
78 |
+ |
|
79 |
+@table @option |
|
80 |
+@item -mpegts_original_network_id @var{number} |
|
81 |
+Set the original_network_id (default 0x0001). This is unique identifier |
|
82 |
+of a network in DVB. Its main use is in the unique identification of a |
|
83 |
+service through the path Original_Network_ID, Transport_Stream_ID. |
|
84 |
+@item -mpegts_transport_stream_id @var{number} |
|
85 |
+Set the transport_stream_id (default 0x0001). This identifies a |
|
86 |
+transponder in DVB. |
|
87 |
+@item -mpegts_service_id @var{number} |
|
88 |
+Set the service_id (default 0x0001) also known as program in DVB. |
|
89 |
+@item -mpegts_pmt_start_pid @var{number} |
|
90 |
+Set the first PID for PMT (default 0x1000, max 0x1f00). |
|
91 |
+@item -mpegts_start_pid @var{number} |
|
92 |
+Set the first PID for data packets (default 0x0100, max 0x0f00). |
|
93 |
+@end table |
|
94 |
+ |
|
95 |
+The recognized metadata settings in mpegts muxer are @code{service_provider} |
|
96 |
+and @code{service_name}. If they are not set the default for |
|
97 |
+@code{service_provider} is "FFmpeg" and the default for |
|
98 |
+@code{service_name} is "Service01". |
|
99 |
+ |
|
100 |
+@example |
|
101 |
+ffmpeg -i file.mpg -acodec copy -vcodec copy \ |
|
102 |
+ -mpegts_original_network_id 0x1122 \ |
|
103 |
+ -mpegts_transport_stream_id 0x3344 \ |
|
104 |
+ -mpegts_service_id 0x5566 \ |
|
105 |
+ -mpegts_pmt_start_pid 0x1500 \ |
|
106 |
+ -mpegts_start_pid 0x150 \ |
|
107 |
+ -metadata service_provider="Some provider" \ |
|
108 |
+ -metadata service_name="Some Channel" \ |
|
109 |
+ -y out.ts |
|
110 |
+@end example |
|
111 |
+ |
|
71 | 112 |
@c man end MUXERS |
... | ... |
@@ -21,6 +21,7 @@ |
21 | 21 |
|
22 | 22 |
#include "libavutil/bswap.h" |
23 | 23 |
#include "libavutil/crc.h" |
24 |
+#include "libavutil/opt.h" |
|
24 | 25 |
#include "libavcodec/mpegvideo.h" |
25 | 26 |
#include "avformat.h" |
26 | 27 |
#include "internal.h" |
... | ... |
@@ -64,8 +65,36 @@ typedef struct MpegTSWrite { |
64 | 64 |
int tsid; |
65 | 65 |
int64_t first_pcr; |
66 | 66 |
int mux_rate; ///< set to 1 when VBR |
67 |
+ |
|
68 |
+ int transport_stream_id; |
|
69 |
+ int original_network_id; |
|
70 |
+ int service_id; |
|
71 |
+ |
|
72 |
+ int pmt_start_pid; |
|
73 |
+ int start_pid; |
|
67 | 74 |
} MpegTSWrite; |
68 | 75 |
|
76 |
+static const AVOption options[] = { |
|
77 |
+ { "mpegts_transport_stream_id", "Set transport_stream_id field.", |
|
78 |
+ offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, |
|
79 |
+ { "mpegts_original_network_id", "Set original_network_id field.", |
|
80 |
+ offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, |
|
81 |
+ { "mpegts_service_id", "Set service_id field.", |
|
82 |
+ offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, |
|
83 |
+ { "mpegts_pmt_start_pid", "Set the first pid of the PMT.", |
|
84 |
+ offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, 0x1000, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM}, |
|
85 |
+ { "mpegts_start_pid", "Set the first pid.", |
|
86 |
+ offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, 0x0100, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM}, |
|
87 |
+ { NULL }, |
|
88 |
+}; |
|
89 |
+ |
|
90 |
+static const AVClass mpegts_muxer_class = { |
|
91 |
+ "MPEGTS muxer", |
|
92 |
+ av_default_item_name, |
|
93 |
+ options, |
|
94 |
+ LIBAVUTIL_VERSION_INT, |
|
95 |
+}; |
|
96 |
+ |
|
69 | 97 |
/* NOTE: 4 bytes must be left at the end for the crc32 */ |
70 | 98 |
static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len) |
71 | 99 |
{ |
... | ... |
@@ -152,16 +181,9 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id, |
152 | 152 |
/*********************************************/ |
153 | 153 |
/* mpegts writer */ |
154 | 154 |
|
155 |
-#define DEFAULT_PMT_START_PID 0x1000 |
|
156 |
-#define DEFAULT_START_PID 0x0100 |
|
157 | 155 |
#define DEFAULT_PROVIDER_NAME "FFmpeg" |
158 | 156 |
#define DEFAULT_SERVICE_NAME "Service01" |
159 | 157 |
|
160 |
-/* default network id, transport stream and service identifiers */ |
|
161 |
-#define DEFAULT_ONID 0x0001 |
|
162 |
-#define DEFAULT_TSID 0x0001 |
|
163 |
-#define DEFAULT_SID 0x0001 |
|
164 |
- |
|
165 | 158 |
/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ |
166 | 159 |
#define DEFAULT_PES_HEADER_FREQ 16 |
167 | 160 |
#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) |
... | ... |
@@ -374,7 +396,7 @@ static MpegTSService *mpegts_add_service(MpegTSWrite *ts, |
374 | 374 |
service = av_mallocz(sizeof(MpegTSService)); |
375 | 375 |
if (!service) |
376 | 376 |
return NULL; |
377 |
- service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1; |
|
377 |
+ service->pmt.pid = ts->pmt_start_pid + ts->nb_services; |
|
378 | 378 |
service->sid = sid; |
379 | 379 |
service->provider_name = av_strdup(provider_name); |
380 | 380 |
service->name = av_strdup(name); |
... | ... |
@@ -401,8 +423,8 @@ static int mpegts_write_header(AVFormatContext *s) |
401 | 401 |
const char *provider_name; |
402 | 402 |
int *pids; |
403 | 403 |
|
404 |
- ts->tsid = DEFAULT_TSID; |
|
405 |
- ts->onid = DEFAULT_ONID; |
|
404 |
+ ts->tsid = ts->transport_stream_id; |
|
405 |
+ ts->onid = ts->original_network_id; |
|
406 | 406 |
/* allocate a single DVB service */ |
407 | 407 |
title = av_metadata_get(s->metadata, "service_name", NULL, 0); |
408 | 408 |
if (!title) |
... | ... |
@@ -410,7 +432,7 @@ static int mpegts_write_header(AVFormatContext *s) |
410 | 410 |
service_name = title ? title->value : DEFAULT_SERVICE_NAME; |
411 | 411 |
provider = av_metadata_get(s->metadata, "service_provider", NULL, 0); |
412 | 412 |
provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME; |
413 |
- service = mpegts_add_service(ts, DEFAULT_SID, provider_name, service_name); |
|
413 |
+ service = mpegts_add_service(ts, ts->service_id, provider_name, service_name); |
|
414 | 414 |
service->pmt.write_packet = section_write_packet; |
415 | 415 |
service->pmt.opaque = s; |
416 | 416 |
service->pmt.cc = 15; |
... | ... |
@@ -440,7 +462,7 @@ static int mpegts_write_header(AVFormatContext *s) |
440 | 440 |
/* MPEG pid values < 16 are reserved. Applications which set st->id in |
441 | 441 |
* this range are assigned a calculated pid. */ |
442 | 442 |
if (st->id < 16) { |
443 |
- ts_st->pid = DEFAULT_START_PID + i; |
|
443 |
+ ts_st->pid = ts->start_pid + i; |
|
444 | 444 |
} else if (st->id < 0x1FFF) { |
445 | 445 |
ts_st->pid = st->id; |
446 | 446 |
} else { |
... | ... |
@@ -964,4 +986,5 @@ AVOutputFormat ff_mpegts_muxer = { |
964 | 964 |
mpegts_write_header, |
965 | 965 |
mpegts_write_packet, |
966 | 966 |
mpegts_write_end, |
967 |
+ .priv_class = &mpegts_muxer_class, |
|
967 | 968 |
}; |