bytedeco / javacv-examples

Examples of using JavaCV / OpenCV library on Java Virtual Machine
337 stars 155 forks source link

VideoWriter class (Ex3WriteVideoSequence) writes a corrupt video #14

Closed ankur2136 closed 6 years ago

ankur2136 commented 7 years ago

[info] Running opencv2_cookbook.chapter11.Ex3WriteVideoSequence [info] Processing video file: /Users/ankurjain/Downloads/javacv-examples-22ef77c9ed889b9cf66ecc8f1972311966b2f1bd/OpenCV2_Cookbook/data/bike.avi [info] Processing video file: /Users/ankurjain/Downloads/javacv-examples-22ef77c9ed889b9cf66ecc8f1972311966b2f1bd/OpenCV2_Cookbook/bikeOut.avi [info] [info] Video processing done.

The resulting bikeOut.avi is an empty file.

I tried a similar code for writing a single frame to a video file and that also gives an empty file. I don't see any other errors.

    {
    val imagePath = getClass.getResource("/IMG_20170221_161618.jpg").getPath
    val origImage = imread(imagePath)
    val writer = createWriter()
    writeNextFrame(writer, origImage)
    writeNextFrame(writer, origImage)
    writeNextFrame(writer, origImage)
    writer.foreach(_.release())
    }

    def createWriter(): Option[VideoWriter] = {
      val writer = new VideoWriter()
      val actualFrameRate = 1
      val actualCodec = VideoWriter.fourcc('M', 'P', 'E', 'G')

      if (writer.open("abc.mpeg", actualCodec, actualFrameRate, new Size(3456, 4608), true)) {
        Some(writer)
     } else {
         None
     }
  }
saudet commented 7 years ago

Please use FFmpegFrameRecorder instead of VideoWriter.

jpsacha commented 6 years ago

VideoProcessor processor was modified to use FFmpegFrameRecorder instead of VideoWriter.