-1

I am trying to use ffmpeg to create a video out of an image file that is overwritten constantly. I'm checking the documentation and I can see this is achievable in reverse:

ffmpeg -y -f v4l2 -video_size 1280x720 -i /dev/video0 \
       -r 0.2 -qscale:v 2 -update 1 /tmp/webcam.jpg

Is there a way I can recreate this video file from this /tmp/webcam.jpg file that is being overwritten constantly with the new frame? Ie: Specify a time to loop over the same image?

In this case, an application is sending a new image every split second via a socket and being saved to /tmp/image.jpg. I need to convert it to a one minute video for example whilst that image is being rewritten.

Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • Creating a video from a single image is [simple](https://stackoverflow.com/questions/25891342/creating-a-video-from-a-single-image-for-a-specific-duration-in-ffmpeg). The "overwritten" part is puzzling. May I ask why does the image being overwritten and not saved with different file name? Are you planning to solve it using a single command line, or using a script? – Rotem Dec 11 '21 at 22:56
  • Do you have any control over that (IMHO stupid) application? – tink Dec 12 '21 at 00:11
  • I have no control over it @tink – Jaquarh Dec 12 '21 at 11:54
  • Its overwritten because its a metasploitable module that captures the desktop and saves it as an image resistively. I was looking to use a command but if its only achievable with a script then I guess it'll have to be done with a script @Rotem – Jaquarh Dec 12 '21 at 11:55
  • The issue I have is that, currently, it outputs to a `html` which refreshes to load the new image. It is hosted externally and thus doesn't have a web-server. `python -m http.server` cannot manage the requests and without building a full HTTP server (with authorisation so others could not view it) then its inaccessible hosted on a VPS. I'm wondering if there is an easier way before I start configuring Apache and building a web app to do it properly. – Jaquarh Dec 12 '21 at 11:59
  • I don't know enough to tell if it's possible. is it possible to create a named pipe with the name "tmp/webcam.jpg"? – Rotem Dec 12 '21 at 16:51
  • That would be a good idea, have a named pipe that perhaps reads the images into some sort of memory (whether that be a database or something) and then just use bash to loop for a minute pushing the image into the pipe. I could then use ffpmeg on all the images but is this an effective way to do this task? @Rotem – Jaquarh Dec 12 '21 at 19:47
  • My idea was a bit simpler - see my answer. It's probably not going to work, because you probably can't make you app writing to a named pipe. You may use a script that keeps reading the image, and write to a pipe. I don't know how can you complete the task before the file is overwritten. – Rotem Dec 12 '21 at 21:37

1 Answers1

2

Named pipe "proof of concept":

  • Create named pipe in Linux terminal:

     mkfifo webcam_pipe
    
  • Execute FFmpeg command that reads from named pipe and writes video to webcam.mkv file:

     ffmpeg -y -r 1 -f image2pipe -vcodec mjpeg -i webcam_pipe -vcodec copy webcam.mkv
    
  • Open another console, and Execute FFmpeg command that writes JPEG images to the named pipe at 1Hz (60 seconds long):

     ffmpeg -y -re -f lavfi -i testsrc=size=1280x720:rate=1 -t 60 -vcodec mjpeg -f image2pipe webcam_pipe
    

It's also working when the pipe name is /tmp/webcam.jpg

In your case "application is sending a new image via a socket", and I have no idea if it's going to work...

Rotem
  • 30,366
  • 4
  • 32
  • 65