0

I'm a C programmer on linux.

I write a program that saves an image in /srv/ftp/preview.png which is updating frequently and i want to create a movie from this updates.

It's timestamp is important for me, e.g if image updates after 3.654 seconds i want movie show this update(frame) after 3.654 seconds too.

I searched in Internet for several hours but i can't find any solution.

I know about ffmpeg but it will convert images(and not one image) to movie without millisecond timestamp.

I found this Question but it seems is not useful in this case.

Is there any tool to do that? if not, please introduce an API in c to write a program myself

milad
  • 1,854
  • 2
  • 11
  • 27
  • I hope it is not a stupid suggestion (I'm not too much into Linux programming) but couldn't you copy your image directly to the frame buffer as soon as you receive it ? – Guillaume Petitjean Nov 27 '19 at 07:31
  • @Gulaume Petitjean not at all, any suggestion is useful. I can copy image to a buffer immediately but then what should i do? how to convert these buffers to video? – milad Nov 27 '19 at 07:46
  • if you write directly to the frame buffer, you basically create a video. HOWEVER i'm not sure it is the best solution under Linux. Also there are probably issues of antialising or similar video specific issues. But basically when you decode a compressed format video (like H264) you reconstitute a set of pictures that you write to the frame buffer at the correct rate. – Guillaume Petitjean Nov 27 '19 at 07:51
  • I think I can't create video by copying images to a buffer directly because I read somewhere that frame buffers has additional headers and need a codec to compress and encode them. by the way, thank you for your attention. I give it a try. – milad Nov 27 '19 at 07:56

1 Answers1

0

You can try to use inotify watch modification on the file and ffmpeg to append file to the movie:

#!/bin/bash
FRAMERATE=1
FILE="/path/to/image.jgp"
while true 
do  inotifywait -e modify "$FILE"
    echo "file changed"
    # create temp file name
    TMP=$(mktemp)

    # copy file
    cp "$FILE" "$TMP$

    # append copy file to movie
    # from https://video.stackexchange.com/q/17228

    # if movie already exist
    if [ -f movie.mp4 ]
    then
        # append image to a new movie
        ffmpeg -y -i movie.avi -loop 1 -f image2 -t $FRAMERATE -i "$TMP".jpg   -f lavfi -t 3 -i anullsrc -filter_complex "[0:v] [1:v] concat=n=2:v=1 [v] "  -map "[v]" newmovie.avi
        # replace old by new movie
        mv newmovie.mp4 movie.mp4
    else   
        #create a movie from one image
        ffmpeg -framerate 1 -t $FRAMERATE -i "$TMP" movie.mp4
    fi
    rm "$TMP" 

done

This script must certainly be adapted, (in particular if your framerate is high) but I think you can try to play with it.

One bad thing also that the movie creation will become slower and slower because the movie becomes bigger.

You should to store images of a certain time duration in a directory and convert all at once (like once an hour/day)


If you want to serve a stream instead of creating a video file, you can look at https://stackoverflow.com/a/31705978/1212012

Mathieu
  • 8,840
  • 7
  • 32
  • 45