84 lines
2.8 KiB
C++
84 lines
2.8 KiB
C++
extern "C" {
|
|
#include <libavformat/avformat.h>
|
|
#include <libavcodec/avcodec.h>
|
|
#include <libavutil/avutil.h>
|
|
#include <libswscale/swscale.h>
|
|
#include <libavutil/imgutils.h>
|
|
#include <libavutil/pixdesc.h>
|
|
}
|
|
|
|
#include <string>
|
|
#include <mxl/flow.h>
|
|
#include <mxl/time.h>
|
|
#include "V210.hpp"
|
|
#include "FlowDef.hpp"
|
|
#include "NodeBase.hpp"
|
|
#include "VideoReader.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
class VideoInNode : public dmf::NodeBase {
|
|
void run() override {
|
|
std::string filename = "/home/itten/test-vid/0.ts";
|
|
log("VideoIn Node started with file: %s", filename.c_str());
|
|
dmf::VideoReader video_reader(filename);
|
|
|
|
const auto video_flow_info = config().at("video_flow_id");
|
|
const auto video_flow_id = video_flow_info.at("id").get<std::string>();
|
|
const int width = video_flow_info.value("width", video_reader.source_info.width);
|
|
const int height = video_flow_info.value("height", video_reader.source_info.height);
|
|
const int fps_num = video_flow_info.value("fps_num", video_reader.source_info.fps_num);
|
|
const int fps_den = video_flow_info.value("fps_den", video_reader.source_info.fps_den);
|
|
|
|
mxlFlowWriter video_writer = nullptr;
|
|
mxlFlowConfigInfo video_config = {};
|
|
std::string video_flow_def = dmf::make_video_flow_def(
|
|
video_flow_id,
|
|
node_id(),
|
|
width,
|
|
height,
|
|
fps_num,
|
|
fps_den
|
|
);
|
|
bool created = false;
|
|
mxlStatus vst = mxlCreateFlowWriter(
|
|
instance(),
|
|
video_flow_def.c_str(),
|
|
"",
|
|
&video_writer,
|
|
&video_config,
|
|
&created
|
|
);
|
|
if (vst != MXL_STATUS_OK) {
|
|
log("MXL flow writer is not created. Reason: %s", dmf::mxl_status_str(vst));
|
|
}
|
|
|
|
mxlRational video_rate = {fps_num, fps_den};
|
|
uint64_t video_index = mxlGetCurrentIndex(&video_rate);
|
|
|
|
while (dmf::g_running.load(std::memory_order_relaxed)) {
|
|
uint8_t* buf = nullptr;
|
|
mxlGrainInfo grain{};
|
|
vst = mxlFlowWriterOpenGrain(video_writer, video_index, &grain, &buf);
|
|
if (vst == MXL_STATUS_OK) {
|
|
if (!video_reader.get_next_frame(buf, nullptr)) continue;
|
|
grain.flags = 0;
|
|
grain.validSlices = grain.totalSlices;
|
|
mxlFlowWriterCommitGrain(video_writer, &grain);
|
|
}
|
|
const uint64_t ns = mxlGetNsUntilIndex(video_index + 1, &video_rate);
|
|
if (ns > 0 && ns < 2'000'000'000ULL) mxlSleepForNs(ns);
|
|
video_index++;
|
|
}
|
|
|
|
mxlReleaseFlowWriter(instance(), video_writer);
|
|
}
|
|
};
|
|
|
|
|
|
int main() {
|
|
VideoInNode node;
|
|
return node.execute();
|
|
}
|