1 #include "ffmpeg_raii.h"
4 #include <libavcodec/avcodec.h>
5 #include <libavformat/avformat.h>
6 #include <libavutil/dict.h>
7 #include <libavutil/frame.h>
8 #include <libswscale/swscale.h>
15 void avformat_close_input_unique::operator() (AVFormatContext *format_ctx) const
17 avformat_close_input(&format_ctx);
20 AVFormatContextWithCloser avformat_open_input_unique(
21 const char *pathname, AVInputFormat *fmt,
22 AVDictionary **options)
24 return avformat_open_input_unique(pathname, fmt, options, AVIOInterruptCB{ nullptr, nullptr });
27 AVFormatContextWithCloser avformat_open_input_unique(
28 const char *pathname, AVInputFormat *fmt,
29 AVDictionary **options,
30 const AVIOInterruptCB &interrupt_cb)
32 AVFormatContext *format_ctx = avformat_alloc_context();
33 format_ctx->interrupt_callback = interrupt_cb;
34 if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
37 return AVFormatContextWithCloser(format_ctx);
42 void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const
44 avcodec_free_context(&codec_ctx);
47 AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec)
49 return AVCodecContextWithDeleter(avcodec_alloc_context3(codec));
55 void avcodec_parameters_free_unique::operator() (AVCodecParameters *codec_par) const
57 avcodec_parameters_free(&codec_par);
62 void av_frame_free_unique::operator() (AVFrame *frame) const
64 av_frame_free(&frame);
67 AVFrameWithDeleter av_frame_alloc_unique()
69 return AVFrameWithDeleter(av_frame_alloc());
74 void sws_free_context_unique::operator() (SwsContext *context) const
76 sws_freeContext(context);