78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
#pragma once
|
|
|
|
extern "C" {
|
|
typedef struct AVCodec AVCodec;
|
|
typedef struct AVCodecContext AVCodecContext;
|
|
typedef struct AVCodecParameters AVCodecParameters;
|
|
typedef struct AVFrame AVFrame;
|
|
typedef struct AVFormatContext AVFormatContext;
|
|
typedef struct AVPacket AVPacket;
|
|
}
|
|
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
|
|
|
|
namespace av {
|
|
struct error : public std::runtime_error {
|
|
using runtime_error::runtime_error;
|
|
};
|
|
|
|
// an enum in reality
|
|
using codec_id = int;
|
|
|
|
// Has no ownership
|
|
struct codec {
|
|
AVCodec * ptr;
|
|
};
|
|
|
|
codec find_encoder(codec_id id);
|
|
|
|
struct frame {
|
|
frame();
|
|
|
|
struct deleter { void operator()(AVFrame * p); };
|
|
std::unique_ptr<AVFrame, deleter> ptr;
|
|
};
|
|
|
|
// TODO: are ref counted... How to do?
|
|
struct packet {
|
|
packet();
|
|
|
|
struct deleter { void operator()(AVPacket * p); };
|
|
std::unique_ptr<AVPacket, deleter> ptr;
|
|
};
|
|
|
|
struct codec_context {
|
|
codec_context();
|
|
codec_context(codec const & c);
|
|
|
|
// If constructed with codec, it must be the same
|
|
// need not be closed
|
|
void open(codec const & c);
|
|
|
|
void send_frame(frame const & f);
|
|
int receive_packet(packet & p);
|
|
|
|
void send_packet(packet const & p);
|
|
int receive_frame(frame & f);
|
|
|
|
void set_parameters(const AVCodecParameters *par);
|
|
|
|
struct deleter { void operator()(AVCodecContext * p); };
|
|
std::unique_ptr<AVCodecContext, deleter> ptr;
|
|
};
|
|
|
|
struct format_context {
|
|
format_context();
|
|
format_context(const std::string & url);
|
|
|
|
codec_context context_from_stream(int i) const;
|
|
|
|
struct deleter { void operator()(AVFormatContext * p); };
|
|
std::unique_ptr<AVFormatContext, deleter> ptr;
|
|
};
|
|
|
|
void encode_as_jpg(const frame & frame, const std::string & filename);
|
|
frame open_image(const std::string & filename);
|
|
}
|