|
|
@ -6,9 +6,15 @@ extern "C" { |
|
|
|
#include <libavcodec/avcodec.h> |
|
|
|
} |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <string> |
|
|
|
#include <cassert> |
|
|
|
|
|
|
|
// Was not yet defined in <string> :(
|
|
|
|
static std::string operator "" s(const char *str, std::size_t len){ |
|
|
|
return {str, len}; |
|
|
|
} |
|
|
|
|
|
|
|
namespace av { |
|
|
|
|
|
|
|
format_context format_open_input(const std::string& filename, AVInputFormat* format, AVDictionary** options){ |
|
|
@ -98,4 +104,23 @@ namespace av { |
|
|
|
return crop(frame_clone(f), left, top, width, height); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool codec_decode_video(codec_context& ctx, frame& f, const packet& pkt){ |
|
|
|
int finished = 0; |
|
|
|
int ret = avcodec_decode_video2(ctx.get(), f.get(), &finished, pkt.get()); |
|
|
|
if (ret < 0) { |
|
|
|
throw std::runtime_error("Error ["s + std::to_string(ret) + "] while decoding frame: "s + strerror(AVERROR(ret))); |
|
|
|
} |
|
|
|
return finished; |
|
|
|
} |
|
|
|
|
|
|
|
void codec_decode_video_remaining(codec_context& ctx, frame& f){ |
|
|
|
AVPacket pkt{0, 0, 0, 0, 0}; // data and size should be 0
|
|
|
|
int finished = 0; |
|
|
|
int ret = avcodec_decode_video2(ctx.get(), f.get(), &finished, &pkt); |
|
|
|
if (ret < 0) { |
|
|
|
throw std::runtime_error("Error ["s + std::to_string(ret) + "] while decoding remaining frame: "s + strerror(AVERROR(ret))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|