Log in

View Full Version : How force a constant bit rate for audio created with ffmpeg?


Starduster
12th October 2020, 02:25
I'm putting title pages between video clips and concatenating them together so I need all the clips to be the same. I am creating the title slides with:


fa=Tone(length=3.0, type="Silence", samplerate=22050, channels=2)
v=BlankClip(90, 960, 540, pixel_type="RGB24", fps=29.97).ConvertToYV12(matrix="rec709").AddAlphaPlane()
AudioDub(v, fa).Subtitle("This is a test", align=5, size=24)


I'm creating the .mp4 clip using ffmpeg with:

ffmpeg -i gsn_10.avs -b:a 128 gsn_10.mp4

if I use -b:a 128k or don't use that parameter at all, it becomes variable rate and I need constant rate. Using the -b:a 128 makes it constant, but the bit rate doesn't change.

MediaInfo gives: "Bit rate: 1 084 b/s" and all other clips have "Bit rate: 128 kb/s"

The bit rate is the only difference in the clips. When I concat them with:

ffmpeg -f concat -safe 0 -i render.txt -c copy highlight.mp4

I get a ton of "Non-monotonous DTS in output stream" errors.

The resulting .mp4 is 19+ hours long when I should be about 6 minutes.

So, is there a way to force a constant bit rate of 128kb in AviSynth or do I need to find another way to do that in ffmpeg.

FranceBB
12th October 2020, 07:36
So, is there a way to force a constant bit rate of 128kb in AviSynth or do I need to find another way to do that in ffmpeg.

Avisynth is a frameserver, i.e it doesn't encode anything, it outputs an uncompressed A/V stream which is "served" to an encoder (in your case, FFMpeg). So... no, you can't "force" a bitrate in Avisynth.
By the way, speaking of FFMpeg, setting -b:a 128k as you've done should set it to CBR (constant bitrate) 'cause AAC needs the flag -vbr to be encoded as variable bitrate.
The only thing I can think about is the fact that you're using the FFMpeg built-in AAC encoder for which this thing might not be true...? (I'm speculating).
Just to be sure, how about trying with libfdk_aac?

Can you try with:


ffmpeg -i "gsn_10.avs" -c:v libx264 -crf 18 -preset:v medium -ac 2 -c:a libfdk_aac -b:a 128k -f mp4 "gsn_10.mp4"


where the video settings have to be the same as the one of your other video (my command line is just for the sake of completeness) and the audio settings are the ones I provided?

tebasuna51
12th October 2020, 08:41
The bitrate must be: -b:a 128k

Seems work fine with a ffmpeg with enabled libfdk_aac.

The internal ffmpeg encoder seems can't encode silence at a CBR of 128k(uses 1084 b/s)

FranceBB
12th October 2020, 09:32
The bitrate must be: -b:a 128k

Oops. Fixed. I wrote it correctly in the text and I pasted it incorrectly in the code section. xD
I had coffee, but for me it's still early in the morning...
I'm more of a night owl than an early bird...

Starduster
12th October 2020, 12:48
Well, Yea!... and Oh crap!.. That did work perfectly but I had to dig around a while to find a version of ffmpeg that contained the libfdk_acc component. I'll have to take a look a what that means since it's "non-free"... (not even sure what that means!) Anyway, thanks for finding the Solution to this!