Commit efdd9d24 authored by corey's avatar corey

sc_factor support for encoding.

Here's the description I'll add to the mplayer man page:
---
Causes frames with higher quantizers to be more likely to trigger a
scene change detection and make libavcodec use an I-frame (default: 1).
1-16 is a sane range.
Values between 2 and 6 may yield increasing PSNR (up to approximately
0.04 dB) and better placement of I-frames in high-motion scenes.
Higher values than 6 may give very slightly better PSNR (approximately
0.01 dB more than sc_factor=6), but noticably worse visual quality.
---

Original idea from Michael; patch by me.


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@4883 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 712ca5a8
...@@ -1989,6 +1989,13 @@ typedef struct AVCodecContext { ...@@ -1989,6 +1989,13 @@ typedef struct AVCodecContext {
* - decoding: unused * - decoding: unused
*/ */
int cutoff; int cutoff;
/**
* multiplied by qscale for each frame and added to scene_change_score
* - encoding: set by user.
* - decoding: unused
*/
int scenechange_factor;
} AVCodecContext; } AVCodecContext;
/** /**
......
...@@ -1179,7 +1179,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, ...@@ -1179,7 +1179,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
if (vard <= 64<<8 || vard < varc) { //FIXME if (vard <= 64<<8 || vard < varc) { //FIXME
c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
}else{ }else{
c->scene_change_score+= s->qscale; c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
} }
return; return;
} }
...@@ -1270,7 +1270,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, ...@@ -1270,7 +1270,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
if (vard <= 64<<8 || vard < varc) if (vard <= 64<<8 || vard < varc)
c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
else else
c->scene_change_score+= s->qscale; c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
if(mb_type == CANDIDATE_MB_TYPE_INTER){ if(mb_type == CANDIDATE_MB_TYPE_INTER){
c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
...@@ -1291,7 +1291,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, ...@@ -1291,7 +1291,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
if (vard <= 64<<8 || vard < varc) if (vard <= 64<<8 || vard < varc)
c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
else else
c->scene_change_score+= s->qscale; c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
if (vard*2 + 200*256 > varc) if (vard*2 + 200*256 > varc)
mb_type|= CANDIDATE_MB_TYPE_INTRA; mb_type|= CANDIDATE_MB_TYPE_INTRA;
...@@ -1397,7 +1397,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, ...@@ -1397,7 +1397,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
if (vard <= 64<<8 || vard < varc) { //FIXME if (vard <= 64<<8 || vard < varc) { //FIXME
c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
}else{ }else{
c->scene_change_score+= s->qscale; c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
} }
} }
...@@ -1843,7 +1843,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, ...@@ -1843,7 +1843,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
/* if (vard <= 64<<8 || vard < varc) { /* if (vard <= 64<<8 || vard < varc) {
c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
}else{ }else{
c->scene_change_score+= s->qscale; c->scene_change_score+= s->qscale * s->avctx->scenechange_factor;
}*/ }*/
return; return;
} }
......
...@@ -734,6 +734,7 @@ static AVOption options[]={ ...@@ -734,6 +734,7 @@ static AVOption options[]={
{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"}, {"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"}, {"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"}, {"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
{"sc_factor", NULL, OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
{NULL}, {NULL},
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment