Answers.Body: <p>You can transform the stream to hls, then you can add the subtitle to every fragment. Make sure that the subtitle and the stream are in sync. After adding the subtitles you can move the new m3u8 file and fragments to be served by nginx. This will add few seconds of latency to your stream ( depending on the fragment duration and fragment count )</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-18T09:09:32.030Z
Answers.LastActivityDate: 2021-11-18T09:09:32.030Z
Answers.UserDisplayName: Methnani Bilel
Body: <p>In my live streaming scenario I need to grab a video source and inject subtitles that I generate algorithmically during the stream (i.e. I do not know the subtitles upfront), and publish the streams together.</p>
  <p>From what documentation and examples I found <code>-f srt</code> input is always from a file, not a stream, or the subtitles already arrive inside a container stream.</p>
  <p>To test, a naive approach of mine was to send UDP packets like this one:</p>
  <pre><code>00:00:05,000 --&gt; 00:00:06,999
  Hello World
  
  </code></pre>
  <p>and consume them as follows</p>
  <pre><code>ffmpeg -f srt -i udp://localhost:1233 \
  -c:s mov_text out.mp4
  </code></pre>
  <p>This does not work which may be obvious to all folks familiar with FFmpeg. I am having a hard time identifying why this does not work or how else to approach the problem, probably because this is not a usual use case?</p>
  
Tags: <ffmpeg><streaming><subtitles><live>
Title: Can I inject subtitles into a live stream with FFmpeg?
UserDisplayName: ilmiacs
ThreadText: # Can I inject subtitles into a live stream with FFmpeg?
  
  (Asked by: username_0 on 2021-11-04)
  
  In my live streaming scenario I need to grab a video source and inject subtitles that I generate algorithmically during the stream (i.e. I do not know the subtitles upfront), and publish the streams together.
  
  From what documentation and examples I found `-f srt` input is always from a file, not a stream, or the subtitles already arrive inside a container stream.
  
  To test, a naive approach of mine was to send UDP packets like this one:
  
  ```
  00:00:05,000 --> 00:00:06,999
  Hello World
  
  ```
  
  and consume them as follows
  
  ```
  ffmpeg -f srt -i udp://localhost:1233 \
  -c:s mov_text out.mp4
  
  ```
  
  This does not work which may be obvious to all folks familiar with FFmpeg. I am having a hard time identifying why this does not work or how else to approach the problem, probably because this is not a usual use case?
  
  **Tags:** ffmpeg, streaming, subtitles, live
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-11-18. Score: 0
  
  You can transform the stream to hls, then you can add the subtitle to every fragment. Make sure that the subtitle and the stream are in sync. After adding the subtitles you can move the new m3u8 file and fragments to be served by nginx. This will add few seconds of latency to your stream ( depending on the fragment duration and fragment count )
  
  
  ---
  
  