You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to write Ogg Vorbis files with the following code:
output = av.open(str(outfile), "w")
out_stream = output.add_stream("libvorbis", rate=audio_stream.rate)
out_stream.options["global_quality"] = "9" # https://ffmpeg.org/ffmpeg-codecs.html#Options-21
for packet in container.demux(audio_stream):
for frame in packet.decode():
pkt = out_stream.encode(frame)
if pkt:
output.mux(pkt)
for pkt in out_stream.encode():
output.mux(pkt)
output.close()
Everything works, but I get an ogg vorbis file with bitrate ~112 kbps, definitely not q9. I also tried to add out_stream.qscale = True, but then the bitrate of the output file is ~ 65 kbps.
Is it a bug or I am doing something wrong? How do I set quality for libvorbis encoder?
// Set global_quality on the codec context
// Values are on a 0–10 scale, multiplied by FF_QP2LAMBDA
codec_ctx->global_quality = 4 * FF_QP2LAMBDA;
codec_ctx->flags |= AV_CODEC_FLAG_QSCALE;
We probably should expose global_quality in CodecContext
I had to add options={"strict": "-2"} because bundled ffmpeg dropped "libvorbis" and introduced experimental "vorbis" codec. Somehow, this code produced a Vorbis file with bitrate ~ 280 kbps, while expected bitrate was ~ 160-180 for quality 6.
Is this a problem with new ffmpeg or I am doing something wrong?
Activity
WyattBlue commentedon Apr 26, 2026
In C FFmpeg, you need to do:
We probably should expose
global_qualityin CodecContextWyattBlue commentedon Apr 26, 2026
#2246 should fix this
shadowlmd commentedon Apr 26, 2026
That was fast. Thank you!
shadowlmd commentedon Jul 3, 2026
@WyattBlue, I tried to use global_quality with PyAV 18.0.0 like this:
I had to add options={"strict": "-2"} because bundled ffmpeg dropped "libvorbis" and introduced experimental "vorbis" codec. Somehow, this code produced a Vorbis file with bitrate ~ 280 kbps, while expected bitrate was ~ 160-180 for quality 6.
Is this a problem with new ffmpeg or I am doing something wrong?