Как я могу использовать FFmpeg для добавления тикера / изменяющегося текста в живое видео?

3106
user763410

Я могу добавить текст к видео на моем жестком диске, прежде чем я сделаю это… с помощью команды.

ffmpeg -y -i IMG_0696.MOV -acodec libmp3lame -vcodec msmpeg4 \ -b:a 192k -b:v 1000k -ar 44100 \ -vf "drawtext=text=string1 string2 string3 string4 string5 string6 string7 :expansion=normal:fontfile=/Windows/Fonts/cambriai.ttf: y=0:x=h-(2*lh)-n: fontcolor=white: fontsize=40: box=1: boxcolor=0x00000000@1" \ -an IMG_0696.avi 

Теперь я хочу добавить разные тексты в разные моменты времени. Это должно быть прочитано из файла, который имеет формат:

00:00:10: Google 00:00:20: Yahoo 00:00:30: мсфт, ,, 00:00:60: amzn, ,, 00:05:30: Java 

Есть ли способ заставить ffmpeg читать файл и добавлять текст в указанное время? В конце концов, я хотел бы добавить символ тикера в видео перед его трансляцией.

2
Не уверен, есть ли способ сделать это «на лету», но если вы хотите добавлять текст через различные промежутки времени, лучше использовать такой формат субтитров, как .srt и муксинг напрямую, чтобы сказать контейнер mkv. Пример: `ffmpeg -i infile -i subtitle.srt -scodec copy -acodec copy -vcodec copy outfile.mkv`. Посмотрите в формате SRT. Rajib 10 лет назад 0

1 ответ на вопрос

1
Breakthrough

From the source code of the drawtext filter (from libavfilter/vf_drawtext.c in the source tree), there appears to be a textfile parameter which can specify a path to a file containing the string to draw (as opposed to setting the text parameter as in your example). You may want to experiment with passing it a filepath as textfile, and updating the file while viewing the video output.

You would also need another program/daemon running in parallel to update the file (which would just contain the current text to be displayed), but this program would be fairly trivial assuming you could synchronize it with the system clock.


Alternatively, you can modify the drawtext filter itself to display a particular string based on the current timecode (which is available to FFmpeg filters). While this would require modifying the filter's source code and recompiling from scratch, it would also avoid the use of a separate program/daemon running in parallel (as your own code would be invoked whenever FFmpeg tries to draw a string).

However, assuming the textfile parameter works (read: is updated every frame), that would probably be a better method, as a simple daemon to update the text file could be written in a scripting language like Python.

Спасибо большое. Я попробовал вариант ... но он в значительной степени ведет себя как текстовый вариант. И файл, кажется, читается все сразу (посмотрите на load_textfile () или строку 401). Если я не получу лучшего ответа, я попытаюсь изменить ffmpeg и посмотреть, работает ли он. user763410 10 лет назад 0

Похожие вопросы