[FFmpeg-devel] Honors -rc_override with libx264
Etienne Buira
etienne.buira.lists at free.fr
Wed May 18 19:02:24 CEST 2011
Hi.
$subject. It might surely be done with -x264opts, but I think a big deal
of ffmpeg is unifying arguments whatever codec is in use.
It has the drawback of not allowing quality factor (is that the same as
crf?), nor q=0 (which should be made possible), nor exploiting setting
local bitrate.
So, would a patch accepting backward compatible -rc_override option as
well as one like <int>,<int>,(q|b|f)=<int> (comments welcome) be welcomed?
Regards.
-------------- next part --------------
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 519dc51..aa9e4ef 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -20,6 +20,7 @@
*/
#include "libavutil/opt.h"
+#include "libavutil/avstring.h"
#include "avcodec.h"
#include <x264.h>
#include <math.h>
@@ -170,6 +171,7 @@ static av_cold int X264_close(AVCodecContext *avctx)
av_free(x4->level);
av_free(x4->stats);
av_free(x4->weightp);
+ av_free(x4->params.rc.psz_zones);
return 0;
}
@@ -387,6 +389,35 @@ static av_cold int X264_init(AVCodecContext *avctx)
if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
x4->params.b_repeat_headers = 0;
+
+ if (avctx->rc_override_count) {
+ int i;
+ size_t curlen=1, talen;
+ char strbuf[36], *zones=NULL;
+
+ zones = av_malloc(1);
+ if (!zones)
+ return -1;
+ zones[0] = '\0';
+ for (i=0; i<avctx->rc_override_count; i++) {
+ if (avctx->rc_override[i].qscale == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Quality factor and q=0 rc_override not supported for libx264\n");
+ return -1;
+ }
+
+ talen = snprintf(strbuf, 36, "%s%u,%u,q=%u",
+ curlen==1 ? "" : "/",
+ avctx->rc_override[i].start_frame,
+ avctx->rc_override[i].end_frame,
+ avctx->rc_override[i].qscale);
+ curlen += talen;
+ zones = av_realloc(zones, curlen);
+ if (!zones)
+ return -1;
+ av_strlcat(zones, strbuf, curlen);
+ }
+ x4->params.rc.psz_zones = zones;
+ }
// update AVCodecContext with x264 parameters
avctx->has_b_frames = x4->params.i_bframe ?
More information about the ffmpeg-devel
mailing list