[Libav-user] libavformat Realtime Best Practice

Steve Sisak steve.sisak at gmail.com
Tue Jan 23 12:32:33 EET 2018


I’m in the process of writing to a wrapper for libavformat to record from an H.264/AAC RTSP stream on macOS/iOS and have some questions on how to start/stop the stream and respond to discontinuities cleanly (i.e. without large hiccups).

I’m using libavformat solely for the RTSP implementation and parsing/consuming the H.264 stream directly and theoretically have no need for libx264 beyond what libavformat requires to open the stream. (Can it be avoided?)

Ideally I’m looking for an “Opening a network stream” and “Reading from a network stream” equivalents of the “Opening a media file” and “Reading from an opened file” sections here:

https://www.ffmpeg.org/doxygen/3.2/group__lavf__decoding.html

If someone is willing to answer some questions on how libavformat is _supposed_ to be used in this scenario, I’ll be glad to summarize them in write those sections.

If already exists, I’d appreciate a link as Google is failing me.

---

At the moment, I have working code avformat_open_input() / avformat_find_stream_info() / av_read_frame() but am seeing occasional bad timestamps and dropouts, which I want to recover from as smoothly as possible.

Calling  avformat_find_stream_info() / av_find_best_stream() cause a large hiccup reading ahead to find the program streams and seems inappropriate for RTSP — especially if the video format could change on the fly.

Further av_read_play() and av_read_pause() have been returning errors — perhaps because avformat_find_stream_info() has been called?

Should I just call avformat_open_input() then  av_read_play()  and assume any necessary AVStream* structures will have been lazily created for any index i see in av_read_frame()?

What I’m looking for is user-level documentation for:

1) Opening/Playing/Pausing an RTSP stream

2) Finding what sub streams are present including format and timebase information

3) Detecting and restarting cleanly after discontinuities — either dropouts of format changed

TIA for any assistance.

-Steve






More information about the Libav-user mailing list