[FFmpeg-user] Proper wait for AVStream fully configurated
Большой Человек
cheloveck2.0 at gmail.com
Tue Jun 14 13:35:21 EEST 2022
I am developing a camera streaming service. And sometimes I have an issue
when I got wrong AVCodecParameters::format during initialization for
cameras with slow connection, or it happens for cameras with h264+ codec
with rare key packets.
How it happens.
This piece of code successes:
```
AVDictionary *opts = NULL;
if (config_->uset_tcp_transport)
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
av_dict_set(&opts, "stimeout", std::to_string(starting_ttl_sec_ *
1000000).c_str(), 0);
avformat_open_input(&fmtc_, rtsp_url, NULL, &opts);
video_stream_index_ = av_find_best_stream(fmtc_, AVMEDIA_TYPE_VIDEO,
-1, -1, &codec_, 0);
audio_stream_index_ = av_find_best_stream(fmtc_, AVMEDIA_TYPE_AUDIO,
-1, -1, &codec_, 0);
```
Then sometimes I get wrong value, when I check pixel format:
chroma_format_ = (AVPixelFormat)
fmtc_->streams[video_stream_index_]->codecpar->format;
But if I try to get a packet first
av_read_frame(fmtc_, pkt_);
Then "chroma_format_" most certainly will be correct.
I assume it is connected with getting first key packet. Why and how
can I be sure that codecpair is fully configurated?
More information about the ffmpeg-user
mailing list