2002-04-10 23:23:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-11-20 13:16:09 +00:00
|
|
|
#include <math.h>
|
2002-12-04 21:46:53 +00:00
|
|
|
#include <time.h>
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2002-12-05 09:13:29 +00:00
|
|
|
#if !defined(INFINITY) && defined(HUGE_VAL)
|
|
|
|
#define INFINITY HUGE_VAL
|
|
|
|
#endif
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
|
|
|
#ifdef USE_LIBAVCODEC
|
|
|
|
|
|
|
|
#include "../mp_msg.h"
|
|
|
|
#include "../help_mp.h"
|
|
|
|
|
|
|
|
#include "codec-cfg.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
|
2002-12-27 22:43:20 +00:00
|
|
|
#include "muxer.h"
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2002-04-13 19:14:34 +00:00
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
2002-04-10 23:23:36 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2002-08-25 23:19:38 +00:00
|
|
|
extern char* passtmpfile;
|
2002-04-10 23:23:36 +00:00
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
#ifdef USE_LIBAVCODEC_SO
|
2002-08-14 21:43:49 +00:00
|
|
|
#include <ffmpeg/avcodec.h>
|
2002-04-10 23:23:36 +00:00
|
|
|
#else
|
|
|
|
#include "libavcodec/avcodec.h"
|
|
|
|
#endif
|
|
|
|
|
2002-12-04 10:49:03 +00:00
|
|
|
#if LIBAVCODEC_BUILD < 4641
|
2003-10-04 17:29:08 +00:00
|
|
|
#error we do not support libavcodec prior to build 4641, get the latest libavcodec CVS
|
2002-04-21 21:38:53 +00:00
|
|
|
#endif
|
|
|
|
|
2003-02-27 23:10:06 +00:00
|
|
|
#if LIBAVCODEC_BUILD < 4659
|
2002-08-25 21:43:22 +00:00
|
|
|
#warning your version of libavcodec is old, u might want to get a newer one
|
|
|
|
#endif
|
|
|
|
|
2002-12-09 12:36:04 +00:00
|
|
|
#if LIBAVCODEC_BUILD < 4645
|
|
|
|
#define AVFrame AVVideoFrame
|
|
|
|
#define coded_frame coded_picture
|
|
|
|
#endif
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
extern int avcodec_inited;
|
|
|
|
|
|
|
|
/* video options */
|
2002-09-29 17:53:14 +00:00
|
|
|
static char *lavc_param_vcodec = "mpeg4";
|
2002-04-10 23:23:36 +00:00
|
|
|
static int lavc_param_vbitrate = -1;
|
2002-08-25 21:43:22 +00:00
|
|
|
static int lavc_param_vrate_tolerance = 1000*8;
|
2003-07-29 02:29:58 +00:00
|
|
|
static int lavc_param_mb_decision = 0; /* default is realtime encoding */
|
2002-04-10 23:23:36 +00:00
|
|
|
static int lavc_param_v4mv = 0;
|
2002-04-11 02:54:42 +00:00
|
|
|
static int lavc_param_vme = 4;
|
2003-10-07 11:45:09 +00:00
|
|
|
static float lavc_param_vqscale = 0.0;
|
2002-08-25 21:43:22 +00:00
|
|
|
static int lavc_param_vqmin = 2;
|
|
|
|
static int lavc_param_vqmax = 31;
|
2002-12-18 10:51:10 +00:00
|
|
|
static int lavc_param_mb_qmin = 2;
|
|
|
|
static int lavc_param_mb_qmax = 31;
|
2003-10-07 11:45:09 +00:00
|
|
|
static float lavc_param_lmin = 2;
|
|
|
|
static float lavc_param_lmax = 31;
|
2002-04-10 23:23:36 +00:00
|
|
|
static int lavc_param_vqdiff = 3;
|
|
|
|
static float lavc_param_vqcompress = 0.5;
|
|
|
|
static float lavc_param_vqblur = 0.5;
|
2002-08-25 21:43:22 +00:00
|
|
|
static float lavc_param_vb_qfactor = 1.25;
|
|
|
|
static float lavc_param_vb_qoffset = 1.25;
|
|
|
|
static float lavc_param_vi_qfactor = 0.8;
|
|
|
|
static float lavc_param_vi_qoffset = 0.0;
|
2002-04-17 13:30:05 +00:00
|
|
|
static int lavc_param_vmax_b_frames = 0;
|
2002-04-10 23:23:36 +00:00
|
|
|
static int lavc_param_keyint = -1;
|
2002-04-21 21:38:53 +00:00
|
|
|
static int lavc_param_vpass = 0;
|
|
|
|
static int lavc_param_vrc_strategy = 2;
|
|
|
|
static int lavc_param_vb_strategy = 0;
|
2002-06-01 02:11:24 +00:00
|
|
|
static int lavc_param_luma_elim_threshold = 0;
|
|
|
|
static int lavc_param_chroma_elim_threshold = 0;
|
2002-05-29 21:34:29 +00:00
|
|
|
static int lavc_param_packet_size= 0;
|
|
|
|
static int lavc_param_strict= 0;
|
|
|
|
static int lavc_param_data_partitioning= 0;
|
2002-06-18 01:39:26 +00:00
|
|
|
static int lavc_param_gray=0;
|
2002-08-25 21:43:22 +00:00
|
|
|
static float lavc_param_rc_qsquish=1.0;
|
|
|
|
static float lavc_param_rc_qmod_amp=0;
|
|
|
|
static int lavc_param_rc_qmod_freq=0;
|
|
|
|
static char *lavc_param_rc_override_string=NULL;
|
|
|
|
static char *lavc_param_rc_eq="tex^qComp";
|
|
|
|
static int lavc_param_rc_buffer_size=0;
|
|
|
|
static float lavc_param_rc_buffer_aggressivity=1.0;
|
|
|
|
static int lavc_param_rc_max_rate=0;
|
|
|
|
static int lavc_param_rc_min_rate=0;
|
|
|
|
static float lavc_param_rc_initial_cplx=0;
|
2002-08-07 00:08:57 +00:00
|
|
|
static int lavc_param_mpeg_quant=0;
|
2002-08-30 00:38:42 +00:00
|
|
|
static int lavc_param_fdct=0;
|
2002-09-29 23:21:57 +00:00
|
|
|
static int lavc_param_idct=0;
|
2002-11-20 13:16:09 +00:00
|
|
|
static char* lavc_param_aspect = NULL;
|
2003-04-26 16:47:25 +00:00
|
|
|
static int lavc_param_autoaspect = 0;
|
2002-09-23 15:46:16 +00:00
|
|
|
static float lavc_param_lumi_masking= 0.0;
|
2002-09-24 11:23:23 +00:00
|
|
|
static float lavc_param_dark_masking= 0.0;
|
2002-09-23 15:46:16 +00:00
|
|
|
static float lavc_param_temporal_cplx_masking= 0.0;
|
|
|
|
static float lavc_param_spatial_cplx_masking= 0.0;
|
|
|
|
static float lavc_param_p_masking= 0.0;
|
|
|
|
static int lavc_param_normalize_aqp= 0;
|
2002-09-26 00:48:25 +00:00
|
|
|
static int lavc_param_interlaced_dct= 0;
|
2002-11-14 19:27:51 +00:00
|
|
|
static int lavc_param_prediction_method= FF_PRED_LEFT;
|
2003-09-01 13:26:05 +00:00
|
|
|
static int lavc_param_format= IMGFMT_YV12;
|
2002-12-04 12:41:57 +00:00
|
|
|
static int lavc_param_debug= 0;
|
2002-12-04 21:46:53 +00:00
|
|
|
static int lavc_param_psnr= 0;
|
2003-01-05 16:06:18 +00:00
|
|
|
static int lavc_param_me_pre_cmp= 0;
|
2002-12-28 00:04:20 +00:00
|
|
|
static int lavc_param_me_cmp= 0;
|
|
|
|
static int lavc_param_me_sub_cmp= 0;
|
|
|
|
static int lavc_param_mb_cmp= 0;
|
2004-01-05 23:44:51 +00:00
|
|
|
#ifdef FF_CMP_VSAD
|
|
|
|
static int lavc_param_ildct_cmp= FF_CMP_VSAD;
|
|
|
|
#endif
|
2003-01-05 16:06:18 +00:00
|
|
|
static int lavc_param_pre_dia_size= 0;
|
2002-12-28 00:04:20 +00:00
|
|
|
static int lavc_param_dia_size= 0;
|
|
|
|
static int lavc_param_qpel= 0;
|
2002-12-31 17:29:53 +00:00
|
|
|
static int lavc_param_trell= 0;
|
2004-02-07 00:19:42 +00:00
|
|
|
static int lavc_param_bit_exact = 0;
|
2003-03-05 16:40:14 +00:00
|
|
|
static int lavc_param_aic= 0;
|
2003-12-22 17:42:54 +00:00
|
|
|
static int lavc_param_aiv= 0;
|
2003-03-05 16:40:14 +00:00
|
|
|
static int lavc_param_umv= 0;
|
2003-12-22 17:42:54 +00:00
|
|
|
static int lavc_param_obmc= 0;
|
|
|
|
static int lavc_param_loop= 0;
|
2003-01-01 14:39:09 +00:00
|
|
|
static int lavc_param_last_pred= 0;
|
2003-01-02 01:33:14 +00:00
|
|
|
static int lavc_param_pre_me= 1;
|
2003-01-05 16:06:18 +00:00
|
|
|
static int lavc_param_me_subpel_quality= 8;
|
2003-02-27 23:10:06 +00:00
|
|
|
static int lavc_param_me_range= 0;
|
2003-03-22 12:46:44 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4663
|
|
|
|
static int lavc_param_ibias= FF_DEFAULT_QUANT_BIAS;
|
|
|
|
static int lavc_param_pbias= FF_DEFAULT_QUANT_BIAS;
|
|
|
|
#endif
|
2003-06-13 21:35:02 +00:00
|
|
|
static int lavc_param_coder= 0;
|
|
|
|
static int lavc_param_context= 0;
|
2003-09-01 14:04:41 +00:00
|
|
|
static char *lavc_param_intra_matrix = NULL;
|
|
|
|
static char *lavc_param_inter_matrix = NULL;
|
2003-09-30 22:32:13 +00:00
|
|
|
static int lavc_param_cbp= 0;
|
2003-10-02 00:28:29 +00:00
|
|
|
static int lavc_param_mv0= 0;
|
2003-11-02 23:21:45 +00:00
|
|
|
static int lavc_param_noise_reduction= 0;
|
2004-02-02 14:19:55 +00:00
|
|
|
static int lavc_param_qns= 0;
|
2003-11-12 12:30:52 +00:00
|
|
|
static int lavc_param_qp_rd= 0;
|
2003-12-22 17:42:54 +00:00
|
|
|
static int lavc_param_inter_threshold= 0;
|
2003-12-28 19:36:10 +00:00
|
|
|
static int lavc_param_sc_threshold= 0;
|
2003-12-22 17:42:54 +00:00
|
|
|
static int lavc_param_ss= 0;
|
|
|
|
static int lavc_param_top= -1;
|
2003-12-30 18:24:19 +00:00
|
|
|
static int lavc_param_alt= 0;
|
|
|
|
static int lavc_param_ilme= 0;
|
2004-06-07 17:31:50 +00:00
|
|
|
static int lavc_param_nssew= 8;
|
2004-07-06 11:15:06 +00:00
|
|
|
static int lavc_param_closed_gop = 0;
|
|
|
|
static int lavc_param_dc_precision = 8;
|
2004-07-06 02:10:22 +00:00
|
|
|
static int lavc_param_threads= 1;
|
2004-09-19 09:59:05 +00:00
|
|
|
static int lavc_param_turbo = 0;
|
2003-12-22 17:42:54 +00:00
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2003-11-03 16:35:40 +00:00
|
|
|
char *lavc_param_acodec = "mp2";
|
|
|
|
int lavc_param_atag = 0;
|
|
|
|
int lavc_param_abitrate = 224;
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
#include "m_option.h"
|
2002-04-10 23:23:36 +00:00
|
|
|
|
|
|
|
#ifdef USE_LIBAVCODEC
|
2003-08-13 16:29:32 +00:00
|
|
|
m_option_t lavcopts_conf[]={
|
2003-11-03 16:35:40 +00:00
|
|
|
{"acodec", &lavc_param_acodec, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
|
|
{"abitrate", &lavc_param_abitrate, CONF_TYPE_INT, CONF_RANGE, 1, 1000, NULL},
|
|
|
|
{"atag", &lavc_param_atag, CONF_TYPE_INT, CONF_RANGE, 0, 0xffff, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
|
|
{"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
|
|
|
|
{"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
|
2003-07-29 02:29:58 +00:00
|
|
|
{"vhq", &lavc_param_mb_decision, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
|
|
|
{"mbd", &lavc_param_mb_decision, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{"v4mv", &lavc_param_v4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
|
|
|
{"vme", &lavc_param_vme, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL},
|
2003-10-07 11:45:09 +00:00
|
|
|
{"vqscale", &lavc_param_vqscale, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{"vqmin", &lavc_param_vqmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
|
|
|
{"vqmax", &lavc_param_vqmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
2002-12-18 10:51:10 +00:00
|
|
|
{"mbqmin", &lavc_param_mb_qmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
|
|
|
{"mbqmax", &lavc_param_mb_qmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
2003-10-07 11:45:09 +00:00
|
|
|
{"lmin", &lavc_param_lmin, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
|
|
|
|
{"lmax", &lavc_param_lmax, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{"vqdiff", &lavc_param_vqdiff, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
|
|
|
{"vqcomp", &lavc_param_vqcompress, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
|
|
|
|
{"vqblur", &lavc_param_vqblur, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
|
2002-08-25 21:43:22 +00:00
|
|
|
{"vb_qfactor", &lavc_param_vb_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL},
|
2002-04-17 13:30:05 +00:00
|
|
|
{"vmax_b_frames", &lavc_param_vmax_b_frames, CONF_TYPE_INT, CONF_RANGE, 0, FF_MAX_B_FRAMES, NULL},
|
2004-09-18 23:20:09 +00:00
|
|
|
{"vpass", &lavc_param_vpass, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
|
2002-04-21 21:38:53 +00:00
|
|
|
{"vrc_strategy", &lavc_param_vrc_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
|
2002-12-09 12:36:04 +00:00
|
|
|
{"vb_strategy", &lavc_param_vb_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
|
2002-05-29 21:34:29 +00:00
|
|
|
{"vb_qoffset", &lavc_param_vb_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL},
|
2002-08-18 01:07:37 +00:00
|
|
|
{"vlelim", &lavc_param_luma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
|
2002-08-17 20:48:23 +00:00
|
|
|
{"vcelim", &lavc_param_chroma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
|
2002-05-29 21:34:29 +00:00
|
|
|
{"vpsize", &lavc_param_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
|
2002-11-14 22:36:16 +00:00
|
|
|
{"vstrict", &lavc_param_strict, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
|
2002-05-29 21:34:29 +00:00
|
|
|
{"vdpart", &lavc_param_data_partitioning, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{"keyint", &lavc_param_keyint, CONF_TYPE_INT, 0, 0, 0, NULL},
|
2002-06-18 01:39:26 +00:00
|
|
|
{"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
|
2002-08-07 00:08:57 +00:00
|
|
|
{"mpeg_quant", &lavc_param_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2002-08-25 21:43:22 +00:00
|
|
|
{"vi_qfactor", &lavc_param_vi_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL},
|
|
|
|
{"vi_qoffset", &lavc_param_vi_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL},
|
|
|
|
{"vqsquish", &lavc_param_rc_qsquish, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
|
|
|
|
{"vqmod_amp", &lavc_param_rc_qmod_amp, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
|
|
|
|
{"vqmod_freq", &lavc_param_rc_qmod_freq, CONF_TYPE_INT, 0, 0, 0, NULL},
|
|
|
|
{"vrc_eq", &lavc_param_rc_eq, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
|
|
{"vrc_override", &lavc_param_rc_override_string, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
|
|
{"vrc_maxrate", &lavc_param_rc_max_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
|
|
|
|
{"vrc_minrate", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
|
2003-10-23 12:05:33 +00:00
|
|
|
{"vrc_buf_size", &lavc_param_rc_buffer_size, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
|
2002-08-25 21:43:22 +00:00
|
|
|
{"vrc_buf_aggressivity", &lavc_param_rc_buffer_aggressivity, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
|
|
|
|
{"vrc_init_cplx", &lavc_param_rc_initial_cplx, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 9999999.0, NULL},
|
2002-08-30 00:38:42 +00:00
|
|
|
{"vfdct", &lavc_param_fdct, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
|
2002-11-20 13:16:09 +00:00
|
|
|
{"aspect", &lavc_param_aspect, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
2003-04-26 16:47:25 +00:00
|
|
|
{"autoaspect", &lavc_param_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2002-09-23 15:46:16 +00:00
|
|
|
{"lumi_mask", &lavc_param_lumi_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
|
|
|
|
{"tcplx_mask", &lavc_param_temporal_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
|
|
|
|
{"scplx_mask", &lavc_param_spatial_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
|
|
|
|
{"p_mask", &lavc_param_p_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
|
|
|
|
{"naq", &lavc_param_normalize_aqp, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2002-09-24 11:23:23 +00:00
|
|
|
{"dark_mask", &lavc_param_dark_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
|
2002-09-26 00:48:25 +00:00
|
|
|
{"ildct", &lavc_param_interlaced_dct, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2002-09-29 23:21:57 +00:00
|
|
|
{"idct", &lavc_param_idct, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
|
2002-11-14 19:27:51 +00:00
|
|
|
{"pred", &lavc_param_prediction_method, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
|
2003-09-01 13:26:05 +00:00
|
|
|
{"format", &lavc_param_format, CONF_TYPE_IMGFMT, 0, 0, 0, NULL},
|
2002-12-04 12:41:57 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4642
|
|
|
|
{"debug", &lavc_param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
|
2002-12-04 21:46:53 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4643
|
|
|
|
{"psnr", &lavc_param_psnr, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PSNR, NULL},
|
2002-12-04 12:41:57 +00:00
|
|
|
#endif
|
2003-01-05 16:06:18 +00:00
|
|
|
{"precmp", &lavc_param_me_pre_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
2002-12-28 00:04:20 +00:00
|
|
|
{"cmp", &lavc_param_me_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
|
|
|
{"subcmp", &lavc_param_me_sub_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
|
|
|
{"mbcmp", &lavc_param_mb_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
2004-01-05 23:44:51 +00:00
|
|
|
#ifdef FF_CMP_VSAD
|
|
|
|
{"ildctcmp", &lavc_param_ildct_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
|
|
|
#endif
|
2004-02-07 00:19:42 +00:00
|
|
|
{"bit_exact", &lavc_param_bit_exact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL},
|
2003-01-05 16:06:18 +00:00
|
|
|
{"predia", &lavc_param_pre_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL},
|
2002-12-31 17:29:53 +00:00
|
|
|
{"dia", &lavc_param_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL},
|
2002-12-28 00:04:20 +00:00
|
|
|
{"qpel", &lavc_param_qpel, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QPEL, NULL},
|
2002-12-31 17:29:53 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4648
|
|
|
|
{"trell", &lavc_param_trell, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_TRELLIS_QUANT, NULL},
|
|
|
|
#endif
|
2003-01-01 14:39:09 +00:00
|
|
|
{"last_pred", &lavc_param_last_pred, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
2003-01-02 01:33:14 +00:00
|
|
|
{"preme", &lavc_param_pre_me, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
|
2003-01-05 16:06:18 +00:00
|
|
|
{"subq", &lavc_param_me_subpel_quality, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL},
|
2003-02-27 23:10:06 +00:00
|
|
|
{"me_range", &lavc_param_me_range, CONF_TYPE_INT, CONF_RANGE, 0, 16000, NULL},
|
2003-03-05 16:40:14 +00:00
|
|
|
#ifdef CODEC_FLAG_H263P_AIC
|
|
|
|
{"aic", &lavc_param_aic, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_AIC, NULL},
|
|
|
|
{"umv", &lavc_param_umv, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_UMV, NULL},
|
2003-03-22 12:46:44 +00:00
|
|
|
#endif
|
2003-12-22 17:42:54 +00:00
|
|
|
#ifdef CODEC_FLAG_H263P_AIV
|
|
|
|
{"aiv", &lavc_param_aiv, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_AIV, NULL},
|
|
|
|
#endif
|
|
|
|
#ifdef CODEC_FLAG_OBMC
|
|
|
|
{"obmc", &lavc_param_obmc, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_OBMC, NULL},
|
|
|
|
#endif
|
|
|
|
#ifdef CODEC_FLAG_LOOP_FILTER
|
|
|
|
{"loop", &lavc_param_loop, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_LOOP_FILTER, NULL},
|
|
|
|
#endif
|
2003-03-22 12:46:44 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4663
|
|
|
|
{"ibias", &lavc_param_ibias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL},
|
|
|
|
{"pbias", &lavc_param_pbias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL},
|
2003-06-13 21:35:02 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4669
|
|
|
|
{"coder", &lavc_param_coder, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
|
|
|
|
{"context", &lavc_param_context, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
|
2003-09-01 14:04:41 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4675
|
|
|
|
{"intra_matrix", &lavc_param_intra_matrix, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
|
|
{"inter_matrix", &lavc_param_inter_matrix, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
2003-09-30 22:32:13 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4681
|
|
|
|
{"cbp", &lavc_param_cbp, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CBP_RD, NULL},
|
2003-10-02 00:28:29 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4683
|
|
|
|
{"mv0", &lavc_param_mv0, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_MV0, NULL},
|
2003-03-05 16:40:14 +00:00
|
|
|
#endif
|
2003-11-02 23:21:45 +00:00
|
|
|
{"nr", &lavc_param_noise_reduction, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
|
2003-11-12 12:30:52 +00:00
|
|
|
#ifdef CODEC_FLAG_QP_RD
|
|
|
|
{"qprd", &lavc_param_qp_rd, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QP_RD, NULL},
|
|
|
|
#endif
|
2003-12-22 17:42:54 +00:00
|
|
|
#ifdef CODEC_FLAG_H263P_SLICE_STRUCT
|
|
|
|
{"ss", &lavc_param_ss, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_SLICE_STRUCT, NULL},
|
2003-12-30 18:24:19 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CODEC_FLAG_ALT_SCAN
|
|
|
|
{"alt", &lavc_param_alt, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_ALT_SCAN, NULL},
|
|
|
|
#endif
|
|
|
|
#ifdef CODEC_FLAG_INTERLACED_ME
|
|
|
|
{"ilme", &lavc_param_ilme, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_INTERLACED_ME, NULL},
|
2004-07-06 11:15:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CODEC_FLAG_CLOSED_GOP
|
|
|
|
{"cgop", &lavc_param_closed_gop, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CLOSED_GOP, NULL},
|
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4711
|
2004-07-06 12:29:32 +00:00
|
|
|
{"dc", &lavc_param_dc_precision, CONF_TYPE_INT, CONF_RANGE, 8, 11, NULL},
|
2003-12-22 17:42:54 +00:00
|
|
|
#endif
|
|
|
|
{"inter_threshold", &lavc_param_inter_threshold, CONF_TYPE_INT, CONF_RANGE, -1000000, 1000000, NULL},
|
2003-12-28 19:36:10 +00:00
|
|
|
{"sc_threshold", &lavc_param_sc_threshold, CONF_TYPE_INT, CONF_RANGE, -1000000, 1000000, NULL},
|
2003-12-22 17:42:54 +00:00
|
|
|
{"top", &lavc_param_top, CONF_TYPE_INT, CONF_RANGE, -1, 1, NULL},
|
2004-02-02 14:19:55 +00:00
|
|
|
{"qns", &lavc_param_qns, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
|
2004-06-07 17:31:50 +00:00
|
|
|
{"nssew", &lavc_param_nssew, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
|
2004-07-06 02:10:22 +00:00
|
|
|
{"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL},
|
2004-09-19 09:59:05 +00:00
|
|
|
{"turbo", &lavc_param_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
2002-04-10 23:23:36 +00:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
2002-12-27 22:43:20 +00:00
|
|
|
muxer_stream_t* mux;
|
2002-09-19 09:47:37 +00:00
|
|
|
AVCodecContext *context;
|
2002-12-09 12:36:04 +00:00
|
|
|
AVFrame *pic;
|
2002-04-10 23:23:36 +00:00
|
|
|
AVCodec *codec;
|
2002-08-25 21:43:22 +00:00
|
|
|
FILE *stats_file;
|
2002-04-10 23:23:36 +00:00
|
|
|
};
|
|
|
|
|
2002-08-25 21:43:22 +00:00
|
|
|
#define stats_file (vf->priv->stats_file)
|
2002-04-10 23:23:36 +00:00
|
|
|
#define mux_v (vf->priv->mux)
|
|
|
|
#define lavc_venc_context (vf->priv->context)
|
|
|
|
|
2003-10-07 11:45:09 +00:00
|
|
|
#if LIBAVCODEC_BUILD < 4684
|
|
|
|
#define FF_QP2LAMBDA 1
|
|
|
|
#endif
|
|
|
|
|
2004-12-01 20:32:05 +00:00
|
|
|
static int encode_frame(struct vf_instance_s* vf, AVFrame *pic);
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
static int config(struct vf_instance_s* vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2002-08-25 21:43:22 +00:00
|
|
|
int size, i;
|
|
|
|
void *p;
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
mux_v->bih->biWidth=width;
|
|
|
|
mux_v->bih->biHeight=height;
|
|
|
|
mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
|
|
|
|
|
|
|
|
printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n",
|
|
|
|
mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression,
|
|
|
|
(char *)&mux_v->bih->biCompression);
|
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->width = width;
|
|
|
|
lavc_venc_context->height = height;
|
2002-04-18 15:23:34 +00:00
|
|
|
if (lavc_param_vbitrate > 16000) /* != -1 */
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->bit_rate = lavc_param_vbitrate;
|
2002-04-18 15:23:34 +00:00
|
|
|
else if (lavc_param_vbitrate >= 0) /* != -1 */
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->bit_rate = lavc_param_vbitrate*1000;
|
2002-04-10 23:23:36 +00:00
|
|
|
else
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->bit_rate = 800000; /* default */
|
|
|
|
lavc_venc_context->bit_rate_tolerance= lavc_param_vrate_tolerance*1000;
|
2003-03-12 15:44:24 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4662
|
|
|
|
lavc_venc_context->frame_rate = mux_v->h.dwRate;
|
|
|
|
lavc_venc_context->frame_rate_base = mux_v->h.dwScale;
|
|
|
|
#else
|
|
|
|
lavc_venc_context->frame_rate = mux_v->h.dwRate*FRAME_RATE_BASE/mux_v->h.dwScale;
|
|
|
|
#endif
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->qmin= lavc_param_vqmin;
|
|
|
|
lavc_venc_context->qmax= lavc_param_vqmax;
|
2002-12-18 10:51:10 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4646
|
|
|
|
lavc_venc_context->mb_qmin= lavc_param_mb_qmin;
|
|
|
|
lavc_venc_context->mb_qmax= lavc_param_mb_qmax;
|
2003-10-07 11:45:09 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4684
|
|
|
|
lavc_venc_context->lmin= (int)(FF_QP2LAMBDA * lavc_param_lmin + 0.5);
|
|
|
|
lavc_venc_context->lmax= (int)(FF_QP2LAMBDA * lavc_param_lmax + 0.5);
|
2002-12-18 10:51:10 +00:00
|
|
|
#endif
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->max_qdiff= lavc_param_vqdiff;
|
|
|
|
lavc_venc_context->qcompress= lavc_param_vqcompress;
|
|
|
|
lavc_venc_context->qblur= lavc_param_vqblur;
|
|
|
|
lavc_venc_context->max_b_frames= lavc_param_vmax_b_frames;
|
|
|
|
lavc_venc_context->b_quant_factor= lavc_param_vb_qfactor;
|
|
|
|
lavc_venc_context->rc_strategy= lavc_param_vrc_strategy;
|
|
|
|
lavc_venc_context->b_frame_strategy= lavc_param_vb_strategy;
|
2005-02-24 02:31:41 +00:00
|
|
|
lavc_venc_context->b_quant_offset= (int)(FF_QP2LAMBDA * lavc_param_vb_qoffset + 0.5);
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->luma_elim_threshold= lavc_param_luma_elim_threshold;
|
|
|
|
lavc_venc_context->chroma_elim_threshold= lavc_param_chroma_elim_threshold;
|
|
|
|
lavc_venc_context->rtp_payload_size= lavc_param_packet_size;
|
|
|
|
if(lavc_param_packet_size )lavc_venc_context->rtp_mode=1;
|
|
|
|
lavc_venc_context->strict_std_compliance= lavc_param_strict;
|
|
|
|
lavc_venc_context->i_quant_factor= lavc_param_vi_qfactor;
|
2005-02-24 02:31:41 +00:00
|
|
|
lavc_venc_context->i_quant_offset= (int)(FF_QP2LAMBDA * lavc_param_vi_qoffset + 0.5);
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->rc_qsquish= lavc_param_rc_qsquish;
|
|
|
|
lavc_venc_context->rc_qmod_amp= lavc_param_rc_qmod_amp;
|
|
|
|
lavc_venc_context->rc_qmod_freq= lavc_param_rc_qmod_freq;
|
|
|
|
lavc_venc_context->rc_eq= lavc_param_rc_eq;
|
|
|
|
lavc_venc_context->rc_max_rate= lavc_param_rc_max_rate*1000;
|
|
|
|
lavc_venc_context->rc_min_rate= lavc_param_rc_min_rate*1000;
|
|
|
|
lavc_venc_context->rc_buffer_size= lavc_param_rc_buffer_size*1000;
|
|
|
|
lavc_venc_context->rc_buffer_aggressivity= lavc_param_rc_buffer_aggressivity;
|
|
|
|
lavc_venc_context->rc_initial_cplx= lavc_param_rc_initial_cplx;
|
2002-12-04 12:41:57 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4642
|
|
|
|
lavc_venc_context->debug= lavc_param_debug;
|
|
|
|
#endif
|
2003-01-01 14:39:09 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4649
|
|
|
|
lavc_venc_context->last_predictor_count= lavc_param_last_pred;
|
|
|
|
#endif
|
2003-01-02 01:33:14 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4650
|
|
|
|
lavc_venc_context->pre_me= lavc_param_pre_me;
|
|
|
|
#endif
|
2003-01-05 16:06:18 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4651
|
|
|
|
lavc_venc_context->me_pre_cmp= lavc_param_me_pre_cmp;
|
|
|
|
lavc_venc_context->pre_dia_size= lavc_param_pre_dia_size;
|
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4652
|
|
|
|
lavc_venc_context->me_subpel_quality= lavc_param_me_subpel_quality;
|
|
|
|
#endif
|
2003-02-27 23:10:06 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4659
|
|
|
|
lavc_venc_context->me_range= lavc_param_me_range;
|
|
|
|
#endif
|
2003-03-22 12:46:44 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4663
|
|
|
|
lavc_venc_context->intra_quant_bias= lavc_param_ibias;
|
|
|
|
lavc_venc_context->inter_quant_bias= lavc_param_pbias;
|
|
|
|
#endif
|
2003-06-13 21:35:02 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4669
|
|
|
|
lavc_venc_context->coder_type= lavc_param_coder;
|
|
|
|
lavc_venc_context->context_model= lavc_param_context;
|
|
|
|
#endif
|
2003-12-28 19:36:10 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4680
|
|
|
|
lavc_venc_context->scenechange_threshold= lavc_param_sc_threshold;
|
|
|
|
#endif
|
2003-11-02 23:21:45 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4690
|
|
|
|
lavc_venc_context->noise_reduction= lavc_param_noise_reduction;
|
|
|
|
#endif
|
2004-02-02 14:19:55 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4700
|
|
|
|
lavc_venc_context->quantizer_noise_shaping= lavc_param_qns;
|
|
|
|
#endif
|
2003-12-22 17:42:54 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4693
|
|
|
|
lavc_venc_context->inter_threshold= lavc_param_inter_threshold;
|
|
|
|
#endif
|
2004-06-07 17:31:50 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4716
|
|
|
|
lavc_venc_context->nsse_weight= lavc_param_nssew;
|
|
|
|
#endif
|
2003-09-01 14:04:41 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4675
|
|
|
|
if (lavc_param_intra_matrix)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
lavc_venc_context->intra_matrix =
|
2005-01-08 19:16:21 +00:00
|
|
|
av_malloc(sizeof(*lavc_venc_context->intra_matrix)*64);
|
2003-09-01 14:04:41 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((tmp = strsep(&lavc_param_intra_matrix, ",")) && (i < 64))
|
|
|
|
{
|
|
|
|
if (!tmp || (tmp && !strlen(tmp)))
|
|
|
|
break;
|
|
|
|
lavc_venc_context->intra_matrix[i++] = atoi(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 64)
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&lavc_venc_context->intra_matrix);
|
2003-09-01 14:04:41 +00:00
|
|
|
else
|
|
|
|
mp_msg(MSGT_MENCODER, MSGL_V, "Using user specified intra matrix\n");
|
|
|
|
}
|
|
|
|
if (lavc_param_inter_matrix)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
lavc_venc_context->inter_matrix =
|
2005-01-08 19:16:21 +00:00
|
|
|
av_malloc(sizeof(*lavc_venc_context->inter_matrix)*64);
|
2003-09-01 14:04:41 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((tmp = strsep(&lavc_param_inter_matrix, ",")) && (i < 64))
|
|
|
|
{
|
|
|
|
if (!tmp || (tmp && !strlen(tmp)))
|
|
|
|
break;
|
|
|
|
lavc_venc_context->inter_matrix[i++] = atoi(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 64)
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&lavc_venc_context->inter_matrix);
|
2003-09-01 14:04:41 +00:00
|
|
|
else
|
|
|
|
mp_msg(MSGT_MENCODER, MSGL_V, "Using user specified inter matrix\n");
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-27 23:10:06 +00:00
|
|
|
|
2002-08-25 21:43:22 +00:00
|
|
|
p= lavc_param_rc_override_string;
|
|
|
|
for(i=0; p; i++){
|
|
|
|
int start, end, q;
|
|
|
|
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
|
|
|
|
if(e!=3){
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"error parsing vrc_q\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->rc_override=
|
|
|
|
realloc(lavc_venc_context->rc_override, sizeof(RcOverride)*(i+1));
|
|
|
|
lavc_venc_context->rc_override[i].start_frame= start;
|
|
|
|
lavc_venc_context->rc_override[i].end_frame = end;
|
2002-08-25 21:43:22 +00:00
|
|
|
if(q>0){
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->rc_override[i].qscale= q;
|
|
|
|
lavc_venc_context->rc_override[i].quality_factor= 1.0;
|
2002-08-25 21:43:22 +00:00
|
|
|
}
|
|
|
|
else{
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->rc_override[i].qscale= 0;
|
|
|
|
lavc_venc_context->rc_override[i].quality_factor= -q/100.0;
|
2002-08-25 21:43:22 +00:00
|
|
|
}
|
|
|
|
p= strchr(p, '/');
|
|
|
|
if(p) p++;
|
|
|
|
}
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->rc_override_count=i;
|
2002-08-25 21:43:22 +00:00
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->mpeg_quant=lavc_param_mpeg_quant;
|
2002-08-30 00:38:42 +00:00
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->dct_algo= lavc_param_fdct;
|
2002-09-29 23:21:57 +00:00
|
|
|
lavc_venc_context->idct_algo= lavc_param_idct;
|
2002-08-30 00:38:42 +00:00
|
|
|
|
2002-09-23 15:46:16 +00:00
|
|
|
lavc_venc_context->lumi_masking= lavc_param_lumi_masking;
|
|
|
|
lavc_venc_context->temporal_cplx_masking= lavc_param_temporal_cplx_masking;
|
|
|
|
lavc_venc_context->spatial_cplx_masking= lavc_param_spatial_cplx_masking;
|
|
|
|
lavc_venc_context->p_masking= lavc_param_p_masking;
|
2002-09-24 11:23:23 +00:00
|
|
|
lavc_venc_context->dark_masking= lavc_param_dark_masking;
|
2002-09-23 15:46:16 +00:00
|
|
|
|
2002-11-20 13:16:09 +00:00
|
|
|
if (lavc_param_aspect != NULL)
|
2002-09-13 20:46:23 +00:00
|
|
|
{
|
2002-11-20 13:16:09 +00:00
|
|
|
int par_width, par_height, e;
|
|
|
|
float ratio=0;
|
|
|
|
|
|
|
|
e= sscanf (lavc_param_aspect, "%d/%d", &par_width, &par_height);
|
|
|
|
if(e==2){
|
|
|
|
if(par_height)
|
|
|
|
ratio= (float)par_width / (float)par_height;
|
|
|
|
}else{
|
|
|
|
e= sscanf (lavc_param_aspect, "%f", &ratio);
|
2002-09-13 20:46:23 +00:00
|
|
|
}
|
2002-11-20 13:16:09 +00:00
|
|
|
|
|
|
|
if (e && ratio > 0.1 && ratio < 10.0) {
|
2003-10-20 21:21:42 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4687
|
2003-10-20 21:40:58 +00:00
|
|
|
lavc_venc_context->sample_aspect_ratio= av_d2q(ratio * height / width, 255);
|
|
|
|
mp_dbg(MSGT_MENCODER, MSGL_DBG2, "sample_aspect_ratio: %d/%d\n",
|
|
|
|
lavc_venc_context->sample_aspect_ratio.num,
|
|
|
|
lavc_venc_context->sample_aspect_ratio.den);
|
2003-10-20 21:21:42 +00:00
|
|
|
#else
|
2002-11-20 13:16:09 +00:00
|
|
|
lavc_venc_context->aspect_ratio= ratio;
|
2003-10-20 21:21:42 +00:00
|
|
|
#endif
|
2004-03-24 15:16:36 +00:00
|
|
|
mux_v->aspect = ratio;
|
2002-11-20 13:16:09 +00:00
|
|
|
mp_dbg(MSGT_MENCODER, MSGL_DBG2, "aspect_ratio: %f\n", ratio);
|
|
|
|
} else {
|
|
|
|
mp_dbg(MSGT_MENCODER, MSGL_ERR, "aspect ratio: cannot parse \"%s\"\n", lavc_param_aspect);
|
|
|
|
return 0;
|
2002-09-13 20:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-18 12:26:45 +00:00
|
|
|
else if (lavc_param_autoaspect) {
|
2003-10-20 21:21:42 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4687
|
2003-11-03 02:42:39 +00:00
|
|
|
lavc_venc_context->sample_aspect_ratio = av_d2q((float)d_width/d_height*height / width, 255);
|
2003-10-20 21:21:42 +00:00
|
|
|
#else
|
2004-03-24 15:16:36 +00:00
|
|
|
lavc_venc_context->aspect_ratio =
|
2003-10-20 21:21:42 +00:00
|
|
|
#endif
|
2004-03-24 15:16:36 +00:00
|
|
|
mux_v->aspect = (float)d_width/d_height;
|
2004-10-18 12:26:45 +00:00
|
|
|
}
|
2002-09-13 20:46:23 +00:00
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
/* keyframe interval */
|
|
|
|
if (lavc_param_keyint >= 0) /* != -1 */
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->gop_size = lavc_param_keyint;
|
2002-04-10 23:23:36 +00:00
|
|
|
else
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->gop_size = 250; /* default */
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2003-07-29 02:29:58 +00:00
|
|
|
lavc_venc_context->flags = 0;
|
|
|
|
if (lavc_param_mb_decision)
|
2002-04-10 23:23:36 +00:00
|
|
|
{
|
|
|
|
printf("High quality encoding selected (non real time)!\n");
|
2003-07-29 02:29:58 +00:00
|
|
|
#if LIBAVCODEC_BUILD < 4673
|
|
|
|
lavc_venc_context->flags = CODEC_FLAG_HQ;
|
|
|
|
#else
|
|
|
|
lavc_venc_context->mb_decision= lavc_param_mb_decision;
|
|
|
|
#endif
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
2002-12-28 00:04:20 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4647
|
|
|
|
lavc_venc_context->me_cmp= lavc_param_me_cmp;
|
|
|
|
lavc_venc_context->me_sub_cmp= lavc_param_me_sub_cmp;
|
|
|
|
lavc_venc_context->mb_cmp= lavc_param_mb_cmp;
|
2004-01-05 23:44:51 +00:00
|
|
|
#ifdef FF_CMP_VSAD
|
|
|
|
lavc_venc_context->ildct_cmp= lavc_param_ildct_cmp;
|
|
|
|
#endif
|
2002-12-28 00:04:20 +00:00
|
|
|
lavc_venc_context->dia_size= lavc_param_dia_size;
|
|
|
|
lavc_venc_context->flags|= lavc_param_qpel;
|
|
|
|
#endif
|
2002-12-31 17:29:53 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4648
|
|
|
|
lavc_venc_context->flags|= lavc_param_trell;
|
|
|
|
#endif
|
2004-02-07 00:19:42 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_bit_exact;
|
2003-03-05 16:40:14 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_aic;
|
2003-12-22 17:42:54 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_aiv;
|
2003-03-05 16:40:14 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_umv;
|
2003-12-22 17:42:54 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_obmc;
|
|
|
|
lavc_venc_context->flags|= lavc_param_loop;
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0;
|
|
|
|
lavc_venc_context->flags|= lavc_param_data_partitioning;
|
2003-09-30 22:32:13 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_cbp;
|
2003-10-02 00:28:29 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_mv0;
|
2003-11-12 12:30:52 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_qp_rd;
|
2003-12-22 17:42:54 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_ss;
|
2003-12-30 18:24:19 +00:00
|
|
|
lavc_venc_context->flags|= lavc_param_alt;
|
|
|
|
lavc_venc_context->flags|= lavc_param_ilme;
|
2004-07-06 11:15:06 +00:00
|
|
|
#ifdef CODEC_FLAG_CLOSED_GOP
|
|
|
|
lavc_venc_context->flags|= lavc_param_closed_gop;
|
|
|
|
#endif
|
2002-09-19 09:47:37 +00:00
|
|
|
if(lavc_param_gray) lavc_venc_context->flags|= CODEC_FLAG_GRAY;
|
2002-06-18 01:39:26 +00:00
|
|
|
|
2002-09-23 15:46:16 +00:00
|
|
|
if(lavc_param_normalize_aqp) lavc_venc_context->flags|= CODEC_FLAG_NORMALIZE_AQP;
|
2002-09-26 00:48:25 +00:00
|
|
|
if(lavc_param_interlaced_dct) lavc_venc_context->flags|= CODEC_FLAG_INTERLACED_DCT;
|
2002-12-04 21:46:53 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4643
|
|
|
|
lavc_venc_context->flags|= lavc_param_psnr;
|
2004-07-06 11:15:06 +00:00
|
|
|
#endif
|
|
|
|
#if LIBAVCODEC_BUILD >= 4711
|
|
|
|
lavc_venc_context->intra_dc_precision = lavc_param_dc_precision - 8;
|
2002-12-04 21:46:53 +00:00
|
|
|
#endif
|
2002-11-14 19:27:51 +00:00
|
|
|
lavc_venc_context->prediction_method= lavc_param_prediction_method;
|
2003-09-01 13:26:05 +00:00
|
|
|
switch(lavc_param_format)
|
|
|
|
{
|
|
|
|
case IMGFMT_YV12:
|
2005-02-23 00:10:26 +00:00
|
|
|
// HACK, mjpeg accepts PIX_FMT_YUV420P only with vstrict=-1
|
|
|
|
if (strcasecmp(lavc_param_vcodec, "mjpeg") == 0)
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUVJ420P;
|
|
|
|
else
|
2003-09-01 13:26:05 +00:00
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUV420P;
|
|
|
|
break;
|
|
|
|
case IMGFMT_422P:
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUV422P;
|
|
|
|
break;
|
|
|
|
case IMGFMT_444P:
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUV444P;
|
|
|
|
break;
|
|
|
|
case IMGFMT_411P:
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUV411P;
|
|
|
|
break;
|
|
|
|
case IMGFMT_YVU9:
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_YUV410P;
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
lavc_venc_context->pix_fmt = PIX_FMT_RGBA32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"%s is not a supported format\n", vo_format_name(lavc_param_format));
|
|
|
|
return 0;
|
2002-11-14 19:27:51 +00:00
|
|
|
}
|
2003-06-17 22:52:57 +00:00
|
|
|
|
2003-09-11 07:09:25 +00:00
|
|
|
if(!stats_file) {
|
2002-04-21 21:38:53 +00:00
|
|
|
/* lavc internal 2pass bitrate control */
|
2002-07-08 21:34:24 +00:00
|
|
|
switch(lavc_param_vpass){
|
2002-08-25 21:43:22 +00:00
|
|
|
case 2:
|
2004-09-18 23:20:09 +00:00
|
|
|
case 3:
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->flags|= CODEC_FLAG_PASS2;
|
2003-09-19 18:45:02 +00:00
|
|
|
stats_file= fopen(passtmpfile, "rb");
|
2002-08-25 21:43:22 +00:00
|
|
|
if(stats_file==NULL){
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fseek(stats_file, 0, SEEK_END);
|
|
|
|
size= ftell(stats_file);
|
|
|
|
fseek(stats_file, 0, SEEK_SET);
|
|
|
|
|
2005-01-08 19:16:21 +00:00
|
|
|
lavc_venc_context->stats_in= av_malloc(size + 1);
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->stats_in[size]=0;
|
2002-08-25 21:43:22 +00:00
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
if(fread(lavc_venc_context->stats_in, size, 1, stats_file)<1){
|
2002-08-25 21:43:22 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: reading from filename=%s\n", passtmpfile);
|
|
|
|
return 0;
|
2002-08-25 21:52:31 +00:00
|
|
|
}
|
2004-09-18 23:20:09 +00:00
|
|
|
if(lavc_param_vpass == 2)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
fclose(stats_file);
|
|
|
|
/* fall through */
|
|
|
|
case 1:
|
|
|
|
lavc_venc_context->flags|= CODEC_FLAG_PASS1;
|
|
|
|
stats_file= fopen(passtmpfile, "wb");
|
|
|
|
if(stats_file==NULL){
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-09-20 20:07:29 +00:00
|
|
|
if(lavc_param_turbo && (lavc_param_vpass == 1)) {
|
2004-09-19 09:59:05 +00:00
|
|
|
/* uses SAD comparison functions instead of other hungrier */
|
|
|
|
lavc_venc_context->me_pre_cmp = 0;
|
|
|
|
lavc_venc_context->me_cmp = 0;
|
|
|
|
lavc_venc_context->me_sub_cmp = 0;
|
|
|
|
lavc_venc_context->mb_cmp = 2;
|
|
|
|
|
|
|
|
/* Disables diamond motion estimation */
|
|
|
|
lavc_venc_context->pre_dia_size = 0;
|
|
|
|
lavc_venc_context->dia_size = 0;
|
|
|
|
|
|
|
|
lavc_venc_context->quantizer_noise_shaping = 0; // qns=0
|
|
|
|
lavc_venc_context->noise_reduction = 0; // nr=0
|
|
|
|
|
|
|
|
if (lavc_param_mb_decision) {
|
|
|
|
lavc_venc_context->mb_decision = 1; // mbd=0 ("realtime" encoding)
|
|
|
|
}
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_QPEL;
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_4MV;
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_TRELLIS_QUANT;
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_CBP_RD;
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_QP_RD;
|
|
|
|
lavc_venc_context->flags &= ~CODEC_FLAG_MV0;
|
|
|
|
}
|
2002-08-25 21:43:22 +00:00
|
|
|
break;
|
2002-07-08 21:34:24 +00:00
|
|
|
}
|
2003-09-11 07:09:25 +00:00
|
|
|
}
|
2002-04-21 21:38:53 +00:00
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->me_method = ME_ZERO+lavc_param_vme;
|
2002-04-10 23:23:36 +00:00
|
|
|
|
|
|
|
/* fixed qscale :p */
|
|
|
|
if (lavc_param_vqscale)
|
|
|
|
{
|
2003-10-07 11:45:09 +00:00
|
|
|
printf("Using constant qscale = %f (VBR)\n", lavc_param_vqscale);
|
2002-09-19 09:47:37 +00:00
|
|
|
lavc_venc_context->flags |= CODEC_FLAG_QSCALE;
|
2003-05-19 13:40:50 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4668
|
2003-10-07 11:45:09 +00:00
|
|
|
lavc_venc_context->global_quality=
|
2003-05-19 13:40:50 +00:00
|
|
|
#endif
|
2003-10-07 11:45:09 +00:00
|
|
|
vf->priv->pic->quality = (int)(FF_QP2LAMBDA * lavc_param_vqscale + 0.5);
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
2004-07-06 02:10:22 +00:00
|
|
|
|
|
|
|
#if LIBAVCODEC_BUILD >= 4716
|
|
|
|
if(lavc_param_threads > 1)
|
|
|
|
avcodec_thread_init(lavc_venc_context, lavc_param_threads);
|
|
|
|
#endif
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
if (avcodec_open(lavc_venc_context, vf->priv->codec) != 0) {
|
2002-04-10 23:23:36 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
if (lavc_venc_context->codec->encode == NULL) {
|
2002-04-10 23:23:36 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-25 21:43:22 +00:00
|
|
|
|
|
|
|
/* free second pass buffer, its not needed anymore */
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&lavc_venc_context->stats_in);
|
2002-11-14 19:27:51 +00:00
|
|
|
if(lavc_venc_context->bits_per_sample)
|
|
|
|
mux_v->bih->biBitCount= lavc_venc_context->bits_per_sample;
|
|
|
|
if(lavc_venc_context->extradata_size){
|
|
|
|
memcpy(mux_v->bih + 1, lavc_venc_context->extradata, lavc_venc_context->extradata_size);
|
|
|
|
mux_v->bih->biSize= sizeof(BITMAPINFOHEADER) + lavc_venc_context->extradata_size;
|
|
|
|
}
|
2002-08-25 21:43:22 +00:00
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vf_instance_s* vf, int request, void* data){
|
|
|
|
|
2004-12-01 20:32:05 +00:00
|
|
|
switch(request){
|
|
|
|
case VFCTRL_FLUSH_FRAMES:
|
|
|
|
if(vf->priv->codec->capabilities & CODEC_CAP_DELAY)
|
|
|
|
while(encode_frame(vf, NULL) > 0);
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
default:
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|
|
|
switch(fmt){
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_I420:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_YV12)
|
2002-11-14 19:27:51 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
2003-06-14 01:26:06 +00:00
|
|
|
case IMGFMT_411P:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_411P)
|
2003-06-14 01:26:06 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
2002-11-14 19:27:51 +00:00
|
|
|
case IMGFMT_422P:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_422P)
|
2002-11-14 19:27:51 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
2003-06-14 01:26:06 +00:00
|
|
|
case IMGFMT_444P:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_444P)
|
2003-06-14 01:26:06 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
|
|
|
case IMGFMT_YVU9:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_YVU9)
|
2003-06-14 01:26:06 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
2003-06-17 22:52:57 +00:00
|
|
|
case IMGFMT_BGR32:
|
2003-09-01 13:26:05 +00:00
|
|
|
if(lavc_param_format == IMGFMT_BGR32)
|
2003-06-17 22:52:57 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
|
|
|
|
break;
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-04 21:46:53 +00:00
|
|
|
static double psnr(double d){
|
|
|
|
if(d==0) return INFINITY;
|
|
|
|
return -10.0*log(d)/log(10);
|
|
|
|
}
|
|
|
|
|
2002-09-10 22:18:32 +00:00
|
|
|
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
2002-12-09 12:36:04 +00:00
|
|
|
AVFrame *pic= vf->priv->pic;
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2002-12-04 10:49:03 +00:00
|
|
|
pic->data[0]=mpi->planes[0];
|
|
|
|
pic->data[1]=mpi->planes[1];
|
|
|
|
pic->data[2]=mpi->planes[2];
|
|
|
|
pic->linesize[0]=mpi->stride[0];
|
|
|
|
pic->linesize[1]=mpi->stride[1];
|
|
|
|
pic->linesize[2]=mpi->stride[2];
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2003-12-22 17:42:54 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4697
|
2003-12-22 20:22:06 +00:00
|
|
|
if(lavc_param_interlaced_dct){
|
|
|
|
if((mpi->fields & MP_IMGFIELD_ORDERED) && (mpi->fields & MP_IMGFIELD_INTERLACED))
|
|
|
|
pic->top_field_first= !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
|
|
|
|
else
|
|
|
|
pic->top_field_first= 1;
|
2003-12-22 17:42:54 +00:00
|
|
|
|
2003-12-22 20:22:06 +00:00
|
|
|
if(lavc_param_top!=-1)
|
|
|
|
pic->top_field_first= lavc_param_top;
|
|
|
|
}
|
2003-12-22 17:42:54 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-01 20:32:05 +00:00
|
|
|
return (encode_frame(vf, pic) >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int encode_frame(struct vf_instance_s* vf, AVFrame *pic){
|
|
|
|
const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'};
|
|
|
|
int out_size;
|
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
|
2002-12-04 10:49:03 +00:00
|
|
|
pic);
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2004-12-01 20:32:05 +00:00
|
|
|
if(out_size == 0)
|
|
|
|
return 0;
|
2003-03-05 16:40:14 +00:00
|
|
|
|
2003-01-19 01:48:52 +00:00
|
|
|
muxer_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0);
|
2002-12-09 12:36:04 +00:00
|
|
|
|
2002-12-04 21:46:53 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4643
|
|
|
|
/* store psnr / pict size / type / qscale */
|
|
|
|
if(lavc_param_psnr){
|
|
|
|
static FILE *fvstats=NULL;
|
|
|
|
char filename[20];
|
|
|
|
static long long int all_len=0;
|
|
|
|
static int frame_number=0;
|
|
|
|
static double all_frametime=0.0;
|
2002-12-09 12:36:04 +00:00
|
|
|
AVFrame *pic= lavc_venc_context->coded_frame;
|
2002-12-04 21:46:53 +00:00
|
|
|
double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0;
|
2003-04-06 23:37:56 +00:00
|
|
|
double quality=0.0;
|
2003-04-07 13:48:51 +00:00
|
|
|
int8_t *q;
|
2002-12-04 21:46:53 +00:00
|
|
|
|
|
|
|
if(!fvstats) {
|
|
|
|
time_t today2;
|
|
|
|
struct tm *today;
|
|
|
|
today2 = time(NULL);
|
|
|
|
today = localtime(&today2);
|
|
|
|
sprintf(filename, "psnr_%02d%02d%02d.log", today->tm_hour,
|
|
|
|
today->tm_min, today->tm_sec);
|
|
|
|
fvstats = fopen(filename,"w");
|
|
|
|
if(!fvstats) {
|
|
|
|
perror("fopen");
|
|
|
|
lavc_param_psnr=0; // disable block
|
2004-08-09 23:46:28 +00:00
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,"Can't open %s for writing. Check its permissions.\n",filename);
|
2004-12-01 20:32:05 +00:00
|
|
|
return -1;
|
2002-12-04 21:46:53 +00:00
|
|
|
/*exit(1);*/
|
|
|
|
}
|
|
|
|
}
|
2003-04-06 23:37:56 +00:00
|
|
|
|
|
|
|
// average MB quantizer
|
2003-04-07 13:48:51 +00:00
|
|
|
q = lavc_venc_context->coded_frame->qscale_table;
|
|
|
|
if(q) {
|
2003-04-06 23:37:56 +00:00
|
|
|
int x, y;
|
|
|
|
int w = (lavc_venc_context->width+15) >> 4;
|
|
|
|
int h = (lavc_venc_context->height+15) >> 4;
|
|
|
|
for( y = 0; y < h; y++ ) {
|
|
|
|
for( x = 0; x < w; x++ )
|
|
|
|
quality += (double)*(q+x);
|
|
|
|
q += lavc_venc_context->coded_frame->qstride;
|
|
|
|
}
|
|
|
|
quality /= w * h;
|
2003-04-07 13:48:51 +00:00
|
|
|
} else
|
2003-10-07 11:45:09 +00:00
|
|
|
quality = lavc_venc_context->coded_frame->quality / (float)FF_QP2LAMBDA;
|
2002-12-04 21:46:53 +00:00
|
|
|
|
|
|
|
fprintf(fvstats, "%6d, %2.2f, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
|
2002-12-09 12:36:04 +00:00
|
|
|
lavc_venc_context->coded_frame->coded_picture_number,
|
2003-04-06 23:37:56 +00:00
|
|
|
quality,
|
2002-12-04 21:46:53 +00:00
|
|
|
out_size,
|
2002-12-09 12:36:04 +00:00
|
|
|
psnr(lavc_venc_context->coded_frame->error[0]/f),
|
|
|
|
psnr(lavc_venc_context->coded_frame->error[1]*4/f),
|
|
|
|
psnr(lavc_venc_context->coded_frame->error[2]*4/f),
|
|
|
|
psnr((lavc_venc_context->coded_frame->error[0]+lavc_venc_context->coded_frame->error[1]+lavc_venc_context->coded_frame->error[2])/(f*1.5)),
|
|
|
|
pict_type_char[lavc_venc_context->coded_frame->pict_type]
|
2002-12-04 21:46:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-25 21:43:22 +00:00
|
|
|
/* store stats if there are any */
|
2002-09-19 09:47:37 +00:00
|
|
|
if(lavc_venc_context->stats_out && stats_file)
|
|
|
|
fprintf(stats_file, "%s", lavc_venc_context->stats_out);
|
2004-12-01 20:32:05 +00:00
|
|
|
return out_size;
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 02:50:47 +00:00
|
|
|
static void uninit(struct vf_instance_s* vf){
|
2002-12-04 21:46:53 +00:00
|
|
|
const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'};
|
|
|
|
|
|
|
|
#if LIBAVCODEC_BUILD >= 4643
|
|
|
|
if(lavc_param_psnr){
|
|
|
|
double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0;
|
2002-12-09 12:36:04 +00:00
|
|
|
f*= lavc_venc_context->coded_frame->coded_picture_number;
|
2002-12-04 21:46:53 +00:00
|
|
|
|
|
|
|
printf("PSNR: Y:%2.2f, Cb:%2.2f, Cr:%2.2f, All:%2.2f\n",
|
|
|
|
psnr(lavc_venc_context->error[0]/f),
|
|
|
|
psnr(lavc_venc_context->error[1]*4/f),
|
|
|
|
psnr(lavc_venc_context->error[2]*4/f),
|
|
|
|
psnr((lavc_venc_context->error[0]+lavc_venc_context->error[1]+lavc_venc_context->error[2])/(f*1.5))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-09-01 14:04:41 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4675
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&lavc_venc_context->intra_matrix);
|
|
|
|
av_freep(&lavc_venc_context->inter_matrix);
|
2003-09-01 14:04:41 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-19 09:47:37 +00:00
|
|
|
avcodec_close(lavc_venc_context);
|
2002-08-25 21:43:22 +00:00
|
|
|
|
2002-08-25 21:52:31 +00:00
|
|
|
if(stats_file) fclose(stats_file);
|
|
|
|
|
2002-08-25 21:43:22 +00:00
|
|
|
/* free rc_override */
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&lavc_venc_context->rc_override);
|
2002-09-19 09:47:37 +00:00
|
|
|
|
2005-01-08 19:16:21 +00:00
|
|
|
av_freep(&vf->priv->context);
|
2002-04-11 02:50:47 +00:00
|
|
|
}
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int vf_open(vf_instance_t *vf, char* args){
|
2002-04-11 02:50:47 +00:00
|
|
|
vf->uninit=uninit;
|
2002-04-10 23:23:36 +00:00
|
|
|
vf->config=config;
|
|
|
|
vf->control=control;
|
|
|
|
vf->query_format=query_format;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
|
|
memset(vf->priv,0,sizeof(struct vf_priv_s));
|
2002-12-27 22:43:20 +00:00
|
|
|
vf->priv->mux=(muxer_stream_t*)args;
|
2002-04-10 23:23:36 +00:00
|
|
|
|
2002-05-05 00:31:40 +00:00
|
|
|
/* XXX: hack: some of the MJPEG decoder DLL's needs exported huffman
|
|
|
|
table, so we define a zero-table, also lavc mjpeg encoder is putting
|
|
|
|
huffman tables into the stream, so no problem */
|
|
|
|
if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "mjpeg"))
|
|
|
|
{
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+28);
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+28);
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+28;
|
|
|
|
}
|
2004-11-28 18:37:49 +00:00
|
|
|
else if (lavc_param_vcodec && (!strcasecmp(lavc_param_vcodec, "huffyuv")
|
|
|
|
|| !strcasecmp(lavc_param_vcodec, "ffvhuff")))
|
2002-11-14 19:27:51 +00:00
|
|
|
{
|
|
|
|
/* XXX: hack: huffyuv needs to store huffman tables (allthough we dunno the size yet ...) */
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+1000);
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+1000);
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+1000;
|
|
|
|
}
|
2003-05-19 13:40:50 +00:00
|
|
|
else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "asv1"))
|
|
|
|
{
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+8);
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+8);
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+8;
|
|
|
|
}
|
2003-09-01 12:44:31 +00:00
|
|
|
else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "asv2"))
|
|
|
|
{
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+8);
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+8);
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+8;
|
|
|
|
}
|
2002-12-28 00:04:20 +00:00
|
|
|
else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "wmv2"))
|
|
|
|
{
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+4);
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+4);
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+4;
|
|
|
|
}
|
2002-05-05 00:31:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mux_v->bih=malloc(sizeof(BITMAPINFOHEADER));
|
|
|
|
memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER));
|
|
|
|
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
|
|
|
|
}
|
2002-04-10 23:23:36 +00:00
|
|
|
mux_v->bih->biWidth=0;
|
|
|
|
mux_v->bih->biHeight=0;
|
|
|
|
mux_v->bih->biPlanes=1;
|
|
|
|
mux_v->bih->biBitCount=24;
|
|
|
|
if (!lavc_param_vcodec)
|
|
|
|
{
|
2002-05-05 00:31:40 +00:00
|
|
|
printf("No libavcodec codec specified! It's required!\n");
|
2002-04-10 23:23:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(lavc_param_vcodec, "mpeg1") || !strcasecmp(lavc_param_vcodec, "mpeg1video"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1');
|
2003-08-25 23:19:08 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "mpeg2") || !strcasecmp(lavc_param_vcodec, "mpeg2video"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '2');
|
2002-04-10 23:23:36 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "h263") || !strcasecmp(lavc_param_vcodec, "h263p"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3');
|
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "rv10"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0');
|
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "mjpeg"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G');
|
2003-06-17 22:52:57 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "ljpeg"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('L', 'J', 'P', 'G');
|
2002-04-10 23:23:36 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "mpeg4"))
|
2005-02-22 20:24:18 +00:00
|
|
|
mux_v->bih->biCompression = mmioFOURCC('F', 'M', 'P', '4');
|
2002-04-10 23:23:36 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "msmpeg4"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3');
|
2002-05-04 18:18:10 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "msmpeg4v2"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('M', 'P', '4', '2');
|
2002-06-18 01:39:26 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "wmv1"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '1');
|
2002-12-28 00:04:20 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "wmv2"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '2');
|
2002-11-14 19:27:51 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "huffyuv"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('H', 'F', 'Y', 'U');
|
2004-11-28 18:37:49 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "ffvhuff"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('F', 'F', 'V', 'H');
|
2003-05-19 13:40:50 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "asv1"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('A', 'S', 'V', '1');
|
2003-09-01 12:44:31 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "asv2"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('A', 'S', 'V', '2');
|
2003-06-09 02:31:04 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "ffv1"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('F', 'F', 'V', '1');
|
2004-08-21 19:31:00 +00:00
|
|
|
else if (!strcasecmp(lavc_param_vcodec, "snow"))
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC('S', 'N', 'O', 'W');
|
2002-04-10 23:23:36 +00:00
|
|
|
else
|
|
|
|
mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0],
|
|
|
|
lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */
|
|
|
|
|
|
|
|
if (!avcodec_inited){
|
|
|
|
avcodec_init();
|
|
|
|
avcodec_register_all();
|
|
|
|
avcodec_inited=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec);
|
|
|
|
if (!vf->priv->codec) {
|
|
|
|
mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, lavc_param_vcodec);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-09 12:36:04 +00:00
|
|
|
#if LIBAVCODEC_BUILD >= 4645
|
|
|
|
vf->priv->pic = avcodec_alloc_frame();
|
|
|
|
#else
|
2002-12-04 10:49:03 +00:00
|
|
|
vf->priv->pic = avcodec_alloc_picture();
|
2002-12-09 12:36:04 +00:00
|
|
|
#endif
|
2002-09-19 09:47:37 +00:00
|
|
|
vf->priv->context = avcodec_alloc_context();
|
|
|
|
|
2002-04-10 23:23:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t ve_info_lavc = {
|
|
|
|
"libavcodec encoder",
|
|
|
|
"lavc",
|
2002-07-08 21:34:24 +00:00
|
|
|
"A'rpi, Alex, Michael",
|
2002-04-10 23:23:36 +00:00
|
|
|
"for internal use by mencoder",
|
|
|
|
vf_open
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
#endif
|