|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "av_base.hpp"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavutil/pixfmt.h>
|
|
|
|
#include <libavcodec/avcodec.h> // only needed for AVCodecID and AVPacket
|
|
|
|
|
|
|
|
typedef struct AVFormatContext AVFormatContext;
|
|
|
|
typedef struct AVInputFormat AVInputFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace av {
|
|
|
|
// AVFormatContext related
|
|
|
|
using format_context = wrapper<AVFormatContext>;
|
|
|
|
format_context format_open_input(std::string const & filename, AVInputFormat* format, AVDictionary** options);
|
|
|
|
format_context format_alloc_context();
|
|
|
|
|
|
|
|
// AVCodec related
|
|
|
|
using codec = wrapper<AVCodec>;
|
|
|
|
codec find_encoder(AVCodecID codec_id);
|
|
|
|
|
|
|
|
using codec_context = wrapper<AVCodecContext>;
|
|
|
|
codec_context context_alloc(codec const & codec);
|
|
|
|
codec_context context_from_stream(format_context const & ctx, size_t i);
|
|
|
|
|
|
|
|
using open_guard = wrapper<AVCodecContext>;
|
|
|
|
open_guard codec_open(codec_context & ctx, codec const & codec, AVDictionary** options);
|
|
|
|
|
|
|
|
// AVPacket related (this is somewhat strange, but matches the usecase)
|
|
|
|
// I need to rethink this
|
|
|
|
using packet_buffer = AVPacket;
|
|
|
|
using packet = wrapper<AVPacket>;
|
|
|
|
packet read_frame(format_context & ctx, packet_buffer & p);
|
|
|
|
|
|
|
|
// AVFrame related
|
|
|
|
using frame = wrapper<AVFrame>;
|
|
|
|
frame frame_alloc();
|
|
|
|
frame frame_clone(frame const & f); // creates a clone with the *same* buffer
|
|
|
|
AVPixelFormat get_format(frame const & f);
|
|
|
|
|
|
|
|
// Does not copy data, it acts as a view
|
|
|
|
void crop(frame & f, int left, int top, int width, int height);
|
|
|
|
frame crop(frame && f, int left, int top, int width, int height);
|
|
|
|
frame crop(frame const & f, int left, int top, int width, int height);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
bool codec_decode_video(codec_context & ctx, frame & f, packet const & pkt);
|
|
|
|
void codec_decode_video_remaining(codec_context & ctx, frame & f);
|
|
|
|
}
|