[FFmpeg-user] update atomically

Simon Thelen ffmpeg-user at c-14.de
Wed Jan 28 10:40:41 CET 2015


On 15-01-28 at 09:20, Anthony Griffiths wrote:
> I stream video with text overlay and wish to change the text every few
> seconds, The text file I use is 'screentext.txt' and I update it by a
> line in a bash script thus:
> 'cp -f new-screentext.txt screentext.txt'
> However the ffmpeg stream process is crashing at random, blaming the
> screentext.txt file for being empty or unfound. The ffmpeg docs say
> the text file should be updated 'atomically'. What does that mean
> exactly? I expect it means as fast as possible but I don't know how to
> update the text file any faster. Is there some special way to update a
> file atomically? This constant crashing is a headache and I need the
> stream to be stable.
As long as you're not working with a network filesystem, you can
atomically update a symlink with `mv -Tf <new> <current>'
In this case you would instruct ffmpeg to read from <current> which
is a symbolic link pointing to screentext.txt (you can create such a
link with `ln -s screentext.txt current'), then when you want to update the
text, you would create new-screentext.txt with the text you want to
display, execute `ln -s new-screentxt.txt new', then `mv -Tf new
current'. Just make sure not to change new-screentxt.txt without
replacing the 'current' symlink again with a symlink pointing to a new
file.

-- 
Simon Thelen


More information about the ffmpeg-user mailing list