0

I have a c# application where I have control of an ffmpeg (https://www.ffmpeg.org/) process. I am using it to capture video and audio, either from desktop or webcam. I am using code similar to the answer from this question (https://stackoverflow.com/questions/45206312/how-to-pause-resume-ffmpeg-video-capture-in-windows-from-c-sharp-application) to suspend and resume the process. However, while suspended, the captured video extends the frame it was suspended on for the entire duration of the suspension.

My arguments passed into the process:

-f gdigrab -framerate 30 -i desktop -f dshow -i audio="Stereo Mix (Realtek(R) Audio)" -preset ultrafast -pix_fmt rgb24 output.mp4

I have tried adding -vf setpts=N/FR/TB to my arguments, and this works partially. It successfully prevents the extended frame, but then seriously affects the playback speed of the video.

How do I prevent this extended frame from occurring, or prevent the additional argument from affecting the playback speed of the video?

My ideal outcome is to have the process record, be suspended then resumed, and have the video play normally without having captured anything while suspended.

Record for 10 seconds, suspend for 20 seconds, record for 30 seconds, end recording -> should result in a 40 second video that plays back at normal speed.

I would love for a c# solution, but I believe the solution may be specific to the arguments I am passing in.

12
  • This is rather nasty. What does the resulting video "look like" at the frame level - is it one frame which has a very long timestamp? Can you do timestamp correction post-processing? Could you just kill and restart the capture instead?
    – pjc50
    Commented Jun 25 at 14:12
  • @pjc50 As far as I can tell, it is one frame with a very long timestamp. I don't know a ton about the video side of things. Visually, if you play the video, it'll play normally, then for the 20 or so seconds the process is suspended, it shows the same frame for the duration. Due to the requirements of the software I'm working with, I can't kill and restart the process. Commented Jun 25 at 15:01
  • Alternate solution: use the Windows APIs for capture learn.microsoft.com/en-us/windows/uwp/audio-video-camera/… - more work but more control. Why is kill and restart not an option?
    – pjc50
    Commented Jun 25 at 15:42
  • @pjc50 I can't kill and restart because every process needs to be continuously running, sometimes upwards of a couple hours. Specifically there are some timing constraints that make completely stopping the process not feasible. And as much as I would like to use something other than ffmpeg, ffmpeg is passed down from above as what we are using. Commented Jun 25 at 16:00
  • gdigrab uses the system clock to assign timestamps. So, if you pause/resume, you will get a gap. Record in different instances and then use concat demuxer to join the segments.
    – Gyan
    Commented Jun 26 at 4:39

0

You must log in to answer this question.

Browse other questions tagged .