Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert H.264 Annex B to MPEG-TS

SO...

I have RAW H.264 video data captured via RTSP in a local file and I am attempting to playback the video in a Java FX application. In order to do this, I need to use Http Live Streaming.

I have successfully prototyped a Java FX architecture that can play a video via HLS with a local server using a local folder containing a .m3u8 (HLS index) file and collection of .ts (MPEG-TS) files. The last piece for me is to replace the .ts files with .264 / .h264 files and in the local server, perform the conversion / wrapping of the H.264 Annex B data into MPEG-TS.

I am having trouble figuring out what is required to get H.264 Annex B into MPEG-TS. I have found the following information...

"Annex B is commonly used in live and streaming formats such as transport streams..."

szatmary.org/blog/25

"Annex B of of the document specifies one such format, which wraps NAL units in a format resembling a traditional MPEG video elementary stream, thus making it suitable for use with containers like MPEG PS/TS unable to provide the required framing..."

wiki.multimedia.cx/?title=H.264

"Java FX supports a number of different media types. A media type is considered to be the combination of a container format and one or more encodings. In some cases the container format might simply be an elementary stream containing the encoded data."

docs.oracle.com/javafx/2/api/javafx/scene/media/package-summary.html

"Use the CODECS attribute of the EXT-X-STREAM-INF tag. When this attribute is present, it must include all codecs and profiles required to play back the stream..."

developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html

It seems like I am missing something simple around Elementary and Transport Streams. I have used ffmpeg to convert my H.264 file into a TS file and try to understand the differences. I have an idea of the approximate format differences, but I am still lacking on the details to do it. Does anyone have a link showcasing this or know something simple about how to serve H.264 Annex B data over MPEG-TS?

I am not looking to use a tool, I need to have a custom file format locally where I parse out the H.264 Annex B data and perform the format change in memory, on the fly. I know of a way to use ffmpeg with pipes to accomplish this, but I do not want to have any dependencies and performance is important.

like image 722
Lane Avatar asked Oct 01 '22 15:10

Lane


1 Answers

Its not a format change. It is a container. There is no need to parse out annex b to write it to a TS file. The TS wraps a PES that wraps a annex b stream. The mpegts format is pretty complex, especially without a third party library. The ts code i wrote and use at work is about 1000 lines of C++.

To write TS code, start by trying to reading a TS file using a hex editor, and referencing the wikipedia documentation. The book Video Demystified also has fairly good documentation.

like image 136
szatmary Avatar answered Oct 23 '22 19:10

szatmary