Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncorrect video codec avc1 metadata in HLS output when format is set to mpegts #3483

Closed
LifelessMuffin opened this issue Oct 20, 2023 · 2 comments · Fixed by #3496
Closed

Comments

@LifelessMuffin
Copy link

Describe the bug
Uncorrect codec metadata present in index.m3u8 when encoding mpegts vs mp4 outputting as HLS. This gives issues with web players such as Theoplayer and hls.js. Also the audio seems to be unsync.

  • index.m3u8 video codec metadata when using mpegts
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2411200,CODECS="mp4a.40.2,avc1",RESOLUTION=640x360
low.m3u8
  • index.m3u8 video codec metadata when using mp4
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2411200,CODECS="mp4a.40.2,avc1.42c01f",RESOLUTION=640x360
low.m3u8

To Reproduce

  • Using mp4 format:
settings.root.max_latency.set(5.)
settings.clock.allow_streaming_errors.set(false)

input = input.srt(port=9000, mode="listener")

low = %ffmpeg(format="mp4", fflags="-autobsf", movflags="+dash+skip_sidx+skip_trailer+frag_custom", frag_duration=10, %audio(codec="aac",channels=2,ar=48000,b="192k"),%video.raw(codec="libx264",pixel_format="yuv420p",width=640, height=360,b="2000k",r=50,g=100,preset="medium",profile="baseline")).{id3 = false}

streams = [("low",low)]

def segment_name(~position,~extname,stream_name) =
  timestamp = int_of_float(time())
  duration = 2
  "#{stream_name}_#{duration}_#{timestamp}_#{position}.#{extname}"
end

output.file.hls(playlist="index.m3u8",
                fallible=true,
                segment_duration=2.0,
                segments=5,
                segments_overhead=5,
                segment_name=segment_name,
                "/var/www/liquidsoap/hls",
                streams,
                input)
  • Using mpegts format:
settings.root.max_latency.set(5.)
settings.clock.allow_streaming_errors.set(false)

input = input.srt(port=9000, mode="listener")

low = %ffmpeg(format="mpegts", fflags="-autobsf", %audio(codec="aac",channels=2,ar=48000,b="192k"),%video.raw(codec="libx264",pixel_format="yuv420p",width=640, height=360,b="2000k",r=50,g=100,preset="medium",profile="baseline")).{id3 = false}

streams = [("low",low)]

def segment_name(~position,~extname,stream_name) =
  timestamp = int_of_float(time())
  duration = 2
  "#{stream_name}_#{duration}_#{timestamp}_#{position}.#{extname}"
end

output.file.hls(playlist="index.m3u8",
                fallible=true,
                segment_duration=2.0,
                segments=5,
                segments_overhead=5,
                segment_name=segment_name,
                "/var/www/liquidsoap/hls",
                streams,
                input)

Expected behavior
When choosing mpegts format, the metadata contained into the index.m3u8 should be similar to the one printed when using mp4 format, something like avc1.42c01f

Version details

  • OS: Ubuntu 22.04
  • Version Liquidsoap 2.2.1

Install method
sudo apt-install liquidsoap and then manual upgrade with latest .deb file from this repo

Comments
Not entirely sure if this is a bug tho

@toots
Copy link
Member

toots commented Oct 21, 2023

Thanks for reporting. I checked back on the ffmpeg code where this comes from and it looks like in ffmpeg case, they would just output this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2411200,CODECS="mp4a.40.2",RESOLUTION=640x360
low.m3u8

Are you able to confirm that this would work as well?

@LifelessMuffin
Copy link
Author

Hi, thank you for your fast reply!
I'm not entirely sure about the question, but so far when outputting only audio then the codec is correct (both with and without re-encoding), the only issue comes with the video codec.
I sort of made it work with any web player (I used Theoplayer and hls.js for the tests) by manually specifying something like this into the Liquidsoap script:

transmux_high = %ffmpeg(format="mpegts", %audio.copy, %video.copy).{codecs = "mp4a.40.2,avc1.4d4015"}
transmux_medium = %ffmpeg(format="mpegts", %audio.copy, %video.copy).{codecs = "mp4a.40.2,avc1.4d4015"}
transmux_low = %ffmpeg(format="mpegts", %audio.copy, %video.copy).{codecs = "mp4a.40.2,avc1.4d4015"}

It's a bit of a "dirty fix" because if the h264 profile and level are changed then it would simply not work anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants