2

I'm busy with FFmpeg streaming to a RTMP server. What I'm trying to do is stream a png file that changes content. The PNG file is been created by PhantomJS every 1 second. The file is not bigger then 2MB.

when the content of the PNG file is changed, I get the error:

[png @ 0xe91740] chunk too big Error while decoding stream #0:0: Invalid data found when processing input

This works fine but it breaks at some point with:

[flv @ 0xe8a9c0] Failed to update header with correct duration.

[flv @ 0xe8a9c0] Failed to update header with correct filesize.

I know the problem is caused because FFmpeg still remembers the previous file data, and encoded the new file with those settings.

This is the command line I use:

 ffmpeg -y -re -stream_loop -1 -f image2 -i image.png -strict -1 \
 -c:v libx264 -preset veryfast -maxrate 1000k -bufsize 1000k \
 -pix_fmt yuv420p -g 50 -threads 1 -f flv rtmp://server/live/test \
 -nostdin -nostats -hide_banner > /dev/null &

I use Ubuntu Server.

Community
  • 1
  • 1
RyanT
  • 21
  • 2
  • 3
    The image update has to be atomic. Write to file1.png and then `mv file1.png file2.png`. Feed `file2.png` to ffmpeg. You can also add `-framerate 5` to increase read interval by ffmpeg, and add `-r 25` to restore output framerate. – Gyan Oct 10 '18 at 12:47
  • 1
    How did you solve your problem? – drkostas Mar 28 '19 at 22:52
  • 1
    @drkostas I solved it with the help of this answer https://stackoverflow.com/a/21405279/988591. Basically I wrote some code that detects changes to the image (using the Watchdog lib) and when that happens 1) it reads the image file, 2) it prepares (opens) another file for writing, 3) moves the writing head (seek) at the beginning it, 4) commits the writing operation to it. This way of isolating the various operations seems to guarantee that the actual write operation (#4) is atomic and in my case it works flawlessly. – Redoman Mar 26 '22 at 03:36
  • 1
    @Redoman I used this library and worked like a charm: https://python-atomicwrites.readthedocs.io/en/latest/ – drkostas Jun 03 '22 at 23:36
  • @drkostas yeah I tried that lib but in my case it didn't work; for some reason my code was still causing non-atomic updates, so in the end I had to do it manually as I said above and it worked. – Redoman Jun 05 '22 at 08:18

0 Answers0