Decode video.
Decode video.
#include <iostream>
#include <set>
#include <map>
#include <memory>
#include <functional>
#include "avcpp/avconfig.h"
int main(int argc, char **argv)
{
if (argc < 2)
return 1;
av::setFFmpegLoggingLevel(AV_LOG_DEBUG);
string uri {argv[1]};
ssize_t videoStream = -1;
error_code ec;
int count = 0;
{
if (ec) {
cerr << "Can't open input\n";
return 1;
}
if (ec) {
cerr << "Can't find streams: " << ec << ", " << ec.message() << endl;
return 1;
}
if (st.mediaType() == AVMEDIA_TYPE_VIDEO) {
vst = st;
videoStream = st.
index();
break;
}
}
cerr << videoStream << endl;
cerr << "Video stream not found\n";
return 1;
}
if (ec) {
cerr << "Can't open codec\n";
return 1;
}
}
if (ec) {
clog << "Packet reading error: " << ec << ", " << ec.message() << endl;
return 1;
}
if (pkt.streamIndex() != videoStream) {
continue;
}
auto ts = pkt.ts();
clog << "Read packet: " << ts << " / " << ts.seconds() << " / " << pkt.timeBase() << " / st: " << pkt.streamIndex() << endl;
#if AVCPP_HAS_PKT_SIDE_DATA
for (auto side : pkt.sideData()) {
clog << " found packet side data: " << side.name() << endl;
if (side.type() == AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL) {
assert(side.span().size() >= sizeof(uint64_t));
uint64_t idType{};
memcpy(&idType, side.span().data(), sizeof(idType));
idType = av_be2ne64(idType);
auto payload = side.span().subspan(sizeof(uint64_t));
clog << " matroska block additions id type = " << idType << endl;
if (!payload.empty() && idType == 100 ) {
clog << " block additions data: " << std::string_view{(const char*)payload.data(), payload.size()} << endl;
}
}
}
#endif
count++;
if (ec) {
cerr << "Error: " << ec << ", " << ec.message() << endl;
return 1;
} else if (!frame) {
cerr << "Empty frame\n";
}
clog <<
" Frame: " << frame.width() <<
"x" << frame.height() <<
", size=" << frame.size() <<
", ts=" << ts <<
", tm: " << ts.
seconds() <<
", tb: " << frame.timeBase() <<
", ref=" << frame.isReferenced() <<
":" << frame.refCount() << endl;
}
clog << "Flush frames;\n";
while (true) {
if (ec) {
cerr << "Error: " << ec << ", " << ec.message() << endl;
return 1;
}
if (!frame)
break;
clog <<
" Frame: " << frame.width() <<
"x" << frame.height() <<
", size=" << frame.size() <<
", ts=" << ts <<
", tm: " << ts.
seconds() <<
", tb: " << frame.timeBase() <<
", ref=" << frame.isReferenced() <<
":" << frame.refCount() << endl;
}
}
}
Audio resampling with libswresample.
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
void open(OptionalErrorCode ec=throws())
Open the codec with the parameters set so far.
Codec descriptor.
Definition codec.h:32
Container context: the entry point for demuxing, muxing and seeking.
Definition formatcontext.h:153
StreamsView streams(OptionalErrorCode ec=throws()) const
All streams as a range, for range-based for and std algorithms.
void openInput(const std::string &uri, OptionalErrorCode ec=throws())
Open an input and probe its container.
void findStreamInfo(OptionalErrorCode ec=throws())
Read the stream parameters of an opened input.
size_t streamsCount() const
Number of streams in the container.
Packet readPacket(OptionalErrorCode ec=throws())
Read the next packet from any stream.
Timestamp pts() const
Presentation timestamp.
Compressed data and its metadata.
Definition packet.h:110
One stream inside a container.
Definition stream.h:34
int index() const
Position of the stream in its container.
bool isValid() const
Whether the view refers to a stream.
double seconds() const noexcept
The timestamp in seconds.
Decodes video packets into frames.
Definition codeccontext.h:1161
VideoFrame decode(const Packet &packet, OptionalErrorCode ec=throws(), bool autoAllocateFrame=true)
decodeVideo - decode video packet
One video frame.
Definition frame.h:578
Codec descriptors and lookup by name or id.
Codec contexts: opening, configuring, encoding and decoding.
FFmpeg types re-exported for the public API and small value wrappers.
Container format contexts: opening, demuxing, muxing and seeking.
Root namespace of the library.
Definition audioresampler.h:19
void init()
Initialize all subsystems the library needs.
Compressed packets and their side data.
bool isNull() const
Whether the wrapper is empty.
Definition ffmpeg.h:77
Video scaling and pixel format conversion with libswscale.