[Ffmpeg-devel] mpeg transport streams
Marcus Hunger
marcus.hunger
Fri May 27 12:54:43 CEST 2005
Hi list, hi Eric,
I'm also working on creating standard-conform mpegts using ffmpeg. The
submitted patch has some issues which I already solved.
e.g.: frames getting bigger than 2^16 bytes (pes_packet_length)
allowing b-frames
keeping constant pcr-interval
The results seem to be quite correct. At least that's what Dektec's
StreamXpert says. However, the changes I made are still not ready for
merging into ffmpeg.
Attached you will find two patches which hopefully give you a picture
of my work. I am interested in a discussion of how these could be
merged into cvs.
best regards,
Marcus Hunger
MUGLER AG
Entwicklung
E-mail: marcus.hunger at mugler.de
Tel. +49-3723-747-183
Fax: +49-3723-747-198
Bitte nutzen Sie die E-Mail-Verbindung mit uns aus-
schliesslich zum Informationsaustausch. Wir koennen
auf diesem Wege keine rechtsgeschaeftlichen Erklaer-
ungen (Auftraege etc.) entgegennehmen. Der Inhalt
dieser Nachricht ist vertraulich und nur fuer den an-
gegebenen Empfaenger bestimmt. Jede Form der Kennt-
nisnahme und Weitergabe durch Dritte ist unzulaessig.
Sollte diese Nachricht nicht fuer Sie bestimmt sein,
so bitten wir Sie, sich mit uns per E-Mail oder
telefonisch in Verbindung zu setzen.
Please use your E-mail connection with us exclusively
for the exchange of information. We do not accept
legally binding declarations (orders, etc) by this means
of communication. The content of this message is
confidential and intended only for the recipient
indicated. Taking notice of this message or disclosure
by third parties is not permitted. In the event
that this message is not intended for you,
please contact us via E-mail or phone.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mpegtsenc.c.patch
Type: application/octet-stream
Size: 18761 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20050527/ea499a66/attachment.obj>
-------------- next part --------------
--- /home/marcus/local/software/FFMpeg-20050322.orig/libavformat/mpegts.h 2004-07-14 03:32:14.000000000 +0200
+++ mpegts.h 2005-05-20 16:13:44.000000000 +0200
@@ -25,9 +25,11 @@
/* pids */
#define PAT_PID 0x0000
#define SDT_PID 0x0011
+#define CAT_PID 0x0001
/* table ids */
#define PAT_TID 0x00
+#define CAT_TID 0x01
#define PMT_TID 0x02
#define SDT_TID 0x42
@@ -44,10 +46,115 @@
#define STREAM_TYPE_AUDIO_AC3 0x81
#define STREAM_TYPE_AUDIO_DTS 0x8a
+/**
+ * 1.0 second at 24Mbit/s
+ * FIXME: the dvb-standard defines a maximum-interval for sdt of 2 seconds
+ */
+#define MAX_SCAN_PACKETS 32000
+
+/* maximum size in which we look for synchronisation if
+ synchronisation is lost */
+#define MAX_RESYNC_SIZE 4096
+
+
+enum MpegTSFilterType {
+ MPEGTS_PES,
+ MPEGTS_SECTION,
+};
+
+typedef void PESCallback(void *opaque, const uint8_t *buf, int len, int is_start);
+
+typedef struct MpegTSPESFilter {
+ PESCallback *pes_cb;
+ void *opaque;
+} MpegTSPESFilter;
+
+typedef void SectionCallback(void *opaque, const uint8_t *buf, int len);
+
+typedef void SetServiceCallback(void *opaque, int ret);
+
+typedef struct MpegTSSectionFilter {
+ int section_index;
+ int section_h_size;
+ uint8_t *section_buf;
+ int check_crc:1;
+ int end_of_section_reached:1;
+ SectionCallback *section_cb;
+ void *opaque;
+
+} MpegTSSectionFilter;
+
+typedef struct MpegTSSection {
+ int pid;
+ int cc;
+ void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet);
+ void *opaque;
+} MpegTSSection;
+
+typedef struct MpegTSFilter {
+ int pid;
+ int last_cc;
+ enum MpegTSFilterType type;
+ union {
+ MpegTSPESFilter pes_filter;
+ MpegTSSectionFilter section_filter;
+ } u;
+} MpegTSFilter;
+
+/*
+ * unified with MpegTSService of mpegtsenc.c
+ */
+typedef struct MpegTSService {
+ int last_cc; /* last cc code (-1 if first packet) */
+ MpegTSSection pmt; /* MPEG2 pmt table context */
+ int pcr_pid;
+ int sid; /* service ID */
+ int running:1;
+ char *provider_name;
+ char *name;
+} MpegTSService;
+
+struct MpegTSContext {
+ /* user data */
+ AVFormatContext *stream;
+ int raw_packet_size; /* raw packet size, including FEC if present */
+ int auto_guess; /* if true, all pids are analized to find streams */
+ int set_service_ret;
+
+ int mpeg2ts_raw; /* force raw MPEG2 transport stream output, if possible */
+ int mpeg2ts_compute_pcr; /* compute exact PCR for each transport stream packet */
+
+ /* used to estimate the exact PCR */
+ int64_t cur_pcr;
+ int pcr_incr;
+ int pcr_pid;
+
+ /* data needed to handle file based ts */
+ int stop_parse; /* stop parsing loop */
+ AVPacket *pkt; /* packet containing av data */
+
+ /******************************************/
+ /* private mpegts data */
+ /* scan context */
+ MpegTSFilter *sdt_filter;
+ int nb_services;
+ MpegTSService **services;
+
+ /* set service context (XXX: allocated it ?) */
+ SetServiceCallback *set_service_cb;
+ void *set_service_opaque;
+ MpegTSFilter *pat_filter;
+ MpegTSFilter *pmt_filter;
+ int req_sid;
+
+ MpegTSFilter *pids[NB_PID_MAX];
+};
+
+typedef struct MpegTSContext MpegTSContext;
+static int add_pes_stream(MpegTSContext *ts, int pid, int stream_type);
unsigned int mpegts_crc32(const uint8_t *data, int len);
extern AVOutputFormat mpegts_mux;
-typedef struct MpegTSContext MpegTSContext;
MpegTSContext *mpegts_parse_open(AVFormatContext *s);
int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
More information about the ffmpeg-devel
mailing list