How to specify the framerate with Live555 RTSPServer? - h.264

I'm trying to put a raw H264 stream into RTSP with Live555 but I ran into a framerate problem.
I've learned that raw H264 streams do not have timestamps.
I'm using Live555's H264VideoFileServerMediaSubsession.
The problem is that my raw H264 stream is created with 20fps, but when a client (ffplay) plays the RTSP stream (with the h264 encapsulated), it defaults to 25fps.
Shall I set (force) the framerate in Live555's subsession, or should the raw H264 stream already contain it?

Related

Container format of this RTSP stream

I would like to know the container format of the following stream:
rtsp://8.15.251.47:1935/rtplive/FairfaxVideo3595
According to ffprobe, the container format is RTSP (format_long_name = RTSP input).
I also looked through the debug messages in VLC but I did not find any information on the stream's container format. What I DID find was that the codec was H264 and that VLC was using live555 to decode the stream. The media files live555 can support according to their website (http://www.live555.com/mediaServer/) makes me think that the above stream is an H264 elementary stream and is not in a container format. Am I correct?
Also, if the stream indeed does not have a container format, is it ok to say the container format is RTP (not RTSP as ffprobe says) because that's the protocol used to send the media data?
Thanks!
RTSP is more of a handshake done with the server, while RTP is the actual stream coming in once the handshake is done and you start streaming. RTSP URLs usually start with RTSP://... and the sequence of requests goes roughly something like
RTSP DESCRIBE, RTSP SETUP, RTSP PLAY, TEARDOWN
The response from the server to DESCRIBE will contain the information you need to know about the encoding of the file (H264, JPEG, etc.) while PLAY will cause the server to start sending the RTP stream. I suggest looking up RTSP SDP (session description protocol) for how to extract this information.
In case of streams, you are most likely correct, since the protocol used for streaming is usually RTP, and it tends to go hand in hand with RTSP (however I'm unsure whether or not we can apply the term container in the context of streaming)

Decoding RTP payload as H264 using wireshark

I am streaming a RTSP video from vlc on windows to ipad app. And I capture packets in wireshark. I can see RTP packets in wireshark and also the RTP header fields like payload type, timestamp, sequence number. My question is, is it possible to decode the RTP payload as H264 NAL units. Currently I can only see the bytes in payload.
You need to configure Wireshark to understand that the RTP dynamic payload type maps to H264.
To do this, use the menu; Edit->Preferences->Protocols->H264
Set H264 dynamic payload types to the value shown in the RTP decode for the payload type.

H264 with multiple PPS and SPS

I have a card that produces a H264 stream with a SPS (Sequence Parameter Set) and a PPS (Picture Parameter Set), in that order, directly before each I-Frame. I see that most H264 streams contain a PPS and SPS at the first I-Frame.
Is this recommended? Do decoders/muxers typically support multiple PPS and SRS?
H.264 comes in a variety of stream formats. One variation is called "Annex B".
(AUD)(SPS)(PPS)(I-Slice)(PPS)(P-Slice)(PPS)(P-Slice) ... (AUD)(SPS)(PPS)(I-Slice).
Typically you see SPS/PPS before each I frame and PPS before other slices.
Most decoders/muxers are happy with "Annex B" and the repetition of SPS/PPS.
Most decoders/muxers won't do anything meaningful if you change the format and SPS/PPS midstream.
Most decoders/muxers parse the first SPS/PPS as part of a setup process and ignore subsequent SPSs.
Some decoders/muxers prefer H.264 without the (AUD), start codes and SPS/PPS.
Then you have to feed SPS/PPS out of band as part of setting up the decoders/muxers.
An IDR frame, or an I-slice can not be decoded without a SPS and PPS. In the case of a container like mp4, the SPS and PPS is stored away from the video data in the file header. Upon playback the mp4 is parsed, the SPS/PPS is used to configure the AVC decoder once, then video can be played back starting at any IDR/I-slice.
There is a second scenario, Live video. With live video, there is no file header, because there is no file. So when a TV tunes into a channel, where does it get the SPS/PPS? Because television is broadcast, meaning the television has no way to request the SPS/PPS, it is repeated in the stream.
So when you start encoding video, your encoder does not know what you intend to do with the video. Now if the extra SPS/PPS show up in an mp4, the decoder just ignores them, but if you are streaming to a TV, without them the stream would never play. So most of the default to repeating SPS/PPS just in case.
I know about matroska(mkv) spec so here SPS and PPS are stored only once as codec private data section. So they are not repeating with every i frame or IDR frame.
If your h264 stream's each i frame/IDR frame has SPS/PPS then matroska muxer will store only 1 copy in codec private data.
So while storing usecase based container format suggest to use only one copy of SPS/PPS but broadcasting and streaming based container formats suggest send SPS/PPS before every iFrame/IDR frame or whenever any codec changes change in h264 stream at that time

How to decode RTP/MP4A-LATM audio payload

I am working on an implementation of RTSP in J2ME to connect to Wowza. I have the RTSP part working, and the extraction of RTP packets. I am able to decode and display the h264 video stream.
I am having problems understanding how to create an appropriate audio stream to pass to a J2ME Player object.
As part of the RTSP Setup exchange I get the following information from SDP
m=audio 0 RTP/AVP 96
a=rtpmap:96 MP4A-LATM/24000/1
a=fmtp:96 profile-level-id=15;object=2;cpresent=0;config=400026103FC0
a=control:trackID=1
From this I know that I can expect RTP packets, containing MP4A-LATM format audio, and (most importantly) the mux config data is not present in line with the stream. The mux config data is 400026103FC0
I just don't know how to interpret the config string, and how I might configure a J2ME Player.

detect key-frame in TS with H264 codec

Is there an easy not horrifyingly complex way to detect key-frame in an H264 video stream wrapped in a Transport Stream?
Also, if extra previous packets needed for the decoding of the key-frame is there a way to find those as well?
There is no super simple way of finding the I frame. You have to read the transport stream packets of the AVC stream. Then you have to assemble the packetized elementry stream packets (PES), strip the PES header and then identify the NAL type 5.
So you will need an transport stream demuxer, find the beginning of PES packets and do minimal H.264 parsing.
For demuxing you could look at this source code: http://tsdemuxer.googlecode.com/svn/trunk/v1.0/tsdemux.cpp