I am currently using ffmpeg-python
library to convert a .mp4
video into HLS format with output looking like this:
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?
Actually you can achieve the same without ffmpeg-python
. I'm the creator of VidGear Video Processing Python Project that contains StreamGear API for this very purpose. 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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.