// Open the initial context variables that are needed
SwsContext *img_convert_ctx;
AVFormatContext* format_ctx = avformat_alloc_context();
AVCodecContext* codec_ctx = NULL;
int video_stream_index;
// Register everything
av_register_all();
avformat_network_init();
if (avformat_open_input(&format_ctx, argv[1],
NULL, NULL) != 0) {
return EXIT_FAILURE;
}
if (avformat_find_stream_info(format_ctx, NULL) < 0) {
return EXIT_FAILURE;
}
//search video stream
for (int i = 0; i < format_ctx->nb_streams; i++) {
if (format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
video_stream_index = i;
}
AVPacket packet;
av_init_packet(&packet);
//open output file
AVFormatContext* output_ctx = avformat_alloc_context();
AVStream* stream = NULL;
//start reading packets from stream and write them to file
av_read_play(format_ctx); // <-- program is frozen in this API call
// Get the codec
AVCodec *codec = NULL;
cout << "avcodec_find_decoder" <<endl;
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
// some more important stuff below ...
当我用MP4文件启动程序时,它可以正常工作。如果我使用它与RTSP H264流,它不会去吹av_read_播放。原始的ffmpeg二进制文件也可以正确地与RTSP流一起工作。这可能是什么原因?