1

I am trying to write the frame into my local machine in mp4 format. The frame is read from an existing mp4 file. After running the following code, I was able to see the VideoOutput.mp4 file, but it is corrupted for some reason. Anyone knows why?

 VideoCapture capture("videoSample.mp4");
    if (capture.isOpened())
        {
            while (true)
            {
                capture >> frame;
            }
VideoWriter video("somepath\\videoOutput.mp4", VideoWriter::fourcc('m', 'p', '4', 'v'), 10, Size(win_width, win_width * 2));

    video.write(frame);
        }
superninja
  • 3,114
  • 7
  • 30
  • 63
  • Probably it needs some additional function for header writing. – Michael Chourdakis May 14 '20 at 21:30
  • if you give the VideoWriter the filename .mp4 extension and instead of using a fourcc, enter -1 as the codec, it works. At least in the newer opencv versions. – Micka May 14 '20 at 21:43
  • @Micka like this? `VideoWriter video("somepath\\videoOutput.mp4", VideoWriter::fourcc('m', 'p', '4', 'v'), 10, Size(win_width, win_width * 2));` It shows `tag 0x31313131/'1111' is not found (format 'mp4 / MP4 (MPEG-4 Part 14)')` – superninja May 14 '20 at 22:38
  • Does your video writer width/height match the frame width/height? If it doesn't that will corrupt your output video. – shortcipher3 May 14 '20 at 22:50
  • 1
    no. like this: VideoWriter video("somepath\\videoOutput.mp4", -1, 10, Size(win_width, win_width * 2)); – Micka May 15 '20 at 05:05

0 Answers0