c++ - Saving frames as images using FFmpeg -



c++ - Saving frames as images using FFmpeg -

there tutorials on net it, of them using deprecated functions , unfortunately api utilize broke , makes mess , i'm confused.

i'm next tutorials, learning documentation , seeing examples of current version (even way examples not work).

what i'm trying save frames in .png, next examples , reading did this, i'm confused conversion frame rbg , saving it:

#include <iostream> extern "c" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavutil/avutil.h> } int main(int argc, char ** argv) { if (argc < 2) { av_log(0, av_log_fatal, "usage: %s <input>", argv[0]); homecoming -1; } const char * filename = argv[1]; // register codecs , formats av_register_all(); // open input file, , allocate format context avformatcontext *avformatcontext = avformat_alloc_context(); if (avformat_open_input(&avformatcontext, filename, 0, 0) < 0) { av_log(0, av_log_fatal, "could not open source file %s", filename); homecoming -1; } // retrieve stream info if (avformat_find_stream_info(avformatcontext, 0) < 0) { av_log(0, av_log_fatal, "could not find stream information"); homecoming -1; } // dump info file onto standard error av_dump_format(avformatcontext, 0, filename, 0); // find "best" video stream in file. int result = av_find_best_stream(avformatcontext, avmedia_type_video, -1, -1, 0, 0); if (result < 0) { av_log(0, av_log_fatal, "could not find %s stream in input file '%s'", av_get_media_type_string(avmedia_type_video), filename); homecoming -1; } int stream = result; avstream *avstream = avformatcontext->streams[stream]; avcodeccontext *avcodeccontext = avstream->codec; // find decoder stream avcodec *avcodec = avcodec_find_decoder(avcodeccontext->codec_id); if (! avcodec) { av_log(0, av_log_fatal, "failed find %s codec", av_get_media_type_string(avmedia_type_video)); homecoming -1; } // init decoders, reference counting avdictionary *avdictionary = 0; av_dict_set(&avdictionary, "refcounted_frames", "1", 0); if (result = avcodec_open2(avcodeccontext, avcodec, &avdictionary) < 0) { av_log(0, av_log_fatal, "failed open %s codec", av_get_media_type_string(avmedia_type_video)); homecoming -1; } avframe *avframe = av_frame_alloc(); if (! avframe) { av_log(0, av_log_fatal, "could not allocate frame"); homecoming -1; } // initialize packet, set info null, allow demuxer fill avpacket avpacket; av_init_packet(&avpacket); avpacket.data = 0; avpacket.size = 0; while (av_read_frame(avformatcontext, &avpacket) >= 0) { if (avpacket.stream_index == stream) { int success = avcodec_decode_video2(avcodeccontext, avframe, &success, &avpacket); if (success <= 0) { av_log(0, av_log_fatal, "error decoding video frame"); homecoming -1; } // ... saving... } } avcodec_close(avcodeccontext); avformat_close_input(&avformatcontext); av_frame_free(&avframe); homecoming 0; }

c++ c ffmpeg

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -