avcpp 3.2.1
Обёртка над FFmpeg, упрощающая его использование в C++ проектах.
Загрузка...
Поиск...
Не найдено
api2-demux-seek.cpp

Демуксинг и позиционирование.

Демуксинг и позиционирование.

api2-demux-seek <входной файл>
// Seeks in a container and prints the packets around the new position.
//
// Shows: seeking to a timestamp in a chosen stream, the key-frame/any-frame
// distinction and how the first packets after a seek carry the flag.
//
// Usage: api2-demux-seek <input file>
#include <iostream>
#include <set>
#include <map>
#include <memory>
#include <functional>
#include "avcpp/av.h"
#include "avcpp/ffmpeg.h"
#include "avcpp/codec.h"
#include "avcpp/packet.h"
#include "avcpp/videorescaler.h"
#include "avcpp/audioresampler.h"
#include "avcpp/avutils.h"
// API2
#include "avcpp/format.h"
#include "avcpp/formatcontext.h"
#include "avcpp/codec.h"
#include "avcpp/codeccontext.h"
using namespace std;
using namespace av;
int main(int argc, char **argv)
{
if (argc < 2)
return 1;
av::init();
av::setFFmpegLoggingLevel(AV_LOG_DEBUG);
string uri {argv[1]};
error_code ec;
FormatContext ictx;
ictx.openInput(uri);
ictx.findStreamInfo();
clog << "Seekable: " << ictx.seekable() << endl;
{
// Seek to the 200 seconds
ictx.seek({200, {1,1}});
auto pkt = ictx.readPacket();
clog << "Seek 0: [" << pkt.streamIndex() << "] pts=" << pkt.pts() << " / " << pkt.pts().seconds() << endl;
}
{
// Seek to the 0 seconds
ictx.seek({0, {1,1}});
auto pkt = ictx.readPacket();
clog << "Seek 0: [" << pkt.streamIndex() << "] pts=" << pkt.pts() << " / " << pkt.pts().seconds() << endl;
}
{
// Seek to the 200 seconds and read to the end
ictx.seek({200, {1,1}});
clog << "Seek 2:\n";
while (true) {
auto pkt = ictx.readPacket(ec);
if (!pkt)
break;
clog << " [" << pkt.streamIndex() << "] pts=" << pkt.pts() << " / " << pkt.pts().seconds() << endl;
}
}
{
// Seek the the begin and read 100 packets
ictx.seek({0, {1,1}});
clog << "Seek 3:\n";
size_t count = 100;
while (count --> 0) {
auto pkt = ictx.readPacket(ec);
if (!pkt)
break;
clog << " [" << pkt.streamIndex() << "] pts=" << pkt.pts() << " / " << pkt.pts().seconds() << endl;
}
}
}