Sélectionner une révision Git
test_matrixeventprocessor.ts
Video.cc 1,88 Kio
#include "Video.hh"
#include "Utils.hh"
#include <QJsonObject>
#include <QJsonArray>
using namespace Vivy;
VideoContext::VideoContext(const QString &path)
: filePath(path)
{
if (!format)
throw std::runtime_error("out of memory, can't create allocate the AVFormatContext");
const std::string stdFilename = filePath.toStdString();
const char *filename = stdFilename.c_str();
AVFormatContext *formatPtr = format.get();
// Get info from video file
if (avformat_open_input(&formatPtr, filename, nullptr, nullptr) != 0) {
[[maybe_unused]] void *relatedOnFailure = format.release(); // freed by avformat_open_input
throw std::runtime_error("failed to open file");
}
if (avformat_find_stream_info(formatPtr, nullptr) < 0) {
throw std::runtime_error("failed to get video stream info");
}
// Populate all the stream indexes
for (uint i = 0; i < format->nb_streams; ++i) {
AVStream *itFormat = format->streams[i];
AVCodecParameters *params = itFormat->codecpar;
AVCodec *streamCodec = avcodec_find_decoder(params->codec_id);
if (streamCodec && streamCodec->type == AVMEDIA_TYPE_VIDEO) {
videoStreams.insert(i, std::make_shared<Stream>(streamCodec, formatPtr, itFormat, i));
}
}
// Get the default stream
defaultStreamIndex = av_find_best_stream(formatPtr, AVMEDIA_TYPE_VIDEO,
-1, // Let AV find one stream
-1, // We don't want related streams
nullptr, 0);
if (defaultStreamIndex < 0) {
qCritical() << "Could not find the best video stream";
}
qDebug() << "Opened video context for" << path << "with duration" << formatPtr->duration
<< "and default stream index" << defaultStreamIndex;
}