m1k1o / go-transcode

On-demand transcoding origin server for live inputs and static files in Go using ffmpeg. Also with NVIDIA GPU hardware acceleration.
Apache License 2.0
208 stars 38 forks source link

(WIP) Hls vod #17

Closed m1k1o closed 2 years ago

m1k1o commented 2 years ago

Transcode static files on demand.

fixes #12

m1k1o commented 2 years ago

It is already functional, just very basic proof of concept, can be called like this:

hlsVodManager := hlsvod.New(hlsvod.Config{
    MediaPath:     "/tmp/test.mp4",
    TranscodeDir:  "/tmp/out",
    SegmentPrefix: "foo",

    VideoProfile: &hlsvod.VideoProfile{
        Width:   1280,
        Height:  720,
        Bitrate: 4200,
    },
    AudioProfile: &hlsvod.AudioProfile{
        Bitrate: 128,
    },

    Cache: true,

    FFmpegBinary:  "ffmpeg",
    FFprobeBinary: "ffprobe",
})

err := hlsVodManager.Start()
if err != nil {
    log.Err(err)
    return
}

http.HandleFunc("/playlist.m3u8", hlsVodManager.ServePlaylist)
http.HandleFunc("/", hlsVodManager.ServeMedia)

log.Info().Msg("listening on :8080")
err = http.ListenAndServe(":8080", nil)
log.Err(err)

edit: added profiles after changes.

m1k1o commented 2 years ago

It has been added to API. You can call it using:

go run main.go serve --voddir /tmp/media/

Assuming file /tmp/media/test.mp4 exists, you can play it with http://127.0.0.1:8080/vod/test.mp4/default.m3u8.

m1k1o commented 2 years ago

TODO: