changeset 30394:55bf07ab4c89

Add an option to cropdetect to periodically reset the detected area. Patch by [quetschke scytek de] with modifications by me.
author reimar
date Tue, 26 Jan 2010 18:15:58 +0000
parents db62840d27ae
children 296ddce42cea
files DOCS/man/en/mplayer.1 libmpcodecs/vf_cropdetect.c
diffstat 2 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Tue Jan 26 08:03:28 2010 +0000
+++ b/DOCS/man/en/mplayer.1	Tue Jan 26 18:15:58 2010 +0000
@@ -5775,7 +5775,7 @@
 .PD 1
 .
 .TP
-.B cropdetect[=limit:round]
+.B cropdetect[=limit:round[:reset]]
 Calculates necessary cropping parameters and prints the recommended parameters
 to stdout.
 .PD 0
@@ -5789,6 +5789,13 @@
 The offset is automatically adjusted to center the video.
 Use 2 to get only even dimensions (needed for 4:2:2 video).
 16 is best when encoding to most video codecs.
+.br
+.IPs <reset>
+Counter that determines after how many frames cropdetect will reset
+the previously detected largest video area and start over to detect
+the current optimal crop area.  This can be useful when channel
+logos distort the video area.  0 indicates never reset and return
+the largest area encountered during playback. (default: 0).
 .RE
 .PD 1
 .
--- a/libmpcodecs/vf_cropdetect.c	Tue Jan 26 08:03:28 2010 +0000
+++ b/libmpcodecs/vf_cropdetect.c	Tue Jan 26 18:15:58 2010 +0000
@@ -15,6 +15,7 @@
     int x1,y1,x2,y2;
     int limit;
     int round;
+    int reset_count;
     int fno;
 };
 
@@ -49,7 +50,7 @@
     vf->priv->y1=height - 1;
     vf->priv->x2=0;
     vf->priv->y2=0;
-    vf->priv->fno=0;
+    vf->priv->fno=-2;
     return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
 }
 
@@ -72,7 +73,16 @@
     dmpi->width=mpi->width;
     dmpi->height=mpi->height;
 
-if(++vf->priv->fno>2){	// ignore first 2 frames - they may be empty
+if(++vf->priv->fno>0){	// ignore first 2 frames - they may be empty
+
+    // Reset the crop area every reset_count frames, if reset_count is > 0
+    if(vf->priv->reset_count > 0 && vf->priv->fno > vf->priv->reset_count){
+	vf->priv->x1=mpi->w-1;
+	vf->priv->y1=mpi->h-1;
+	vf->priv->x2=0;
+	vf->priv->y2=0;
+	vf->priv->fno=1;
+    }
 
     for(y=0;y<vf->priv->y1;y++){
 	if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){
@@ -153,9 +163,11 @@
     vf->priv=malloc(sizeof(struct vf_priv_s));
     vf->priv->limit=24; // should be option
     vf->priv->round = 0;
-    if(args) sscanf(args, "%d:%d",
+    vf->priv->reset_count = 0;
+    if(args) sscanf(args, "%d:%d:%d",
     &vf->priv->limit,
-    &vf->priv->round);
+    &vf->priv->round,
+    &vf->priv->reset_count);
     return 1;
 }