Changes between Initial Version and Version 1 of Capture/Lightning

Sep 21, 2012, 2:41:24 AM (8 years ago)



  • Capture/Lightning

    v1 v1  
     1= The problem =
     3This is a funny tutorial that describes one of the ways you can capture a lightning, during storms. The problem with a lightning capturing is that it happens at a random time interval and lasts for a brief moment of time, so it is very tricky to capture it easily. The usual way is to record the sky continuously for a longer time period and later to edit the recording and cut the pieces where the lightning happened or using some hi-tech expensive cameras, that can do all this for you.
     5= The ideal solution =
     7But let's do this in a cheap and easy way. What we need is to capture the video of the sky continuously and to save a video only when a lightning happens. We can accomplish this by using "buffered recording". Consider the following example.
     91. One ffmpeg instance captures the camera's input and buffers the output for, say 20 seconds.
     102. We can start another ffmpeg instance, whenever we see the lightning bolt, which will take the output of the first ffmpeg and record it to a file.
     12Let's translate this into familiar ffmpeg commands. First let's start the first ffmpeg instance, which will constantly keep capturing the camera's output and buffer it for some time:
     14ffmpeg -f v4l2 -i /dev/video0 -vcodec rawvideo -delay 20 -f mpegts udp://
     17and when we see the lightning, we'll just type something like this and press the Enter key:
     19ffmpeg -f mpegts -i udp:// -vcodec libx264 -t 30 output.flv
     22Now, this is all great, except FFmpeg doesn't have (yet) a "-delay <seconds>" option, which will buffer and delay the output for specified amount of seconds. I hope this will be implemented soon, but until then, we can use another tool, which can do what we need.
     24''If you are interested in a discussion about the "-delay" option in ffmpeg, please [ read this ticket].''
     26= The actual solution =
     28The tool is a modified version of [ Samplicator] which "Sends copies of (UDP) datagrams to multiple receivers". The modified version of this tool has a feature added that allows Samplicator to delay its output UDP stream for some time.
     30Shortly, it works like this. We start the first instance of ffmpeg, capture the camera input and forward the video output to a local udp port number 1234:
     32ffmpeg -f v4l2 -i /dev/video0 -vcodec rawvideo -f mpegts udp://
     35Then we start a modified Samplicator, to buffer that udp stream for 20 seconds:
     37samplicate -p 1234 -z 20
     40and finally, we will prepare the following command and when we see the lightning, we'll just press the Enter key:
     42ffmpeg -f mpegts -i udp:// -vcodec libx264 -t 30 output.flv
     45This way we will start recording our video somewhere a couple of seconds in the past (depending on how much time it takes ffmpeg to start up and start recording the video), but since we delay the original for 20 seconds, it should be enough. Also, we record for the next 30 seconds (-t 30) which should capture the moment when the lightning happened.
     47= Download =
     49The source code of the modified Samplicator tool can be found here: []
     51Keep in mind it is in a pure beta stage, so it might not even work on your platform at all, but the author of the original Samplicator was contacted and provided with all the changes, so hopefully we can soon expect that those will be merged into the original tool and tested for bugs. Until that happens (and if it happens at all), you might use that modified tool under the same license that is provided for the original tool, nothing more, nothing less.
     53Happy lightning hunting :)