用FFMPEG创建HLS变体 [英] Creating HLS variants with FFMPEG

查看:413
本文介绍了用FFMPEG创建HLS变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用高分辨率视频文件,我想为移动流创建3种变体,低品质,中等质量和高品质。我想要将这些中/低/高变体分割成tsu,这个m3u8文件将被指向。有没有办法在ffmpeg中一行呢?



我已经使用ffmpeg成功生成了一个m3u8文件和ts段,我需要做3x并设置低/中/高的规格吗?如果是这样,如何获得单个m3u8文件指向所有变体,而不是每个变体一个?



这是我用来生成m3u8文件以及ts段的命令。



ffmpeg -i C:\Users\george\Desktop\video\hos.mp4 -strict -2 -acodec aac -vcodec libx264 -crf 25 C:\Users\user\Desktop\video\hos_Phone.m3u8

解决方案

是的,您需要对所有变体进行编码,并首先生成媒体播放列表(包含片段的播放列表)。



如果你想要它在一个命令中,因为 ffmepg 支持 multiple输入/输出的。例如:

  ffmpeg -i input \ 
... [encoding parameters 1] ... output1 \
... [encoding parameters 2] ... output2 \
.... [encoding parameters 3] ... output3

您必须提供多种质量/比特率的变体,但宽高比必须保持不变。



所有变体流必须是关键帧对齐,所以使用 -g 选项设置GOP大小,并使用段持续时间 hls_time 这是您的关键帧间隔的倍数。



一旦您拥有所有3x m3u8 媒体播放列表,您可以手动创建指向每个媒体播放列表的主播放列表。



Apple的示例 HLS文档,您必须根据自己的编码选项更改带宽,编解码器,分辨率和播放列表文件名:

 #EXTM3U 
#EXT-X-VERSION:6
#EXT-X-STREAM-INF:PROGRAM-ID = 1,BANDWIDTH = 2855600,CODECS =avc1.4d001f, mp4a.40.2,分辨率= 960x540
medium.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID = 1,BANDWIDTH = 5605600,CODECS =avc1.640028,mp4a.40.2解决方案= 1280x720
high.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID = 1,BANDWIDTH = 1755600,CODECS =avc1.42001f,mp4a.40.2,分辨率= 640x360
low.m3u8


I am starting with a high res video file and I would like to create 3 variants, low quality, mid quality, and high quality for mobile streaming. I want these mid/low/high variants to be segmented into ts pieces that the m3u8 file will be pointing that. Is there a way to do this in one line in ffmpeg?

I have successfully generated an m3u8 file and ts segments with ffmpeg, do I need to do this 3x and set specs for low/mid/high? If so, how do I get the singular m3u8 file to point to all variants as opposed to one for each variant?

This is the command I used to generate the m3u8 file along with the ts segments.

ffmpeg -i C:\Users\george\Desktop\video\hos.mp4 -strict -2 -acodec aac -vcodec libx264 -crf 25 C:\Users\user\Desktop\video\hos_Phone.m3u8

解决方案

Yes, you need to encode all variants and generate the media playlists first (the playlists containing the segments).

If you want you can do it in one command since ffmepg supports multiple inputs/outputs. Eg:

ffmpeg -i input \
    ... [encoding parameters 1] ... output1 \
    ... [encoding parameters 2] ... output2 \
    ....[encoding parameters 3] ... output3

You must provide the variants in multiple qualities/bitrates but the aspect ratio must remain the same.

All variant streams must be keyframe aligned so set a GOP size using the -g option and use a segment duration hls_time which is a multiple of your keyframe interval.

Once you have all 3x m3u8 media playlist you can manually create the master playlist which points to each media playlist.

Example from the Apple HLS documentation, you must change the bandwidth, codecs, resolution and playlist filenames according to your own encoding options:

#EXTM3U
#EXT-X-VERSION:6
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2855600,CODECS="avc1.4d001f,mp4a.40.2",RESOLUTION=960x540
medium.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=5605600,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1280x720
high.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1755600,CODECS="avc1.42001f,mp4a.40.2",RESOLUTION=640x360
low.m3u8

这篇关于用FFMPEG创建HLS变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆