node-castro icon indicating copy to clipboard operation
node-castro copied to clipboard

video file created cannot be opened

Open ChaimF90 opened this issue 7 years ago • 6 comments

Just trying to use this in a very basic example as follows

const castro = require('castro')
const movie = new castro.Castro();
movie.setLocation('/Users/Me/Movies/totes-epic.mp4')

movie.start();

setTimeout(() => {
    movie.stop()
},4000);

I am not getting any errors, and I even see the file that was generated in the movies folder as expected. When I try to play the video however, it wont open.

Any ideas?

ChaimF90 avatar Aug 16 '17 17:08 ChaimF90

Can you provide more info about your setup? (Specifically, node and OS X / MacOS version numbers.) Also, did you see any errors in the console when you ran 'npm install castro'?

hugs avatar Aug 16 '17 17:08 hugs

FWIW, I just tested this and I can confirm your issue. (Tested on Node v6.9.1 on OS X 10.11.6)

The weird thing is that your script works correctly (the video is playable) when you paste the script into a live Node REPL. But it does not work when it's run as a command line (node your-script.js). Will need to do more digging to find out what's going on.

hugs avatar Aug 16 '17 18:08 hugs

Well this is interesting... Try adding one more timeout that fires at least 500 ms (possibly more) after your video ends. There appears to be a timing issue where some video processing hasn't quite finished running in the background before the script ends. Adding a delay is not a great permanent solution, but it might be a good enough workaround for now.

Example:

const castro = require('castro')
const movie = new castro.Castro()
movie.setLocation('/Users/Me/Movies/totes-epic.mp4')

movie.start()

setTimeout(() => {
    movie.stop()
}, 4000)

setTimeout(() => {
    console.log('Done!')
}, 4500)

hugs avatar Aug 16 '17 19:08 hugs

We might be able to modify Castro's stop() method to check that the movie's isRecording property value is false before returning.

But since we're dealing with timing and events here, a better solution is probably to have Castro fire a "stopped" event when isRecording switches from true to false. And then you'd modify your script to wait for that event. Of course, this might be harder to test. #HaltingProblem

hugs avatar Aug 16 '17 19:08 hugs

Hey, I am gonna play around with this tonight and see what works based on your suggestions. I will also get back to you about the node version I am running.

Thank you!

ChaimF90 avatar Aug 16 '17 21:08 ChaimF90

Ok so I just tried your added delay trick and that did work. I didn't notice any errors when installing the module. As for versions, I am running node version v7.7.4 and, macOs version 10.12.3.

ChaimF90 avatar Aug 16 '17 21:08 ChaimF90