简体   繁体   English

多比特率 HLS 与 ffmpeg-python

[英]Multiple bitrates HLS with ffmpeg-python

I am currently using ffmpeg-python library to convert a .mp4 video into HLS format with output looking like this:我目前正在使用ffmpeg-python库将.mp4视频转换为 HLS 格式,输出如下所示:

ffmpeg.output(
    mp4_input,
    m3u8_name,
    format='hls', start_number=0, hls_time=5,
    hls_list_size=0,
),

How do I make ffmpeg-python output HLS with in multiple bitrates and create a master playlist for them?如何以多种比特率制作ffmpeg-python输出 HLS 并为它们创建主播放列表?

Actually you can achieve the same without ffmpeg-python .实际上,您可以在没有ffmpeg-python情况下实现相同的目标。 I'm the creator of VidGear Video Processing Python Project that contains StreamGear API for this very purpose.我是VidGear视频处理 Python 项目的创建者,项目包含用于此目的的StreamGear API。 The example code is as follows:示例代码如下:

# import required libraries
from vidgear.gears import StreamGear

# activate Single-Source Mode and also define various streams
stream_params = {
    "-video_source": "foo.mp4",
    "-streams": [
        {"-resolution": "1920x1080", "-video_bitrate": "4000k"},  # Stream1: 1920x1080 at 4000kbs bitrate
        {"-resolution": "1280x720", "-framerate": 30.0},  # Stream2: 1280x720 at 30fps framerate
        {"-resolution": "640x360", "-framerate": 60.0},  # Stream3: 640x360 at 60fps framerate
        {"-resolution": "320x240", "-video_bitrate": "500k"},  # Stream3: 320x240 at 500kbs bitrate
    ],
}
# describe a suitable master playlist location/name and assign params
streamer = StreamGear(output="hls_out.m3u8", format = "hls", **stream_params)
# trancode source
streamer.transcode_source()
# terminate
streamer.terminate()

and that's it.就是这样。 Goodluck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM