Changes between Version 1 and Version 2 of Capture/Lightning


Ignore:
Timestamp:
Sep 21, 2012, 10:18:45 PM (7 years ago)
Author:
burek
Comment:

rephrased some lines, formatted the text a little bit

Legend:

Unmodified
Added
Removed
Modified
  • Capture/Lightning

    v1 v2  
    55= The ideal solution =
    66
    7 But 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.
     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 capturing". Consider the following example.
    88
    9 1. One ffmpeg instance captures the camera's input and buffers the output for, say 20 seconds.
    10 2. 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.
     91. First ffmpeg instance captures the input from camera and buffers its output for, say 20 seconds. This allows the output to always be late for 20 seconds, comparing to the input.
     102. Second ffmpeg instance starts whenever the lightning happens, captures the output of the first ffmpeg instance and records it to a file.
    1111
    12 Let'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:
     12This way, in ideal situation, we will start saving our video file 20 seconds in the past, comparing to the current time. Of course, it will take some time for second ffmpeg instance to start, but it should be enough (less than 20 seconds) to capture the moment of the lightning, when it arrives from the buffer. Also, we record for the next 30 seconds (-t 30) which should capture the moment when the lightning happened (20 seconds before the lightning and 10 seconds after). The idea is pretty simple, right?
     13
     14Let's translate all that into familiar ffmpeg commands. For the first ffmpeg instance, which will constantly keep capturing the input from the camera and buffer it for some time, we should type something like this:
    1315{{{
    1416ffmpeg -f v4l2 -i /dev/video0 -vcodec rawvideo -delay 20 -f mpegts udp://127.0.0.1:1234
    1517}}}
    1618
    17 and when we see the lightning, we'll just type something like this and press the Enter key:
     19And we will prepare the following command for the second ffmpeg instance and when we see the lightning, we'll just press the Enter key:
    1820{{{
    1921ffmpeg -f mpegts -i udp://127.0.0.1:1234 -vcodec libx264 -t 30 output.flv
    2022}}}
    2123
    22 Now, 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.
    23 
    24 ''If you are interested in a discussion about the "-delay" option in ffmpeg, please [http://ffmpeg.org/trac/ffmpeg/ticket/1753 read this ticket].''
     24Now, this all looks great, except FFmpeg doesn't have (yet) a "-delay <seconds>" option, which will buffer and delay the output for specified number of seconds. If you are interested in a discussion about the "-delay" option in ffmpeg, please [http://ffmpeg.org/trac/ffmpeg/ticket/1753 read this ticket]. I hope this will be implemented soon, but until then, we can use another tool, which can do what we need.
    2525
    2626= The actual solution =
    2727
    28 The tool is a modified version of [http://code.google.com/p/samplicator/ 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.
     28The tool we will use is a modified version of [http://code.google.com/p/samplicator/ Samplicator tool] 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.
    2929
    30 Shortly, 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:
     30With the help of this tool, we are now able to accomplish what we want. First, we will start the first ffmpeg:
    3131{{{
    3232ffmpeg -f v4l2 -i /dev/video0 -vcodec rawvideo -f mpegts udp://127.0.0.1:1234
    3333}}}
    3434
    35 Then we start a modified Samplicator, to buffer that udp stream for 20 seconds:
     35then we will start a modified Samplicator tool, to buffer the UDP stream for 20 seconds:
    3636{{{
    3737samplicate -p 1234 -z 20 127.0.0.1/5678
    3838}}}
    3939
    40 and finally, we will prepare the following command and when we see the lightning, we'll just press the Enter key:
     40and, finally, we will prepare the following command for the second ffmpeg instance and when we see the lightning, we'll just press the Enter key:
    4141{{{
    4242ffmpeg -f mpegts -i udp://127.0.0.1:5678 -vcodec libx264 -t 30 output.flv
    4343}}}
    44 
    45 This 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.
    4644
    4745= Download =
     
    4947The source code of the modified Samplicator tool can be found here: [http://ffmpeg.gusari.org/uploads/samplicator-1.3.6-z.tar.gz]
    5048
    51 Keep 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.
     49Keep in mind it is in early 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.
    5250
    5351Happy lightning hunting :)