Answers.Body: <p>When ffmpeg will flush to output depends on the protocol. For file protocol, atleast 256 kiB data must be waiting, unless it's end of output. So, for text formats, there will be only one payload write.</p>
  
  <p>You can workaround by forcing ffmpeg to flush a stream after each packet.</p>
  
  <pre><code> ffmpeg -nostdin -i - -map 0:2 -c:0 webvtt -flush_packets 1 -f webvtt first.vtt \
  -map 0:3 -c:0 webvtt -flush_packets 1 -f webvtt second.vtt \
  -map 0:0 -c:0 copy -map 0:1 -c:1 aac \
  -use_timeline 1 -min_seg_duration 1000000 \
  -use_template 1 -init_seg_name $RepresentationID$-0.mp4s \
  -media_seg_name $RepresentationID$-$Number$.mp4s \
  -adaptation_sets "id=mkv/0,streams=0 id=mkv/1,streams=1" \
  -f dash -dash 1 out.mpd
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-07T03:12:30.327Z
Answers.Text: See also https://stackoverflow.com/questions/50574086/ffmpeg-flushing-output-file-every-chunk/50576757#50576757 for another example
Answers.UserDisplayName: rogerdpack
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-08T12:23:06.660Z
Answers.LastActivityDate: 2017-12-08T12:23:06.660Z
Answers.UserDisplayName: Gyan
Body: <p>I'm feeding ffmpeg from stdin and do several transcoding operations in one command only. The issue is that ffmpeg seems to transcode them(or at least write on disk) sequently (i.e. first it transcodes/writes audio/video and then it transcodes the subtitles). This way it takes minutes before you get any subtitle content which translates in a poor user experience(if the transcoding is "on demand"/live) because the client needs to wait for the subtitles even if the audio/video is ready(at least partially). 
    How can I change that? How can I make ffmpeg write the subtitles to the disk as soon as they are copied/transcoded?</p>
  
  <p>Note:  I believe the transcoding is done concurrently for the subtitles too but for some reasons it flushes/writes them on disk only after the audio/video transcoding completes. That's because there is no way ffmpeg could start reading the input from beginning after a/v transcoding is done because it can't seek/start over from stdin. </p>
  
  <p>Below is a sample of my command: </p>
  
  <pre><code> ffmpeg -nostdin -i - -map 0:2 -c:0 webvtt -f webvtt first.vtt \
  -map 0:3 -c:0 webvtt -f webvtt second.vtt \
  -map 0:0 -c:0 copy -map 0:1 -c:1 aac \
  -use_timeline 1 -min_seg_duration 1000000 \
  -use_template 1 -init_seg_name $RepresentationID$-0.mp4s \
  -media_seg_name $RepresentationID$-$Number$.mp4s \
  -adaptation_sets "id=mkv/0,streams=0 id=mkv/1,streams=1" \
  -f dash -dash 1 out.mpd
  </code></pre>
  
Tags: <ffmpeg><transcoding><subtitles>
Title: How to make ffmpeg flush the subtitles in real time while transcoding?
UserDisplayName: mike
ThreadText: # How to make ffmpeg flush the subtitles in real time while transcoding?
  
  (Asked by: username_0 on 2017-12-08)
  
  I'm feeding ffmpeg from stdin and do several transcoding operations in one command only. The issue is that ffmpeg seems to transcode them(or at least write on disk) sequently (i.e. first it transcodes/writes audio/video and then it transcodes the subtitles). This way it takes minutes before you get any subtitle content which translates in a poor user experience(if the transcoding is "on demand"/live) because the client needs to wait for the subtitles even if the audio/video is ready(at least partially).
  How can I change that? How can I make ffmpeg write the subtitles to the disk as soon as they are copied/transcoded?
  
  Note: I believe the transcoding is done concurrently for the subtitles too but for some reasons it flushes/writes them on disk only after the audio/video transcoding completes. That's because there is no way ffmpeg could start reading the input from beginning after a/v transcoding is done because it can't seek/start over from stdin.
  
  Below is a sample of my command:
  
  ```
   ffmpeg -nostdin -i - -map 0:2 -c:0 webvtt -f webvtt first.vtt \
  -map 0:3 -c:0 webvtt -f webvtt second.vtt \
  -map 0:0 -c:0 copy -map 0:1 -c:1 aac \
  -use_timeline 1 -min_seg_duration 1000000 \
  -use_template 1 -init_seg_name $RepresentationID$-0.mp4s \
  -media_seg_name $RepresentationID$-$Number$.mp4s \
  -adaptation_sets "id=mkv/0,streams=0 id=mkv/1,streams=1" \
  -f dash -dash 1 out.mpd
  
  ```
  
  **Tags:** ffmpeg, transcoding, subtitles
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-08. Score: 2 | Accepted answer
  
  When ffmpeg will flush to output depends on the protocol. For file protocol, atleast 256 kiB data must be waiting, unless it's end of output. So, for text formats, there will be only one payload write.
  
  You can workaround by forcing ffmpeg to flush a stream after each packet.
  
  ```
   ffmpeg -nostdin -i - -map 0:2 -c:0 webvtt -flush_packets 1 -f webvtt first.vtt \
  -map 0:3 -c:0 webvtt -flush_packets 1 -f webvtt second.vtt \
  -map 0:0 -c:0 copy -map 0:1 -c:1 aac \
  -use_timeline 1 -min_seg_duration 1000000 \
  -use_template 1 -init_seg_name $RepresentationID$-0.mp4s \
  -media_seg_name $RepresentationID$-$Number$.mp4s \
  -adaptation_sets "id=mkv/0,streams=0 id=mkv/1,streams=1" \
  -f dash -dash 1 out.mpd
  
  ```
  
  > **Comments:**
  > **username_2**: See also https://stackoverflow.com/questions/50574086/ffmpeg-flushing-output-file-every-chunk/50576757#50576757 for another example  
  
  ---
  
  