[FFmpeg-user] Transcoding individual segments of HLS?

David Johansen davejohansen at gmail.com
Wed Mar 20 03:14:18 EET 2024

On Sat, Mar 16, 2024 at 11:31 AM David Johansen <davejohansen at gmail.com>

> On Sat, Mar 16, 2024 at 12:56 AM Def Etienne <shaker.doc at gmail.com> wrote:
>> Sent from my iPhone
>> > On 16 Mar 2024, at 06:44, David Johansen <davejohansen at gmail.com>
>> wrote:
>> >
>> > I've used ffmpeg to convert an H.264 .mp4 to segments for HLS playback
>> and
>> > it works. I'd like to then transcode them to H.265 so that it's
>> available
>> > as well, and I'd like to process them as individual segments so it can
>> be
>> > done in parallel.
>> >
>> > I'm doing that by creating a manifest that has the init.mp4 and single
>> > segment and then outputting just that segment, but when I do that, it
>> will
>> > only playback the first segment and then stop. I believe that something
>> is
>> > going wrong with the PTS and/or DTS values when I do this.
>> >
>> > I tried using -copyts but it didn't change the output and I also
>> disabled
>> > B-frames because it made the PTS values of the resulting HLS appear in
>> > sequential order as the original one does, but it still won't play in
>> the
>> > browser.
>> >
>> The command you used and the complete  uncut console output (a good
>> posting guideline) is always a good starting point for anyone who wants to
>> help.
> Sorry, I should have included that.
> Here's the command to convert the file to HLS segments:
> ffmpeg -i input.mp4 -c:v copy -c:a copy -map v:0 -map a:0 -tag:v hvc1
> -hls_segment_type fmp4 -hls_init_time 5.9 -hls_time 6 -hls_list_size 10000
> -hls_flags "independent_segments+program_date_time+temp_file"
> -master_pl_name index.m3u8 -var_stream_map "v:0,agroup:aud
> a:0,agroup:aud,default:yes" -f hls "%v/index.m3u8"
> Then I make a manifest file for each segment that looks like this:
> #EXT-X-MAP:URI=init.mp4
> #EXTINF:<duration>
> <segment.m4s>
> And then I run this command to transcode each segment:
> ffmpeg -i segment.m3u8 -c:v libx265 -tag:v hvc1 -x265-params
> "log-level=warning:no-wpp=1:lookahead-slices=0" -hls_segment_type fmp4
> -hls_init_time 5.9 -hls_time 6 -f hls video.m3u8
> I tried adding bframes=0 to -x265-params and that made the PTS values be
> sequential like the original input, but the player still only showed the
> first segment. I also tried adding -copyts and -muxdelay 0 but that didn't
> change the output.

It appears that the issues is that that libx265 encoder is ignoring the
input PTS values, so is there a way to tell it to use those or pass in a
value to use?
(I tried using -bsf:v setts but then it set every frame to that PTS value
and I could get it to do anything else)

More information about the ffmpeg-user mailing list