twitter / vireo

Vireo is a lightweight and versatile video processing library written in C++11
MIT License
932 stars 111 forks source link

Scala Wrapper Not Working #24

Open KhuramKhalid opened 6 years ago

KhuramKhalid commented 6 years ago

Native library throws exception when initialising demux.Movie object with ByteData(arrayOfBytes)

Expected behavior

Should initialise the Movie object without exception.

Actual behavior

Native code throws exception.

Steps to reproduce the behavior

val pathToMP4 = Paths.get("helloworld.mp4")

val bytes = Files.readAllBytes(pathToMP4)

val byteData = new common.ByteData(bytes)

val movie = new demux.Movie(byteData)

If possible, can you provide a Scala example.

hs_err_pid22716.log

canbal commented 6 years ago

Can you try to initialize as follow?

val movie = new demux.Movie("helloworld.mp4")
KhuramKhalid commented 6 years ago

I tried, it gives syntax error. However, if I try val movie = demux.Movie("helloworld.mp4") then there isn't any syntax error but I get the above mentioned error again.

canbal commented 6 years ago

I think it might be related to the underlying native object being destroyed before the Scala counterpart is gone. Can you try the following? I will try to create a helloworld example for Scala as well.

import resource._

for (movie <- managed(demux.Movie("helloworld.mp4"))) {
  println("video track duration: %d".format(movie.videoTrack.duration())
}

FYI: I didn't have the chance to test this snippet yet. It might be a while before I can provide a well tested sample.

KhuramKhalid commented 5 years ago

I got the same error with the above code as well. As soon as I access the movie instance within loop, it breaks.

KhuramKhalid commented 5 years ago

I also tried the following, but still the same error.

object UsingMovie {
  def apply[T](src: String)(f: demux.Movie => T): T = {
    val movie = demux.Movie(src)
    try {
      f(movie)
    } finally {
      movie.close()
    }
  }
}
object App {
  def main(args: Array[String]): Unit = {
    UsingMovie("helloworld.mp4") { movie =>
      println("video track duration: %d".format(movie.videoTrack.duration()))
    }
  }
}
canbal commented 5 years ago

Ok, I'll have to do a deeper dive it seems. I'll keep the thread posted.

Best, Can On Dec 6, 2018, 2:34 AM -0800, Khuram U. Khalid notifications@github.com, wrote:

I also tried the following, but still the same error. object UsingMovie { def apply[T](src: String)(f: demux.Movie => T): T = { val movie = demux.Movie(src) try { f(movie) } finally { movie.close() } } } object App { def main(args: Array[String]): Unit = { UsingMovie("helloworld.mp4") { movie => println("video track duration: %d".format(movie.videoTrack.duration())) } } } — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

KhuramKhalid commented 5 years ago

Many thanks.