[FFmpeg-devel] [PATCH] In libx264 wrapper, correctly support 2pass log filename option.
Baptiste Coudurier
baptiste.coudurier at gmail.com
Wed Apr 20 01:36:55 CEST 2011
---
ffmpeg.c | 12 +++++++++---
libavcodec/libx264.c | 14 ++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index eadfc80..a62da6a 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -209,7 +209,7 @@ static int do_hex_dump = 0;
static int do_pkt_dump = 0;
static int do_psnr = 0;
static int do_pass = 0;
-static char *pass_logfilename_prefix = NULL;
+static const char *pass_logfilename_prefix;
static int audio_stream_copy = 0;
static int video_stream_copy = 0;
static int subtitle_stream_copy = 0;
@@ -2333,7 +2333,7 @@ static int transcode(AVFormatContext **output_files,
break;
}
/* two pass mode */
- if (ost->encoding_needed &&
+ if (ost->encoding_needed && codec->codec_id != CODEC_ID_H264 &&
(codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
char logfilename[1024];
FILE *f;
@@ -4270,6 +4270,12 @@ static void log_callback_null(void* ptr, int level, const char* fmt, va_list vl)
{
}
+static void opt_passlogfile(const char *arg)
+{
+ pass_logfilename_prefix = arg;
+ opt_default("passlogfile", arg);
+}
+
static const OptionDef options[] = {
/* main options */
#include "cmdutils_common_opts.h"
@@ -4343,7 +4349,7 @@ static const OptionDef options[] = {
{ "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
"use same quantizer as source (implies VBR)" },
{ "pass", HAS_ARG | OPT_FUNC2 | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
- { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" },
+ { "passlogfile", HAS_ARG | OPT_VIDEO, {(void*)&opt_passlogfile}, "select two pass log file name prefix", "prefix" },
{ "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
"deinterlace pictures" },
{ "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 29c535c..5f6ee44 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -39,6 +39,7 @@ typedef struct X264Context {
const char *tune;
const char *profile;
const char *level;
+ const char *stats;
int fastfirstpass;
} X264Context;
@@ -173,6 +174,15 @@ static av_cold int X264_close(AVCodecContext *avctx)
} \
} while (0); \
+#define OPT_STR(opt, param) \
+ do { \
+ if (param && x264_param_parse(&x4->params, opt, param) < 0) { \
+ av_log(avctx, AV_LOG_ERROR, \
+ "bad value for '%s': '%s'\n", opt, param); \
+ return -1; \
+ } \
+ } while (0); \
+
static av_cold int X264_init(AVCodecContext *avctx)
{
X264Context *x4 = avctx->priv_data;
@@ -291,6 +301,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
}
}
+ OPT_STR("stats", x4->stats);
+
// if neither crf nor cqp modes are selected we have to enable the RC
// we do it this way because we cannot check if the bitrate has been set
if (!(avctx->crf || (avctx->cqp > -1)))
@@ -303,6 +315,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
}
OPT_STR("level", x4->level);
+ OPT_STR("stats", x4->stats);
if (x4->fastfirstpass)
x264_param_apply_fastfirstpass(&x4->params);
@@ -371,6 +384,7 @@ static const AVOption options[] = {
{"fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, 1, 0, 1, VE},
{"profile", "Set profile restrictions", OFFSET(profile), FF_OPT_TYPE_STRING, 0, 0, 0, VE},
{"level", "Specify level (as defined by Annex A)", OFFSET(level), FF_OPT_TYPE_STRING, 0, 0, 0, VE},
+ {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), FF_OPT_TYPE_STRING, 0, 0, 0, VE},
{ NULL },
};
--
1.7.4.1
More information about the ffmpeg-devel
mailing list