fix: VideoReader bugs — stride, memory, audio detection, UB
Pass MXL grain stride (from sliceSizes[0]) into get_next_frame so
YUV422P10toV210 writes with the correct line width instead of a
self-computed value that may not match the MXL buffer.
Fix audio stream detection: condition was inverted (!= -1 → == -1),
so the first audio stream was never picked up.
Add return false at end of get_next_frame to fix UB when g_running
goes false and the loop exits without returning.
Replace av_frame_unref/av_packet_unref with av_frame_free/av_packet_free
in destructor — unref only releases data, not the struct itself.
Add av_freep(&p10_data[0]) in destructor to free av_image_alloc memory.
Remove unused p10_buffer and v210_buffer allocations.
Read filename from config("file") instead of hardcoded path.
Add early return if mxlCreateFlowWriter fails.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,12 +15,10 @@ extern "C" {
|
||||
#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";
|
||||
void run() override {
|
||||
const std::string filename = config().value("file", std::string{});
|
||||
if (filename.empty()) { log("config missing 'file'"); return; }
|
||||
log("VideoIn Node started with file: %s", filename.c_str());
|
||||
dmf::VideoReader video_reader(filename);
|
||||
|
||||
@@ -51,8 +49,10 @@ class VideoInNode : public dmf::NodeBase {
|
||||
&created
|
||||
);
|
||||
if (vst != MXL_STATUS_OK) {
|
||||
log("MXL flow writer is not created. Reason: %s", dmf::mxl_status_str(vst));
|
||||
log("mxlCreateFlowWriter failed (%s)", dmf::mxl_status_str(vst));
|
||||
return;
|
||||
}
|
||||
const uint32_t video_stride = video_config.discrete.sliceSizes[0];
|
||||
|
||||
mxlRational video_rate = {fps_num, fps_den};
|
||||
uint64_t video_index = mxlGetCurrentIndex(&video_rate);
|
||||
@@ -62,7 +62,7 @@ class VideoInNode : public dmf::NodeBase {
|
||||
mxlGrainInfo grain{};
|
||||
vst = mxlFlowWriterOpenGrain(video_writer, video_index, &grain, &buf);
|
||||
if (vst == MXL_STATUS_OK) {
|
||||
if (!video_reader.get_next_frame(buf, nullptr)) continue;
|
||||
if (!video_reader.get_next_frame(buf, video_stride, nullptr)) continue;
|
||||
grain.flags = 0;
|
||||
grain.validSlices = grain.totalSlices;
|
||||
mxlFlowWriterCommitGrain(video_writer, &grain);
|
||||
|
||||
Reference in New Issue
Block a user