c怎么起子c 判断进程是否运行运行ffmpeg

FFMpeg的码率统制 - C语言当前位置:& &&&FFMpeg的码率统制FFMpeg的码率统制&&网友分享于:&&浏览:0次FFMpeg的码率控制mediaxyz是一位研究ffmpeg有三年的高人了,这几天一直在折腾ffmpeg中的x264,就是不知道该如何控制码率,主要是参数太多,也不知道该如何设置,在google上search了一下,这方面的介绍为0,那就找mediaxyz请教请教吧,这些可都是经验,非常宝贵!
以下是与mediaxyz在QQ上聊天的记录,只有一部分,因为QQ把之前的谈话删除了,但基本上精髓都可这里了。
mediaxyz 23:40:26
你说的qsable是c-&global_quality吧
Leon 23:40:44
br值的设定规则,是100kbps 就为 100*1024 吧?
mediaxyz 23:41:07
mediaxyz 23:41:26
你有没有发现,ffmpeg是100*1000
mediaxyz 23:41:37
并不是100*1024
Leon 23:41:28
Leon 23:42:13
我看到有这样一句话:
& &qscale 以&数值&质量为基础的VBR,取值0.01-255,越小质量越好
mediaxyz 23:42:30
而且在后面的处理中还是/1000
mediaxyz 23:42:43
mediaxyz 23:42:51
越小质量越好,码率越大
Leon 23:42:55
那0.01-255范围也太大了吧!
mediaxyz 23:43:29
这是为了精细控制,实际上没必要
mediaxyz 23:43:42
我测试0。01-50就可以了
mediaxyz 23:43:52
再大图像很糟糕
Leon 23:43:55
global_quality有什么作用?
mediaxyz 23:44:18
反正老外总是想的很周到
mediaxyz 23:44:35
global_quality你说的 &数值&质量
Leon 23:44:36
就是我说的qscale值?
mediaxyz 23:45:01
Leon 23:45:01
这个值能不能动态的调整?
mediaxyz 23:45:56
我没有试过
mediaxyz 23:46:07
按照ffmpeg的调用规则,好像不行
Leon 23:46:32
按照你的说话,VBR设定如下几个值就可以了:
c-&flags |= CODEC_FLAG_QSCALE;
c-&rc_min_rate =
c-&rc_max_rate =
c-&bit_rate =
br是平均码率
是这样吗?
mediaxyz 23:47:06
mediaxyz 23:47:51
也就是这样设置的码率会在Min,max之间波动
mediaxyz 23:48:11
如果设置qscale,则波动范围是非常大的,
mediaxyz 23:48:21
c-&rc_min_rate =
c-&rc_max_rate = max都控制不了
Leon 23:48:27
Leon 23:48:29
还有一个帧率的问题,在x264编码方式下,我设定了5帧,为什么不起作用?
AVRational time_
time_base.num = 1;
time_base.den = 5;
c-&time_base= time_
mediaxyz 23:49:05
你是实时,还是转码?
Leon 23:48:55
mediaxyz 23:49:23
mediaxyz 23:49:27
实时可以控制
mediaxyz 23:49:38
控制的方法就是控制图像捕获的帧率传入就行了
mediaxyz 23:49:48
靠x264本身不行
Leon 23:49:42
呵呵,明白了!
Leon 23:50:04
我本想靠ffmpeg来控制的,就是不行!
mediaxyz 23:51:12
帧率控制是说:播放是的帧率
Leon 23:51:03
在ffmpeg中,time_base只是起到一个时间戳增量的作用,并不能控制帧率,对吧!
mediaxyz 23:51:31
不管你选择5还是10,时间戳是按照播放设置的
mediaxyz 23:52:11
播放的时候,读取这个按照5或者10计算的时间戳才设定播放时间区间,这个时候才其作用
Leon 23:53:21
如果输入的流是25帧,而我设的确是5,会产生什么后果吗,我这儿的测试结果是没有什么影响?
mediaxyz 23:53:37
不过ffmpeg的码率控制对x264不起作用
mediaxyz 23:53:53
Leon 23:54:02
ffmpeg的码率控制对x264不起作用?按照前面的设定了也不能控制x264的码率?
mediaxyz 23:54:30
如果是实时捕获的,则捕获程序会丢弃
mediaxyz 23:54:42
这些情况我都测试过了
mediaxyz 23:55:07
本想写个ffmpeg心得,实在没有时间
Leon 23:55:10
如果是实时捕获的,则捕获程序会丢弃?如何理解?
mediaxyz 23:56:09
捕获程序有一个缓存,如果到特定时间,还没有把缓存中的数据清空,则自动丢弃
mediaxyz 23:56:23
directshow,vfw都是这样的
Leon 23:56:16
我现在想通过实时采集的视频,用x264编码,采用VBR,就是你前面说的几个参数设定,能起作用吗?
mediaxyz 23:56:57
那你最好采用第二种方法
Leon 23:57:01
c-&flags |= CODEC_FLAG_QSCALE;
c-&rc_min_rate =
c-&rc_max_rate =
c-&bit_rate =
mediaxyz 23:57:29
mediaxyz 23:57:32
mediaxyz 23:57:34
( 23:30:54) & mediaxyz()
c-&bit_rate =
& & & & & & & & c-&rc_min_rate =
& & & & & & & & c-&rc_max_rate =
& & & & & & & & c-&bit_rate_tolerance =
& & & & & & & & c-&rc_buffer_size=
& & & & & & & & c-&rc_initial_buffer_occupancy = c-&rc_buffer_size*3/4;
& & & & & & & & c-&rc_buffer_aggressivity= (float)1.0;
& & & & & & & & c-&rc_initial_cplx= 0.5;
Leon 23:57:29
mediaxyz 23:57:56
第一种波动太大
mediaxyz 23:58:09
说糊涂了,不好意思
mediaxyz 23:58:14
第二种波动太大
Leon 23:59:20
可是波动太大也就其好处,当画面静止时,码流就很小,活动时,码流才上来,是这样的吗?
mediaxyz 23:59:49
mediaxyz 23:59:58
如果是网络上传输,这种情况就惨了
Leon 00:00:12
我认为:网络上传输,这种情况应该更合适
mediaxyz 00:00:32
&码流才上来&,上来的可能会非常大
mediaxyz 00:00:52
是的,更合适,如果非常大,怎么办?
Leon 00:01:24
非常大?不是通过c-&rc_max_rate =可以控制其最高码率吗?
mediaxyz 00:02:15
我刚才说,理论上是这样的,但ffmpeg实际没有实现
mediaxyz 00:02:19
ffmpeg的缺点
Leon 00:02:21
max就是我预计网络能承载的最大负荷。
Leon 00:02:31
喔,然来如此!
mediaxyz 00:03:02
ffmpeg中的h263,h263p比mpeg4要控制的好
mediaxyz 00:03:07
x264更糟糕
mediaxyz 00:04:39
睡觉了,改天再聊
Leon 00:04:32
不过在同等码率下,x264的视频质量要比其它的都好,比较的细腻。但其编码的效率不高。
mediaxyz 00:05:13
windows的x264已经非常不错了
Leon 00:05:18
如果你不介意,我把今天的内容发到论坛上,也算是你的经验吧!
mediaxyz 00:05:54
Leon 00:05:46
得出的结论:
ffmpeg中CBR(固定码率控制)的设置:
& & & & & & & & c-&bit_rate =
& & & & & & & & c-&rc_min_rate =
& & & & & & & & c-&rc_max_rate =
& & & & & & & & c-&bit_rate_tolerance =
& & & & & & & & c-&rc_buffer_size=
& & & & & & & & c-&rc_initial_buffer_occupancy = c-&rc_buffer_size*3/4;
& & & & & & & & c-&rc_buffer_aggressivity= (float)1.0;
& & & & & & & & c-&rc_initial_cplx= 0.5;
ffmpeg中VBR(可变率控制)的设置:
& & & & & & & & c-&flags |= CODEC_FLAG_QSCALE;
& & & & & & & & c-&rc_min_rate =
& & & & & & & & c-&rc_max_rate =
& & & & & & & & c-&bit_rate =
刚才经过实验,得出如下结论:
ffmpeg的CBR可以控制得非常好,与设定值br十分接近
ffmpeg的VBR控制得非常不好,最高码流max没有限制住
与mediaxyz的说话完全吻合。
感谢mediaxyz奉献如此宝贵的经验。
我粗略的看了一下对话内容
我可以肯定的说:
80%以上的内容都是错误的,标准的误人子弟!
CODEC_FLAG_QSCALE;
表示固定量化,与VBR没有关系!具体怎么用你看看MpegEncContext中的成员:fixed_qscale,以及AVFrame中的quality就知道了
实际上FFmpeg的VBR和CBR都控制不好
但是从实验的数据来看,ffmpeg的CBR确实控制的不错,我设定值是50kbps,实际测试值平均为49.7kbps,编码器是x264,CIF格式,5fps。
& & VBR目前还没有找到好的解决方案,Fastreaming 你可以把你的VBR设值参数帖出来,探讨一下。
我按楼主说的CBR和 VBR进行设置,br=12*1000和br=10*1000进行测试,在对编码后的数据按秒计算平均值,结果差不多,不知道哪里错了,测试代码如下:
in_c-&time_base.den = 25;
& & & & in_c-&time_base.num = 1;
& & & & &bitrate=12000;
& & &in_c-&bit_rate =
& & &in_c-&rc_min_rate =
& & &in_c-&rc_max_rate =
& & &in_c-&bit_rate_tolerance =
& & &in_c-&rc_buffer_size=
& & &in_c-&rc_initial_buffer_occupancy = in_c-&rc_buffer_size*3/4;
& & &in_c-&rc_buffer_aggressivity= (float)1.0;
& & &in_c-&rc_initial_cplx= 0.5;
& & & & in_c-&bit_rate=2000;//bitrate/100; & //12*1000k/s,低码流。值越大视频质量越好,值越小码流越低。MpegEncContext.qscale---量化参数。
& & & & in_c-&gop_size = 10; /* emit one intra frame every ten frames */
& & & & in_c-&max_b_frames=0;//两个非b帧之间的最大b帧数。
// & & & &in_c-&flags
& & & & in_c-&pix_fmt = PIX_FMT_YUV420P;
我在测试x264的cbr时,发现不加qcomp = 0,很容易vbv buffer underflow,但是加了之后,发现控制的非常好,而且没出现过vbv buffer underflow,请问这个qcomp 是什么用途。
`-qcomp compression'
video quantizer scale compression (VBR) (default 0.5). Constant of ratecontrol equation. Recommended range for default rc_eq: 0.0-1.0
谁能讲讲啊,对视频质量又是有何影响啊目前发现的一个影响是cpu(P%.... 1fps
我使用的命令:ffmpeg&-i d:\\test_video\\hd\\js.mpg -bufsize 1835008 -maxrate 6000000 -minrate 6000000 -b 6000000 -packetsize 2048 -muxrate
-vcodec libxavs d:\\test_video\\6kbps.mpg
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有如何用ffmpeg录像并存储到本地_百度知道
如何用ffmpeg录像并存储到本地
提问者采纳
0kB global headers: Invalid argumentframe= 1 fps= 0 q=6. 0libavdevice 52, 320x240:Stream #0:03:ffmpeg -f video4linux -s 320*240 -r 10 -i /sStream #0.00 tb(r)Output #0, et al.00 tb(c)Stream mapping, asf.5 Lsize= 32kB time=0:0kB muxing overhead 11,video0 test: N/, Copyright (c)
Fabrice Bellard. 1: msmpeg4; 49; 52;&#47:22. 0 / 52.0 -&gt.25.2Input #0, video4linux: Video, q=2-31. 0libavcodec 52.3, 10, yuv420p, from &#39, start.062058: V 52;video0&#39, 10;s video.0:Stream #0;dev&#47. 1;;s.14.asf运行的结果是FFmpeg version SVN-r16967.14, yuv420p, 9216 kb/A;dev&#47, 320x240;s.0: 9216 kb&#47:28kB audio:Duration.0Press [q] to stop encodingVIDIOCMCAPTURE.10 bitrate=2594. 0built on Feb 3 2009 15: rawvideo: .configuration. 0 &#47. 0 &#47.5kbits&#47.11.11: --enable-pthreads --enable-x11grab --enable-memalign-hack --enable-gpl --enable-libmp3lame --disable-vhooklibavutil 49, 200 kb&#47. 0 &#47. 0libavformat 52.asf&#39: 4.25; #0, gcc, to &#39您好,您试试
其他类似问题
为您推荐:
ffmpeg的相关知识
下载知道APP
随时随地咨询
出门在外也不愁How can I normalize audio using ffmpeg? - Super User
to customize your list.
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
Here's how it works:
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I want the loudest peak sound in a movie clip to be as loud as the codec allows, then have every other sound amplified accordingly.
What's a practical example in order to accomplish this using ffmpeg?
45.2k27135234
Built-in Normalization Filters
Current ffmpeg has two filters that can be directly used for normalization – although they are already quite advanced, so they do not simply apply gain. Here they are:
: loudness normalization according to EBU R128. You can set an integrated loudness target, a loudness range target, or maximum true peak. This is recommended for publishing audio and video.
: “intelligent” loudness normalization without clipping, which applies normalization dynamically over windowed portions of the file. This may change the characteristics of the sound, so it should be applied with caution.
If you want a “simple” RMS-based normalization to 0 dBFS, read on.
For the lazy ones:
I created , . You simply:
(choose a static build)
put the ffmpeg executable in your $PATH by either adding it in, for example, /usr/local/bin, or
To install: Either run pip install ffmpeg-normalize or in the source code, run python setup.py install.
Once the script is installed, use ffmpeg-normalize
On Ubuntu / Debian:
sudo apt-get install ffmpeg python-pip
sudo pip install ffmpeg-normalize
For example, to normalize the audio of every MP4 file to 0 dB, run this:
ffmpeg-normalize *.mp4
It'd output WAV files with the normalized audio, using the prefix normalized-. You have to merge the audio back into the original files. See
on how to do it.
Using ffmpeg to normalize audio
In ffmpeg you can use the volume filter to change the volume of a track. Make sure you
of the program.
This guide is for peak normalization, meaning that it will make the loudest part in the file sit at 0 dB instead of something lower. There is also RMS-based normalization which tries to make the average loudness the same across multiple files. To do that, do not try to push the maximum volume to 0 dB, but the mean volume to the dB level of choice (e.g. -26 dB).
Find out the gain to apply
First you need to analyze the audio stream for the maximum volume to see if normalizing would even pay off:
ffmpeg -i video.avi -af "volumedetect" -f null /dev/null
Replace /dev/null with NUL on Windows. This will output something like the following:
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] histogram_0db: 87861
As you can see, our maximum volume is -5.0 dB, so we can apply 5 dB gain. If you get a value of 0 dB, then you don't need to normalize the audio.
Apply the volume filter:
Now we apply the
to an audio file. Note that applying the filter means we will have to re-encode the audio stream. What codec you want for audio depends on the original format, of course. Here are some examples:
Plain audio file: Just encode the file with whatever encoder you need:
ffmpeg -i input.wav -af "volume=5dB" output.mp3
Your options are very broad, of course.
AVI format: Usually there's MP3 audio with video that comes in an AVI container:
ffmpeg -i video.avi -af "volume=5dB" -c:v copy -c:a libmp3lame -q:a 2 output.avi
Here we chose quality level 2. Values range from 0–9 and lower means better. Check the
for more info on setting the quality. You can also set a fixed bitrate with -b:a 192k, for example.
MP4 format: With an MP4 container, you will typically find AAC audio. We can use ffmpeg's build-in AAC encoder.
ffmpeg -i video.mp4 -af "volume=5dB" -c:v copy -c:a aac -strict experimental -b:a 192k output.mp4
Here you can also use other AAC encoders. Some of them support VBR, too. See
for some tips.
In the above examples, the video stream will be copied over using -c:v copy. If there are subtitles in your input file, or multiple video streams, use the option -map 0 before the output filename.
120k37290349
Here's a script to normalize sound levels of .m4a files. Watch out if the sound levels are too quiet to start with. The final sound can be better if you use something like Audacity in that case.
#!/bin/bash
# Purpose: Use ffmpeg to normalize .m4a audio files to bring them up to max volume, if they at first have negative db volume. Doesn't process them if not. Keeps bitrate same as source files.
# Parameters: $1 should be the name of the directory containing input .m4a files.
$2 should be the output directory.
INPUTDIR=$1
OUTPUTDIR=$2
&&"COMMENT"
# For ffmpeg arguments /questions/323119/how-can-i-normalize-audio-using-ffmpeg
# /blog//ffmpeg-converting-m4a-files-to-mp3-with-the-same-bitrate/
ffmpeg -i test.m4a -af "volumedetect" -f null /dev/null
ffmpeg -i test.m4a -af "volumedetect" -f null /dev/null 2&&1 | grep max_volume
# output: max_volume: -10.3 dB
ffmpeg -i test.m4a -af "volumedetect" -f null /dev/null 2&&1 | grep 'max_volume\|Duration'
Duration: 00:00:02.14, start: 0.000000, bitrate: 176 kb/s
# [Parsed_volumedetect_0 @ 0x7f] max_volume: -10.3 dB
ffmpeg -i test.m4a -af "volumedetect" -f null /dev/null 2&&1 | grep max_volume | awk -F': ' '{print $2}' | cut -d' ' -f1
# Output: -10.3
ffmpeg -i test.m4a 2&&1 | grep Audio
# output: Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 170 kb/s (default)
ffmpeg -i test.m4a 2&&1 | grep Audio | awk -F', ' '{print $5}' | cut -d' ' -f1
# output: 170
# This works, but I get a much smaller output file. The sound levels do appear normalized.
ffmpeg -i test.m4a -af "volume=10.3dB" -c:v copy -c:a aac -strict experimental output.m4a
# Operates quietly.
ffmpeg -i test.m4a -af "volume=10.3dB" -c:v copy -c:a aac -strict experimental -b:a 192k output.m4a -loglevel quiet
# $1 (first param) should be the name of a .m4a input file, with .m4a extension
# $2 should be name of output file, with extension
function normalizeAudioFile {
INPUTFILE=$1
OUTPUTFILE=$2
DBLEVEL=`ffmpeg -i ${INPUTFILE} -af "volumedetect" -f null /dev/null 2&&1 | grep max_volume | awk -F': ' '{print $2}' | cut -d' ' -f1`
# We're only going to increase db level if max volume has negative db level.
# Bash doesn't do floating comparison directly
COMPRESULT=`echo ${DBLEVEL}'&'0 | bc -l`
if [ ${COMPRESULT} -eq 1 ]; then
DBLEVEL=`echo "-(${DBLEVEL})" | bc -l`
BITRATE=`ffmpeg -i ${INPUTFILE} 2&&1 | grep Audio | awk -F', ' '{print $5}' | cut -d' ' -f1`
# echo $DBLEVEL
# echo $BITRATE
ffmpeg -i ${INPUTFILE} -af "volume=${DBLEVEL}dB" -c:v copy -c:a aac -strict experimental -b:a ${BITRATE}k ${OUTPUTFILE} -loglevel quiet
echo "Already at max db level:" $DBLEVEL "just copying exact file"
cp ${INPUTFILE} ${OUTPUTFILE}
for inputFilePath in ${INPUTDIR}/*; do
inputFile=$(basename $inputFilePath)
echo "Processing input file: " $inputFile
outputFilePath=${OUTPUTDIR}/$inputFile
normalizeAudioFile ${inputFilePath} ${outputFilePath}
I can not comment on the best message so that is my ugly bash based on it to do that
ffmpeg -i sound.mp3 -af volumedetect -f null -y nul && original.txt
grep "max_volume" original.txt & original1.tmp
sed -i 's|: -|=|' original1.tmp
if [ $? = 0 ]
sed -i 's| |\r\n|' original.tmp
sed -i 's| |\r\n|' original.tmp
sed -i 's| |\r\n|' original.tmp
sed -i 's| |\r\n|' original.tmp
grep "max_volume" original1.tmp & original2.tmp
sed -i 's|max_volume=||' original2.tmp
yourscriptvar=$(cat "./original2.tmp")dB
rm result.mp3
ffmpeg -i sound.mp3 -af "volume=$yourscriptvar" result.mp3
ffmpeg -i result.mp3 -af volumedetect -f null -y nul && result.txt
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Super User works best with JavaScript enabled}

我要回帖

更多关于 ffmpeg c 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信