Say I have something like this
ffmpeg -i video.avi -ar 22050 -ab 32 -f flv -s 320x240 video.flv
-ar (Audio sampling rate in Hz)
-ab (Audio bit rate in kbit/s)
regarding the -ar and the -ab how do I know what rate to use? I got this ffmpeg command from a site somewhere and I was wondering how the person knew what values to put for the rates? Do I need to understand audio in order to figure that out?
Probably 44100 for audio sampling rate and 128 for bit rate should be sufficient.
Check Wikipedia's sampling rate and audio bit rate articles for examples to see if those values are too high or too low for what you're trying to do.
You have to use "ffmpeg -i video.avi" to know the sampling rate and the bitrate of the audio stream in the source video.avi.
The audio stream can be extracted with the same sampling rate and bitrate without lose quality.
You can decide to reduce one of them for size reasons, but don't increment one of them to increase quality because you never can't upgrade the original quality.
I'm using -ar 22050 and -ab 48 for Avi and Mpeg video files. It works normally.
Related
Whenever I use the ffmpeg commands, the video is larger and the seeking/keyframe inteval is not the same as the video rendered from Blender. How can I convert the following Blender settings to ffmpeg please?
Blender Settings:
Frame rate: 30
Codec: h.264
Output .mp4
Keyframe interval: 1
Output quality: Medium
Encoding speed: Good
Here's my current command however the seeking and file size is different:
ffmpeg -framerate 30 -i %04d.jpg -g 1 -vcodec libx264 video.mp4
ffmpeg -r 30 -i %04d.jpg -vcodec libx264 -crf 25 -x264-params keyint=30:scenecut=0 -preset veryslow video.mp4
Explanation:
-r 30 befor input pictures will say ffmpeg to use 30 pictures per second
-vcodec libx264 will let ffmpeg encode in plain old H.264
-crf 25 will let the encoder decide on the bitrate for a medium quality (lower it for better quality / higher file size, increase it for worse quality / lower file size. Need to find your right setting there through testing)
-x264-params keyint=30:scenecut=0 will tell the x264 encoder to set a keyframe every 30s frames (here 1s) and to disable scene detection. Be aware that this increases the file size a lot, you should not use a keyframe every second, except for livestreaming. Modern video encoders like AV1 will at most times set a keyframe every 10-20s based on scene detection.
-preset veryslow will use the best libx264 preset available to make the file as small as possible with H.264 (however needs more time to encode). If you want a faster encode but a larger file set it to slow.
Some general opinions from me:
If you don't need compatibility to very old devices rather encode with libx265 or 2-pass libvpx-vp9. This will save you a lot of space without quality loss. libx265 slow is even faster then libx264 veryslow for me.
When I transcode video to H265 with following command, I get a bitrate about 600K and the quality is almost the same as the original.
ffmpeg -i data2.mp4 -c:v libx265 -c:a copy d2.mp4
However when I use the hevc_nvenc, I get a very high bitrate (about 2M), I need to have a bitrate as low as possible and keeping almost the same quality.
ffmpeg -i data2.mp4 -c:v hevc_nvenc -c:a copy d3.mp4
It works if I specify the output bitrate, but I want to know how to figure out the proper bitrate?
There is no such thing as "proper bitrate". You get to choose the bitrate. if you don't, the encoder will choose on for you. In this case, you are using two different encoders, so you get different bitrates. You can change this by adding -b:v option to ffmpeg.
But that's probably not what you want. You probably want to use a constant quality factor by setting -crf to a value between 0 (Great quality large file) to 51 (bad quality small file)
Note that hevc_nvenc will almost produce larger files than libx265 at a given quality because it not as efficient as an encoder.
I have some audio (wave file) that is sampled at a rate of 48000 samples per second.
This audio was created to match a 30 FPS video. However, the video actually plays back on the target at the NTSC framerate of 29.97 (30 X 1000/1001).
This means that I need to time-dilate the audio so that there are 48048 samples where there were previously 48000 samples (it plays back 1.001 times slower) but still maintains that the final audio file's rate is 48000 samples per second.
Ideally, also, I'd like to do this resample using the sox library option for FFMPEG since I hear it has much higher quality.
Can anyone help me with the command line necessary to process a file in this manner?
Basic command is
ffmpeg -i in.wav -af asetrate=47952,aresample=48000:resampler=soxr out.wav
This assumes that libsoxr is linked.
When extracting Audio streams using ffmpeg from containers such as MP4, how does ffmpeg increase bitrate, if it is higher than the source bitrate?
An example might be ffmpeg -i video.mp4 -f mp3 -ab 256000 -vn music.mp3. What does ffmpeg do if the incoming bitrate is 128k? Does it interpolate or default to 128k on the output music.mp3? I know this seems like not a so-called "programming question" but ffmpeg forum says it is going out of business and no one will reply to posts there.
During transcoding, ffmpeg (or any transcoder) decodes the input into an uncompressed version; for audio, that's PCM. The encoder compresses this PCM data. It has no idea of, or interaction with, the original source representation.
If no bitrate is specified, ffmpeg will use the default rate control mode and bitrate of the encoder. For MP3 or AAC, that's typically 128 kbps for a stereo output . Although it can be lower, like 96 kbps for Opus. Encoders typically adjust based on no. of output channels. So for a 6-ch output, it may be 320 kbps. If a bitrate is specified, that's used unless the value is invalid (beyond the encoder's range). In which case, the encoder will fallback on its default bitrate selection.
I'm trying to perform a real-time encoding of a video using HEVC with ffmpeg. I'm able to achieve the required performance when running the x265 encoder separately without the support of ffmpeg. This way the my system can perform the encoding at 30 frames per second. However, my requirement is to create a MPEG-TS stream with the encoded content and therefore, the video is encoded with the ffmpeg as follows:
ffmpeg -s:v 1280x720 -i input.yuv -c:v libx265 -x265-params crf=20:keyint=25:fps=25:preset=ultrafast -f mpegts out.ts
Strangely, the performance of the encoding is reduced drastically and I'm only able to achieve an encoding performance of just 10 frames per second.
Is this a problem of the multiplexing process within ffmpeg?. Could someone please help me to resolve this issue.
Thanks.
This is can be a reason q factor in FFmpeg. You need to compare q value of FFmpeg and x265 bin. This is my guess.