<p>You need to disable the video and audio streams with <code>-an</code> and <code>-vn</code> options respectively, then use the generic <code>segment</code> output format instead of <code>hls</code>.</p>
<p>The <strong><a href="https://ffmpeg.org/ffmpeg-all.html#segment_002c-stream_005fsegment_002c-ssegment" rel="nofollow noreferrer">segment muxer</a></strong> can produce HLS playlist format if the output file format has <code>.m3u8</code> extension.</p>
<p><em>Copied from my answer on S:O (<a href="https://stackoverflow.com/a/76920564/1957951">https://stackoverflow.com/a/76920564/1957951</a>):</em></p>
<p>Here's an example that creates segmented <code>VTT</code> subtitles with <code>0000.vtt</code> filename format and a playlist named <code>index.m3u8</code>.
Please note that FFmpeg automatically determines the internal format of the playlist by analyzing the file extension of the <code>-segment_list</code>, but this can be set with the <code>segment_format</code> option.</p>
<p><strong>Command breakdown:</strong></p>
<pre><code>ffmpeg -y -hide_banner -i input.mp4 \
-vn \                       # drop all video streams
-an \                       # drop all audio streams
-map s:0 \                  # select the first embedded subtitle stream
-f segment \                # use generic segment format
-segment_time 3.0 \         # set segment duration
-segment_list index.m3u8 \  # set playlist filename (internal format determined by extension)
%04d.vtt
</code></pre>
<p><strong>Output files:</strong></p>
<p>By printing the contents of a subtitle segment, you can see that these contain only fragments of the original subtitle:</p>
<pre><code>$ cat 0000.vtt
WEBVTT

00:00.000 --&gt; 00:02.880
you may have seen videos in which someone is using  

00:02.880 --&gt; 00:06.660
an old computer when it suddenly 
makes popping and crackling noises
</code></pre>
<p>The command produces a playlist in HLS format:</p>
<pre><code>$ head -n9 index.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:12
#EXTINF:6.660000,
0000.vtt
#EXTINF:6.120000,
0001.vtt
</code></pre>

CC BY-SA 4.0
2023-08-24T17:24:26.470Z
I honestly forgot that I ever asked that question.

The current solution saves the subtitles as a separate file and provides that to the frontend. The frontend then is responsible for overlaying the subtitles. It's a pretty hacky solution, but it got me around and allows for ass subtitles.

I'll try it out and see if I can integrate it into the current solution. Thanks for your response!
Euklios
CC BY-SA 4.0
2023-08-25T07:50:24.247Z
No probs! I've recently run into the same issue and I tought I'll check if someone else had the same problem. :D
Gergely Lukacsy
CC BY-SA 4.0
2023-08-17T10:23:23.153Z
2023-08-17T10:28:46.573Z
2023-08-17T10:28:46.573Z
Gergely Lukacsy
<p>I'm trying to create an HLS subtitle playlist from subtitles embedded within a video file.
So the input looks something like this:</p>
<pre><code>container: mkv
  stream 0: video h264
  stream 1: audio aac
  stream 2: subtitle ass
</code></pre>
<p>And the output folder should look something like this:</p>
<pre><code>index.m3u8
subs_0.vtt
subs_1.vtt
subs_2.vtt
...
</code></pre>
<p>Currently, I get to the desired output by using the following two commands:</p>
<pre class="lang-bash prettyprint-override"><code>ffmpeg \
  -i in.mkv \
  -map 0:2 \
  -scodec webvtt \
  temp.vtt

ffmpeg -y \
  -i temp.vtt \
  -scodec webvtt \
  -f segment \
  -segment_list_type m3u8 \
  -segment_list_size 0 \
  -segment_time 6 \
  -segment_start_number 0 \
  -segment_format webvtt \
  -segment_list index.m3u8 \
  -map 0:0 \
  -scodec copy subs_%d.vtt
</code></pre>
<p>However, due to constraints in the surrounding system, I'd prefer to combine these two steps into a single command.
But, whenever I try that, the output file is collapsed to a single subs_0.vtt file.</p>
<p>Currently failing attempt:</p>
<pre class="lang-bash prettyprint-override"><code>ffmpeg -y \
  -f matroska,webm \
  -i in.mkv \
  -scodec webvtt \
  -f segment \
  -segment_list_type m3u8 \
  -segment_list_size 0 \
  -segment_time 6 \
  -segment_start_number 0 \
  -segment_format webvtt \
  -segment_list index.m3u8 \
  -map 0:2 \
  out_%d.vtt
</code></pre>
<p>This command only creates a single vtt file, rather than the desired segmented files.</p>
<p>Is there a way to combine the two commands without losing the segmentation?</p>
<p>Edit:</p>
<p>I'm not sure if this is relevant, so I'm going to add it here.
The failing command produces multiple &quot;Non-monotonous DTS in output stream&quot; messages.
It sources from &quot;segment&quot;, so I'd assume at least the correct format should be active, but maybe it prevents the segmented from splitting the file?</p>
<p>Example line:</p>
<pre><code>[segment @ 0000011cec905440] Non-monotonous DTS in output stream 0:0; previous: 90402, current: 90400; changing to 90403. This may result in incorrect timestamps in the output file.
</code></pre>

<ffmpeg><hls>
ffmpeg convert and segment subtitles
Euklios
# ffmpeg convert and segment subtitles

(Asked by: username_0 on 2022-08-29)

I'm trying to create an HLS subtitle playlist from subtitles embedded within a video file.
So the input looks something like this:
container: mkv
  stream 0: video h264
  stream 1: audio aac
  stream 2: subtitle ass

And the output folder should look something like this:
index.m3u8
subs_0.vtt
subs_1.vtt
subs_2.vtt
...

Currently, I get to the desired output by using the following two commands:
ffmpeg \
  -i in.mkv \
  -map 0:2 \
  -scodec webvtt \
  temp.vtt

ffmpeg -y \
  -i temp.vtt \
  -scodec webvtt \
  -f segment \
  -segment_list_type m3u8 \
  -segment_list_size 0 \
  -segment_time 6 \
  -segment_start_number 0 \
  -segment_format webvtt \
  -segment_list index.m3u8 \
  -map 0:0 \
  -scodec copy subs_%d.vtt

However, due to constraints in the surrounding system, I'd prefer to combine these two steps into a single command.
But, whenever I try that, the output file is collapsed to a single subs_0.vtt file.
Currently failing attempt:
ffmpeg -y \
  -f matroska,webm \
  -i in.mkv \
  -scodec webvtt \
  -f segment \
  -segment_list_type m3u8 \
  -segment_list_size 0 \
  -segment_time 6 \
  -segment_start_number 0 \
  -segment_format webvtt \
  -segment_list index.m3u8 \
  -map 0:2 \
  out_%d.vtt

This command only creates a single vtt file, rather than the desired segmented files.
Is there a way to combine the two commands without losing the segmentation?
Edit:
I'm not sure if this is relevant, so I'm going to add it here.
The failing command produces multiple "Non-monotonous DTS in output stream" messages.
It sources from "segment", so I'd assume at least the correct format should be active, but maybe it prevents the segmented from splitting the file?
Example line:
[segment @ 0000011cec905440] Non-monotonous DTS in output stream 0:0; previous: 90402, current: 90400; changing to 90403. This may result in incorrect timestamps in the output file.

**Tags:** ffmpeg, hls


---

## 1 answers

### Answer by username_1 on 2023-08-17. Score: 1

You need to disable the video and audio streams with -an and -vn options respectively, then use the generic segment output format instead of hls.
The segment muxer can produce HLS playlist format if the output file format has .m3u8 extension.
Copied from my answer on S:O (https://stackoverflow.com/a/76920564/1957951):
Here's an example that creates segmented VTT subtitles with 0000.vtt filename format and a playlist named index.m3u8.
Please note that FFmpeg automatically determines the internal format of the playlist by analyzing the file extension of the -segment_list, but this can be set with the segment_format option.
Command breakdown:
ffmpeg -y -hide_banner -i input.mp4 \
-vn \                       # drop all video streams
-an \                       # drop all audio streams
-map s:0 \                  # select the first embedded subtitle stream
-f segment \                # use generic segment format
-segment_time 3.0 \         # set segment duration
-segment_list index.m3u8 \  # set playlist filename (internal format determined by extension)
%04d.vtt

Output files:
By printing the contents of a subtitle segment, you can see that these contain only fragments of the original subtitle:
$ cat 0000.vtt
WEBVTT

00:00.000 --> 00:02.880
you may have seen videos in which someone is using  

00:02.880 --> 00:06.660
an old computer when it suddenly 
makes popping and crackling noises

The command produces a playlist in HLS format:
$ head -n9 index.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:12
#EXTINF:6.660000,
0000.vtt
#EXTINF:6.120000,
0001.vtt

> **Comments:**
> **username_0**: I honestly forgot that I ever asked that question.  The current solution saves the subtitles as a separate file and provides that to the frontend. The frontend then is responsible for overlaying the subtitles. It's a pretty hacky solution, but it got me around and allows for ass subtitles.  I'll try it out and see if I can integrate it into the current solution. Thanks for your response!  
> **username_1**: No probs! I've recently run into the same issue and I tought I'll check if someone else had the same problem. :D  

---

