Skip to content

HLS video support #1391

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

Merged
merged 1 commit into from
Nov 16, 2020
Merged

HLS video support #1391

merged 1 commit into from
Nov 16, 2020

Conversation

toots
Copy link
Member

@toots toots commented Oct 26, 2020

This PR adds video and mp4 format support to output.file.hls!

TODO:

  • Test with ffmpeg.copy
  • Test persistence with mp4 format
  • Cleanup default ISO codes and bitrate
  • Better convention for init segment name

Test script:

set("log.level",5)

source = playlist("~/Documents/playlist")

#source = single("/tmp/bla.mkv")

# To re-encode with liquidsoap internal format:
mpegts = %ffmpeg(
           format="mpegts",
           %audio(
              codec="aac",
              b="128k",
              channels=2,
              ar=44100
           ),
           %video(
             codec="libx264",
             b="5M"
           )
         )

mp4 = %ffmpeg(
        format="mp4",
        movflags="+dash+skip_sidx+skip_trailer+frag_custom",
        frag_duration=10,
        %audio(
          codec="aac",
          b="128k",
          channels=2,
          ar=44100),
        %video(
          codec="libx264",
          b="5M"
        )
      )

# To re-encode with ffmpeg raw frames:
mpegts = %ffmpeg(
           format="mpegts",
           %audio.raw(
              codec="aac",
              b="128k",
              channels=2,
              ar=44100
           ),
           %video.raw(
             codec="libx264",
             b="5M"
           )
         )

mp4 = %ffmpeg(
        format="mp4",
        movflags="+dash+skip_sidx+skip_trailer+frag_custom",
        frag_duration=10,
        %audio.raw(
          codec="aac",
          b="128k",
          channels=2,
          ar=44100),
        %video.raw(
          codec="libx264",
          b="5M"
        )
      )

# To copy without re-encoding:
mpegts = %ffmpeg(
           format="mpegts",
           %audio.copy,
           %video.copy)

mp4 = %ffmpeg(
        format="mp4",
        movflags="+dash+skip_sidx+skip_trailer+frag_custom",
        frag_duration=10,
        %audio.copy,
        %video.copy)

streams = [
  ("mpegts",mpegts),
  ("mp4", mp4)
]

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

output.file.hls(playlist="live.m3u8",
                segment_duration=2.0,
                segments=5,
                segments_overhead=5,
                segment_name=segment_name,
                #persist_at="/tmp/state.config",
                "/tmp/hls",
                streams,
                fallible=true,
                source)

@toots toots added this to the 2.0.0 milestone Oct 26, 2020
@smimram
Copy link
Member

smimram commented Oct 26, 2020

Wow great!! :)

@toots toots force-pushed the hls-key-frames branch 4 times, most recently from 13030dd to 3758ca4 Compare November 1, 2020 18:47
@toots toots marked this pull request as ready for review November 3, 2020 02:16
@toots toots requested a review from smimram November 3, 2020 02:19
@toots toots merged commit 1aa34b8 into master Nov 16, 2020
@toots toots deleted the hls-key-frames branch November 16, 2020 04:56
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 this pull request may close these issues.

2 participants