[FFmpeg-devel] pts/dts generation and index for mpegts (vob)

Erik Van Grunderbeeck erik
Sat May 2 07:40:41 CEST 2009


> its on topic here and welcome
> support of chapter/menu/... is definitly nice
> 

Hello;

Please find included my first try at a contribution for ffmpeg.

The files will extend the libs to allow playing directly from DVD. It
includes support for menu handling, vob transition, subtitle color changes
and queue clearing. I am still working on implementing support for search
(both on chapters and file itself).

To play, just call av_open_input_file() with the path to the dvd drive.

I implemented this with the use of libdvdnav/libdvdread. That means you have
to have the library compiled, and either have the dynamic link available or
link directly with it. I tested linking with a static build.

To compile, include dvd_protocol.h/dvd_protocol.c in libavformat [makefile]
and attachment_dec.c [makefile] in libavcodec. Patch mpeg.c with the
attached patch also. That's the only change needed.

My test run shows that everything works, with caveats explained below.

Before I continue more work on it, I would like some feedback on the setup,
and the flow. 

Changed flow for muxer/decoder:

What I basically did is add an extra startcode (0x1ff) to the mpeg stream,
that gets decoded into a ATTACHMENT stream. That stream is then pulled (as
usual) by the client, who can ignore it and free the packets, or decode it.
The decoding is done by attachment_dec.c. It de-assembles my blocks into a
structure, that contains commands for the client.

To make it reasonably save, the first block of the stream packet I send
contains "EXTNAVDATA". If the packet doesn't contain that, both the stream
parser in mpeg.c will reject the packet, and the attachment decoder also
checks for it.

I simply patched the decoder reg to include attachment_dec if mpeg stream
decoding is allowed (see patch).

Changed flow for any player/streamer:

The client should just decode the packets from the ATTACHMENT stream, by
passing the packet and a pointer to a AVAttachmentParseContext() structure.
Attachment_dec.c takes the packet, parses it and fills the structure.
 
There are states the client should act on if he/she pulls the stream. They
are defined as an enum, and are the first types of AVAttachmentParseContext:

	effdvd_Buttons:
		Structure is filled with coordinates of buttons that should
be selectable by user. Nr of buttons in m_ButtonCount. Coordinates are in
pal size.

	effdvd_Buttons_Highlight
		Highlight the button with the index (0 based) as the current
selection. Button nr is in m_HighLightIndex


	effdvd_CLUT
		Change the colors used for displaying subtitles to the color
map included. Note that this is important, since most DVD's use the subtitle
stream to display button texts.

	effdvd_Clear_Queue
		Clear all packets in the queue waiting for rendering.
Basically clear own queu and call avcodec_flush_buffers() on your streams.
Important also, as this usually means a stream transition will happen (ege
after a button select, or a chapter select).

	effdvd_Wait
		Check m_Wait for the action. 
			0 means: wait until queues are empty, then continue.
			0xff means: last video frame was a still. Display it
for ever (usually because button input is needed)
			Any other value: time to wait in seconds before you
should continue to decode video / subtitle streams

Caveats:

	1) dvd_protocol.h now contains 2 functions that directly call the
protocol handler. They are a kind of hack, since I need to push input back
into the handler. Feedback appreciated on how to continue this.

		void	dvd_protocol_select_button(uint32_t nIndex);
			Call this when a user selects a button (usually by
clicking), with the index of the button selected.

		void	dvd_protocol_signal_queue();
			Call this when your queue is empty (after you
received effdvd_Wait), so the decoder knows it can continue.

	2) Stream resets:
		Esp a problem with audio. Since most streams will change
(ege channel layout, codec data on a vob transition), the audio can sound
bad. Example: a vob (the "don't copy this dvd or the FBI will bust down your
door") contains 2 channel AC3 audio. The next vob played after this (the
main movie) contains 6 channel layout. The audio decoder thus needs to be
reset. I have no way of doing this right now (but can dedect when its
needed).

	3) The extra data added for the mpeg.c demuxer . I checked the docs
for 0x1ff and it should be ok to include a packet header like this. The
security risk is low to none (since I check for correct data). The worst
that could happen is that a hacker diverts the colors of the subtitles to
pink or so. Attachment_dec is also pretty stringent on sizes and layout (and
will send log calls when it fails).
	
	4) I did not include timestamps in the packets I send (would be easy
to do so). Reason is that all packets send need to be acted on "immediately"
as that are commands. Let me know if that is needed.

	5) I probably forgot to mention something. Please let me know what
is unclear.

Feedback appreciated.

Erik
 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: attachment_dec.c
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090502/8e107c2c/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dvd_protocol.h
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090502/8e107c2c/attachment.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dvd_protocol.c
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090502/8e107c2c/attachment-0001.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mpeg_attachment_dec.patch
Type: application/octet-stream
Size: 1867 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090502/8e107c2c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mpeg_attachment_dec.patch
Type: application/octet-stream
Size: 1867 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090502/8e107c2c/attachment-0001.obj>



More information about the ffmpeg-devel mailing list