Opened 12 years ago

Last modified 10 years ago

#1753 open enhancement

Delay output for X seconds

Reported by: burek Owned by:
Priority: wish Component: avfilter
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

It would be nice to add a feature where the output could be delayed for certain amount of time (specified in seconds or hh:mm:ss.mmm). One use case for this might be the case where we want to capture the video, only when a certain event occurs (like lightning bolt, robbery or trespassing for example). If we start capturing the output at that exact moment, we might loose some valuable time, but if the output was buffered, then capturing would start in the past, enabling people to record an important event.

How to make use of the feature?

Start one ffmpeg to capture and buffer the webcam input (the output will start after 10 seconds and will continue real-time, always being late for 10 seconds, comparing to the current time):

ffmpeg -f v4l2 -i /dev/video0 -vf delay 10 -af delay 10 -f mpegts udp://localhost:1234

Start another ffmpeg only when some important event occurs (triggered by the sensor or something similar):

ffmpeg -f mpegts -i udp://localhost:1234 -map 0 -c copy capture.avi

Obviously capture.avi will start recording from the past, considering the current time the event was triggered, which will allow the beginning of the event to get recorded as well.

Change History (11)

comment:1 by burek, 12 years ago

I can't edit the original text, but there is a mistake. Instead of "-vf delay 10 -af delay 10" it should say "-vf delay=10 -af delay=10"

comment:2 by burek, 11 years ago

If this is not viable to implement at the filter level, then it might be done as an output option "-delay <seconds>" to be used like this:

ffmpeg -f v4l2 -i /dev/video0 -delay 10 -f mpegts udp://localhost:1234

The expected result should be that the output is always 10 seconds late in comparison to the input.

comment:3 by Clément Bœsch, 11 years ago

This -delay option doesn't seem to even be recognized at all anymore anyway. Possibly a dec/enc flag issue.

in reply to:  3 ; comment:4 by Carl Eugen Hoyos, 11 years ago

Replying to ubitux:

This -delay option doesn't seem to even be recognized at all anymore anyway.

Please elaborate...

in reply to:  4 ; comment:5 by Clément Bœsch, 11 years ago

Replying to cehoyos:

Replying to ubitux:

This -delay option doesn't seem to even be recognized at all anymore anyway.

Please elaborate...

FFmpeg 1.2:

% ffmpeg -f v4l2 -i /dev/video0 -delay 20 -vcodec rawvideo -f mpegts udp://127.0.0.1:1234
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
  built on May 10 2013 16:31:05 with gcc 4.8.0 (GCC) 20130502 (prerelease)
  configuration: --prefix=/usr --disable-debug --disable-static --enable-avresample --enable-dxva2 --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-postproc --enable-runtime-cpudetect --enable-shared --enable-vdpau --enable-version3 --enable-x11grab
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[video4linux2,v4l2 @ 0x1447080] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 1773.705972, bitrate: 110592 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, 110592 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Output #0, mpegts, to 'udp://127.0.0.1:1234':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> rawvideo)
Press [q] to stop, [?] for help
frame=   59 fps= 30 q=0.0 Lsize=   28627kB time=00:00:01.96 bitrate=119242.2kbits/s    
video:26550kB audio:0kB subtitle:0 global headers:0kB muxing overhead 7.821740%

FFmpeg git/master:

% ./ffmpeg -f v4l2 -i /dev/video0 -delay 20 -vcodec rawvideo -f mpegts udp://127.0.0.1:1234
ffmpeg version N-53432-gaccbb7b Copyright (c) 2000-2013 the FFmpeg developers
  built on May 25 2013 01:08:59 with gcc 4.8.0 (GCC) 20130502 (prerelease)
  configuration: --enable-gpl --enable-version3 --enable-fontconfig --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-x11grab --enable-libopenjpeg --enable-libass --enable-libmodplug --enable-libv4l2 --cc=colorgcc --samples=/home/ubitux/fate-samples --prefix=/tmp/ffinstall --disable-runtime-cpudetect --enable-libcelt --enable-libopencv --enable-frei0r --enable-libcaca --enable-libiec61883 --enable-libopencore-amrwb --enable-libopencore-amrnb --enable-libopus --enable-libpulse --enable-libspeex --enable-libquvi --assert-level=2 --enable-libzmq --enable-libschroedinger
  libavutil      52. 34.100 / 52. 34.100
  libavcodec     55. 12.100 / 55. 12.100
  libavformat    55.  7.100 / 55.  7.100
  libavdevice    55.  1.101 / 55.  1.101
  libavfilter     3. 70.100 /  3. 70.100
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 1766.944404, bitrate: 147456 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Codec AVOption delay () specified for output file #0 (udp://127.0.0.1:1234) is not an encoding option.

That wiki page is mentioning such command: http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20capture%20a%20lightning%20%28thunderbolt%29%20with%20FFmpeg

in reply to:  5 ; comment:6 by Carl Eugen Hoyos, 11 years ago

Replying to ubitux:

Replying to cehoyos:

Replying to ubitux:

This -delay option doesn't seem to even be recognized at all anymore anyway.

Please elaborate...

FFmpeg 1.2:

% ffmpeg -f v4l2 -i /dev/video0 -delay 20 -vcodec rawvideo -f mpegts udp://127.0.0.1:1234
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers

Are you sure -delay has any effect in this command line?
I may miss something but I don't think so.

in reply to:  6 comment:7 by Clément Bœsch, 11 years ago

Replying to cehoyos:

Replying to ubitux:

Replying to cehoyos:

Replying to ubitux:

This -delay option doesn't seem to even be recognized at all anymore anyway.

Please elaborate...

FFmpeg 1.2:

% ffmpeg -f v4l2 -i /dev/video0 -delay 20 -vcodec rawvideo -f mpegts udp://127.0.0.1:1234
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers

Are you sure -delay has any effect in this command line?
I may miss something but I don't think so.

Probably not; I was unable to get something working from the examples in that page anyway. The behaviour is just different now (aborting instead of ignoring). That may be the appropriate thing to do in that case though (but wiki needs to be updated).

comment:8 by burek, 11 years ago

The wiki says it clearly:
"Now, this all looks great, except FFmpeg doesn't have (yet) a "-delay <seconds>" option"

The page mentions that it would be great if such option would exist, which would avoid all the workaround explained in that wiki page.

Just to clear things up, this is a feature request, and the issue is marked as such. The "-delay" option was never before implemented in ffmpeg.

P.S. This is actually a request for a buffered output and could be implemented with a simple circular buffer, which would buffer the output frames up until PTS of the first frame in the buffer and PTS of the last frame in the buffer differ for more than <seconds> seconds, in which case the first packet in the buffer would be released from the buffer and sent to the real output.

Last edited 11 years ago by burek (previous) (diff)

comment:9 by Carl Eugen Hoyos, 11 years ago

@ubitux, @saste:
Do you finally believe me?
Or is there any more proof needed to convince you?

comment:10 by Elon Musk, 10 years ago

This is just filter that buffers frames from input and drop older frames from buffer
when they appear to not be needed any more.

When something interesting happens (for example another sensor filter finds something),
filter would just stop buffering and will start returning all frames from
cache and any other frames from input.

Both encoding and sensor filter would need to be done in realtime anyway
as caching have limits.

comment:11 by Elon Musk, 10 years ago

Component: undeterminedavfilter
Status: newopen
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.