justadudewhohacks/opencv4nodejs

Video files is not output in VideoWriter

nassyi opened this issue · 2 comments

Note: I'm a non-native English speaker, so I'm using machine translation.

No error message.
OpenCV version (example 3.4.1): 5.5.0
With OpenCV-contrib? (extra modules): no
OS: Windows 7 / 8 / 10? / MacOSX? / Ubuntu? : LinuxMint Ver 19.3.

I have created this code to create a video from an image.
When I execute this code, no error message, but I don't output "out.mp4".
What's wrong with this code? Am I using it wrong?

const cv4n = require('opencv4nodejs');
const fs = require('fs');

const sz= new cv4n.Size(500, 500);
let video = new cv4n.VideoWriter("./out.mp4",cv4n.VideoWriter.fourcc("mp4v"), 10, sz, true);

let text = fs.readFileSync("file.list"); // use image file list
let lines = text.toString().split('\n');

for(var i = 0; i < lines.length; i++){
    let pass = "./" + lines[i];
    let img = cv4n.imread(pass);
    video.write(img);
}
video.release();

I've faced a similar problem in my hobby project. An empty-frame file is yielded without any error message if the size of Mat objects is different than the size of VideoWriter.

To resolve the issue, it is necessary to match the size of both. For example, resize the image to same size as VideoWriter and then write the resized image.

    let img = cv4n.imread(pass).resize(sz.width, sz.height);
    video.write(img);

See also #312 (comment)

Thanks for your response.

I added a resize to the process, but "out.mp4" isn’t output.
Also, The images were all resized to 500x500 before being processed.
The result is the same, "out.mp4" isn't output.
In my case, it doesn't generate an empty file.
I wonder if there is some other cause.