Search code examples
.netwindowsffmpeg

Streaming an Updating Folder of Images with FFmpeg Without Restarting the Script


I'm working on a project where I need to stream a series of images stored in a folder using FFmpeg. My current command looks like this:

ffmpeg -stream_loop -1 -f image2 -framerate 5 -i "C:\Images\%d.bmp" -c:v libx264 -preset ultrafast -tune zerolatency -crf 35 -pix_fmt bgra -vf format=bgra -f mpegts "udp://127.0.0.1:8554?pkt_size=1316&buffer_size=64k"

Initially, the folder contains:

Input:
1.bmp
2.bmp
3.bmp
.
.
.
N.bmp

Running this command successfully streams the images. However, new images (e.g., N2.bmp) might be added to the folder during runtime, and I need these new images to be included in the stream without restarting FFmpeg.

Challenges:

  1. I need to include newly added images in the ongoing stream without rerunning the FFmpeg command.
  2. I delete the .bmp files after they are streamed to avoid filling up my hard disk, so rerunning the command is not an option.

Additional Context:

The FFmpeg command is embedded within my .NET program, which handles the deletion of images after they are streamed. This ensures that my PC's hard disk does not fill up, but it also means I cannot simply restart the FFmpeg command whenever new images are added.

Question:

Is there a way to configure FFmpeg or use an additional tool to dynamically update the input source to include newly added images without stopping and restarting the FFmpeg command?

Any guidance or suggestions on how to achieve this would be greatly appreciated. Thank you!


Solution

  • For me my result was to implement NamedPipeServerStream and use it as my input using the following command:

     ffmpeg -f image2pipe -re -framerate 5 -i \\.\pipe\imagePipe -c:v libx264 -preset ultrafast -tune zerolatency -crf 35 -pix_fmt yuv444p -f mpegts "udp://127.0.0.1:8554?pkt_size=1316&buffer_size=64k"
    

    And after an image was converted into byte[] and flushed down the pipe, I've deleted it.