Use ffmpeg to delay webcam feed with dshow displayed locally

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
Hi - I'm trying to use ffmpeg to add a fixed delay (in the range of 5-10 seconds) to a dshow webcam, outputting to the local display.
The base command I'm using is:ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -pix_fmt yuv420p -f sdl2 "SDL OUT"
I have tried to use various filters such as cue, loop, and buffer, as well as itsoffset but haven't been able to get it to actually delay.
The result that I'm looking for is essentially what happens when you use ffplay to display the webcam feed, and then pause it for 5-10 seconds.  If there is a commandline way to make this happen with ffplay, I'm happy to do that as well.
Thanks for any help!

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
> On Feb 12, 2019, at 12:44 PM, scott denton <[hidden email]> wrote:
>
> I have tried to use various filters such as cue, loop, and buffer, as well as itsoffset but haven't been able to get it to actually delay.

Try the tpad filter.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
 Hi Ted,
Thanks for your quick response!  I tried this, and it basically popped up the video window and left it blank for a while, then transitioned directly to a non-delayed video feed.ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -pix_fmt yuv420p -filter:v tpad=start_duration=500 -f sdl2 "SDL OUT"
I also tried the following which cloned the first frame for a while, then went to a non-delayed video feed:ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -pix_fmt yuv420p -filter:v tpad=start=2000:start_mode=clone -f sdl2 "SDL OUT"
So neither one appears to be actually delaying the full video feed - only delaying the *start* of the video which then jumps back to real time after that initial delay.
Am I implementing the tpad filter the way you were thinking?
Thanks again for your help!!
Scott
   On Tuesday, February 12, 2019, 10:50:08 AM PST, Ted Park <[hidden email]> wrote:  
 
 > On Feb 12, 2019, at 12:44 PM, scott denton <[hidden email]> wrote:
>
> I have tried to use various filters such as cue, loop, and buffer, as well as itsoffset but haven't been able to get it to actually delay.

Try the tpad filter.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".  
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
Oh. I thought you had the opposite problem for some reason. Using cue with buffer didn’t do this for you?
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
In reply to this post by scott denton
Hi - it very well might, but I'm not sure how to combine those.  Would you be willing to give me an example?

Thanks again!


--------------------------------------------
On Tue, 2/12/19, Ted Park <[hidden email]> wrote:

 Subject: Re: [FFmpeg-user] Use ffmpeg to delay webcam feed with dshow displayed locally
 To: "FFmpeg user questions" <[hidden email]>
 Date: Tuesday, February 12, 2019, 12:18 PM
 
 Oh. I thought you had the
 opposite problem for some reason. Using cue with buffer
 didn’t do this for you?
 _______________________________________________
 ffmpeg-user mailing list
 [hidden email]
 http://ffmpeg.org/mailman/listinfo/ffmpeg-user
 
 To unsubscribe, visit link
 above, or email
 [hidden email]
 with subject
 "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
> Hi - it very well might, but I'm not sure how to combine those.  Would you be willing to give me an example?

There is a buffer parameter for the cue filter, you can just set it a reasonable number of seconds bigger than your delay introduced by cue. In bash, you can set something like

cue=cue=(`date +%s`+$DELAY)*1000000:buffer=20

(The cue timestamp is in microseconds)
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
 Hi Ted,
Thank you so much for your help and suggestions.  I tried a few different permutations of what you recommended, but without luck.  :(

It seems that nothing I'm trying does anything other than *delay the start* of the video.  The video itself still isn't delayed. 

For example, I tried the following command:export this_date=`date +%s`;this_date=`echo \($this_date+10\)*1000000|bc`;./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -pix_fmt yuv420p -filter:v cue=cue=$this_date:buffer=20 -f sdl2 "SDL OUT"

It shows a white output screen for 10 seconds, then it shows what appears to be a very fast set of "catchup" frames for a fraction of a second, then shows the live video stream again with no delay.
Commandline output is below.  Thanks again for your help with this!
-Scott
** Commandline output**
 libavcodec     58. 46.100 / 58. 46.100
  libavformat    58. 26.100 / 58. 26.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, dshow, from 'video=Integrated Webcam':
  Duration: N/A, start: 93371.403000, bitrate: N/A
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 160x120, 30 fps, 30 tbr, 10000k tbn, 10000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, sdl,sdl2, to 'SDL OUT':
  Metadata:
    encoder         : Lavf58.26.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 160x120, q=2-31, 6912 kb/s, 30 fps, 30 tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.46.100 rawvideo
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 73 >= 73
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 84 >= 84
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 97 >= 97
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 109 >= 109
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 120 >= 120
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 133 >= 133
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 144 >= 144
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 252 >= 252
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 264 >= 264
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 276 >= 276
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 289 >= 289
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 300 >= 300
[sdl,sdl2 @ 00000257dc497180] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 312 >= 312
av_interleaved_write_frame(): I/O errore=00:00:13.66 bitrate=N/A speed=   1x
frame=  423 fps= 30 q=-0.0 Lsize=N/A time=00:00:14.16 bitrate=N/A speed=   1x





    On Wednesday, February 13, 2019, 6:50:32 AM PST, Ted Park <[hidden email]> wrote:  
 
 > Hi - it very well might, but I'm not sure how to combine those.  Would you be willing to give me an example?

There is a buffer parameter for the cue filter, you can just set it a reasonable number of seconds bigger than your delay introduced by cue. In bash, you can set something like

cue=cue=(`date +%s`+$DELAY)*1000000:buffer=20

(The cue timestamp is in microseconds)
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".  
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
> It shows a white output screen for 10 seconds, then it shows what appears to be a very fast set of "catchup" frames for a fraction of a second, then shows the live video stream again with no delay.

Oh. :s Does chaining setpts=expr=PTS+$DELAY/TB work? (Sorry I’m throwing all the spaghetti against the wall till something sticks)

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
 Hi Ted,
Thank you - I definitely appreciate all of the suggestions.  It seems like with the cue filter, frames are getting buffered and then at the end of the start delay, they all play through really quickly. It makes me wonder if there isn't some index that needs to be updated to basically tell it to not start at the beginning, but somewhere in the middle of the buffer.  You can see I tried using setpts in combination with the cue filter, and also tried adding the fifo statement but I really don't know how any of these interact.  I'm wondering if there is some combination of buffer filter and cue filter?  I'm having a hard time getting the buffer statement to work.

I tried all of the following (and more), but with no success. 

All of the following just shows live input:
./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts=expr=PTS+10/TB -pix_fmt yuv420p -f sdl2 "SDL_OUT"

$ ./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts='expr=PTS+10/(TB*1000000)' -pix_fmt yuv420p -f sdl2 "SDL_OUT"

 $ ./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts='(RTCTIME-RTCSTART+10)/(TB*1000000)' -pix_fmt yuv420p -f sdl2 "SDL_OUT"

$ ./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts='(RTCTIME-RTCSTART-10)/(TB*1000000)' -pix_fmt yuv420p -f sdl2 "SDL_OUT"

All of the following shows a delayed start to the video (blank white screen), then realtime video:
export this_date=`date +%s`;this_date=`echo \($this_date+10\)*1000000|bc`;./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter cue=cue=$this_date:buffer=20,setpts='(RTCTIME-RTCSTART+10)/(TB*1000000)' -pix_fmt yuv420p -f sdl2 "SDL_OUT"

export this_date=`date +%s`;this_date=`echo \($this_date+10\)*1000000|bc`;./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts='(RTCTIME-RTCSTART+10)/(TB*1000000)',cue=cue=$this_date:buffer=20 -pix_fmt yuv420p -f sdl2 "SDL_OUT"

export this_date=`date +%s`;this_date=`echo \($this_date+5\)*1000000|bc`;./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter fifo,cue=cue=$this_date:buffer=20 -pix_fmt yuv420p -f sdl2 "SDL_OUT"



    On Thursday, February 14, 2019, 5:23:20 AM PST, Ted Park <[hidden email]> wrote:  
 
 > It shows a white output screen for 10 seconds, then it shows what appears to be a very fast set of "catchup" frames for a fraction of a second, then shows the live video stream again with no delay.

Oh. :s Does chaining setpts=expr=PTS+$DELAY/TB work? (Sorry I’m throwing all the spaghetti against the wall till something sticks)

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".  
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
> ./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts=expr=PTS+10/TB -pix_fmt yuv420p -f sdl
ohhh wait. SDL gives you a hw surface to draw on if I understand correctly? So it will happily gobble up frames and draw them fast as it can whenever it gets it, I doubt they are even timestamped.

You need the 10 seconds of delayed frames to be stored anyway (I was thinking of keeping them in memory) so I would say just write to file and play back after delay. There is no output at realtime function.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

scott denton
 Hi Ted,
Thanks again for all your suggestions.  Ok, I will try to get this delay with a file, or something like that.
I'm curious though, what happens function / command wise when you hit the pause key because this ends up producing the results I'm looking for.  When you hit the pause key and then 10 seconds un-pause it, you end up with a live stream which is 10 seconds delayed.
I guess what you are saying is there is not a good way to replicate that using the filters or other options?
Scott


    On Thursday, February 14, 2019, 1:28:59 PM PST, Ted Park <[hidden email]> wrote:  
 
 > ./ffmpeg.exe -f dshow -video_size 160x120 -framerate 30 -i video="Integrated Webcam" -filter setpts=expr=PTS+10/TB -pix_fmt yuv420p -f sdl
ohhh wait. SDL gives you a hw surface to draw on if I understand correctly? So it will happily gobble up frames and draw them fast as it can whenever it gets it, I doubt they are even timestamped.

You need the 10 seconds of delayed frames to be stored anyway (I was thinking of keeping them in memory) so I would say just write to file and play back after delay. There is no output at realtime function.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".  
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Use ffmpeg to delay webcam feed with dshow displayed locally

kumowoon1025
> I'm curious though, what happens function / command wise when you hit the pause key because this ends up producing the results I'm looking for.  When you hit the pause key and then 10 seconds un-pause it, you end up with a live stream which is 10 seconds delayed.
I don’t know, but it isn’t ffmpeg that does this. It must be the sdl library.

> I guess what you are saying is there is not a good way to replicate that using the filters or other options?
It’s something I would have used ffserver for, now I don’t think there’s a way without writing to an intermediate streaming format.

> Ok, I will try to get this delay with a file, or something like that.
And it doesn’t have to be a regular file, it shouldn’t be if you don’t want a full recording. You could pipe a stream to another FFmpeg, write to a fifo, unix socket, something that functions as a circular buffer.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".