node-castro
node-castro copied to clipboard
video file created cannot be opened
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?
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'?
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.
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)
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
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!
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.