如何减少ffmpeg的cpu使用率? [英] how to reduce cpu usage of ffmpeg?
问题描述
我正在将hls流作为hls流重播
hi i am restreaming an hls stream as a hls stream
SETLOCAL
:loop
ffmpeg -thread_queue_size 32768 -i "http://xx/636.m3u8" -f hls -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 -hls_flags delete_segments -segment_list_flags +live -hls_base_url "../ts/" -hls_segment_filename "C:\nginx\html\ts\lig-%random%%random%-%%3d.svgz" -y "C:\nginx\html\hls\lig1.m3u8" > log.txt
goto loop
但它使用%15-20 cpu我必须在同一台服务器上制作16个类似的流,但是我不能。
but it uses %15-20 of cpu i have to make 16 streams like that in same server but i can't.
我不能进行配置,就像只是下载.ts文件来克隆m3u8一样?
cant i make a configuration like just downloading .ts files cloning the m3u8?
推荐答案
默认情况下,即使您不使用任何与编码相关的参数,FFmpeg也会尝试重新编码输入。
By default, FFmpeg will try to reencode the input, even if you don't use any encoding related parameters.
如果只想按原样复制流,则应尝试使用流复制功能:
If you want to just copy the stream as is, you should try the streamcopy function:
-c:v copy -c:a copy
通过复制传入流,您可以完全跳过编码过程。
By copying the incoming streams, you can skip the encoding process entirely.
所以您的命令应如下所示:
So your command would look like this:
ffmpeg -thread_queue_size 32768 -i "http://xx/636.m3u8" -f hls -c:v copy -c:a copy -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 -hls_flags delete_segments -segment_list_flags +live -hls_base_url "../ts/" -hls_segment_filename "C:\nginx\html\ts\lig-%random%%random%-%%3d.svgz" -y "C:\nginx\html\hls\lig1.m3u8" > log.txt
(不过不确定是否可以。)
(Not sure if it'll work, though.)
当您需要对传入流进行重新编码时,应考虑向命令添加一些编码参数。
When you need to re-encode the incoming stream, you should consider to add some encoding parameters to the command.
默认情况下,ffmpeg尝试匹配源参数和质量,这在实时应用程序中并不总是最理想的。
By default, ffmpeg tries to match the source parameters and quality, which not always the most optimal in live applications.
非常快,超快速和超快速的h264预设是获得性能提升的良好开始。
The "veryfast, superfast and ultrafast" h264 presets is a good start to get some performance boost.
-c:v h264 -preset:v ultrafast
您还可以摆弄CRF(恒定速率因子)编码,更高的比特率等。
You can also fiddle with CRF (Constant Rate Factor) encoding, higher bitrates, etc.
有关H264加密的更多信息: https:// trac.ffmpeg.org/wiki/Encode/H.264
More about H264 enoding: https://trac.ffmpeg.org/wiki/Encode/H.264
这篇关于如何减少ffmpeg的cpu使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!