- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <fstream>
- #include <sstream>
-
- extern "C"
-
- #define log(msg) std::wcout << L"[FFmpegRTSP] " << msg << std::endl << std::flush
- #define logError(msg)std:: wcout << L"[Error] [FFmpegRTSP] " << msg << std::endl << std::flush
-
- AVFormatContext* avFormatContext = nullptr;
- SwsContext *swsContext = nullptr;
- AVCodecContext* avCodecContext;
- AVCodec *codec = nullptr;
- int frameCount = 0;
-
- void writePPM(AVFrame* frameRGB, int fileSuffix)
- }
- output_file.close();
- }
-
- int main(int argc, char** argv)
-
- if (avformat_find_stream_info(avFormatContext, NULL) < 0)
-
- int videoStreamIndex = -1;
- for (int i = 0; i < avFormatContext->nb_streams; i++)
- }
- if (videoStreamIndex == -1)
-
- av_read_play(avFormatContext);
-
- codec = avcodec_find_decoder(AV_CODEC_ID_H264);
- if (!codec)
- avCodecContext = avcodec_alloc_context3(codec);
- avcodec_get_context_defaults3(avCodecContext, codec);
- avcodec_copy_context(avCodecContext, avFormatContext->streams[videoStreamIndex]->codec);
-
- if (avcodec_open2(avCodecContext, codec, NULL) != 0)
-
- int width = avCodecContext->width;
- int height = avCodecContext->height;
-
- swsContext = sws_getContext(width, height, avCodecContext->pix_fmt, width,
- height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
-
- AVFrame* frame = av_frame_alloc();
- frame->format = avCodecContext->pix_fmt;
- frame->width = width;
- frame->height = height;
- av_frame_get_buffer(frame, 0);
-
- AVFrame* frameRGB = av_frame_alloc();
- frameRGB->format = AV_PIX_FMT_RGB24;
- frameRGB->width = width;
- frameRGB->height = height;
- av_frame_get_buffer(frameRGB, 0);
-
- AVPacket packet;
- av_init_packet(&packet);
-
- while (av_read_frame(avFormatContext, &packet) >= 0 && frameCount < 1000)
- frameCount++;
- }
- av_free_packet(&packet);
- av_init_packet(&packet);
- }
- av_frame_free(&frame);
- av_frame_free(&frameRGB);
-
- av_read_pause(avFormatContext);
- avcodec_free_context(&avCodecContext);
- avformat_free_context(avFormatContext);
-
- return EXIT_SUCCESS;
- }
-
-
select language
-
select style
goto line: