summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2013-09-03 22:00:30 +0000
committerjstebbins <[email protected]>2013-09-03 22:00:30 +0000
commitf725f85aa1573b5a8d4748ae5150ff19b84f9250 (patch)
tree57be8b984452d9b4047d50653ef7644061562e7f /libhb
parent2a344e45c4ed8f98e872066aa506512063d5ae51 (diff)
libhb: remove mcdeint deinterlacer
It's slow and it's quality isn't perticularly impressive... and it relies on the snow encoder which no longer exists in libav. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5766 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/decomb.c60
-rw-r--r--libhb/deinterlace.c43
-rw-r--r--libhb/mcdeint.c221
-rw-r--r--libhb/mcdeint.h35
4 files changed, 12 insertions, 347 deletions
diff --git a/libhb/decomb.c b/libhb/decomb.c
index a95e998d8..715d52784 100644
--- a/libhb/decomb.c
+++ b/libhb/decomb.c
@@ -33,7 +33,6 @@ Original "Faster" settings:
#define MODE_BLEND 2 // Use blending interpolation
#define MODE_CUBIC 4 // Use cubic interpolation
#define MODE_EEDI2 8 // Use EEDI2 interpolation
-#define MODE_MCDEINT 16 // Post-process with mcdeint
#define MODE_MASK 32 // Output combing masks instead of pictures
#define MODE_BOB 64 // Deinterlace each field to a separate frame
@@ -60,36 +59,21 @@ which will feed EEDI2 interpolations to yadif.
9: EEDI2->yadif
10: Switch between EEDI2 and blend
11: Switch between EEDI2->yadif and blend
-17: Yadif->mcdeint
-18: Blend->mcdeint
-19: Switch between blending and yadif -> mcdeint
-20: Cubic->mdeint
-21: Cubic->yadif->mcdeint
-22: Cubic or blend -> mcdeint
-23: Cubic->yadif or blend -> mcdeint
-24: EEDI2->mcdeint
-25: EEDI2->yadif->mcdeint
...okay I'm getting bored now listing all these different modes
32: Passes through the combing mask for every combed frame (white for combed pixels, otherwise black)
33+: Overlay the combing mask for every combed frame on top of the filtered output (white for combed pixels)
12-15: EEDI2 will override cubic interpolation
-16: DOES NOT WORK BY ITSELF-- mcdeint needs to be fed by another deinterlacer
*****/
#include "hb.h"
#include "hbffmpeg.h"
#include "mpeg2dec/mpeg2.h"
#include "eedi2.h"
-#include "mcdeint.h"
#include "taskset.h"
#define PARITY_DEFAULT -1
-#define MCDEINT_MODE_DEFAULT -1
-#define MCDEINT_MODE_ENABLED 2
-#define MCDEINT_QP_DEFAULT 1
-
#define ABS(a) ((a) > 0 ? (a) : (-(a)))
#define MIN3(a,b,c) MIN(MIN(a,b),c)
#define MAX3(a,b,c) MAX(MAX(a,b),c)
@@ -168,9 +152,6 @@ struct hb_filter_private_s
int yadif_ready;
- int mcdeint_mode;
- mcdeint_private_t mcdeint;
-
int deinterlaced_frames;
int blended_frames;
int unfiltered_frames;
@@ -1971,8 +1952,6 @@ static void yadif_filter( hb_filter_private_t * pv,
else
{
/* Just passing through... */
-
- /* For mcdeint's benefit... */
pv->yadif_arguments[0].is_combed = is_combed; // 0
hb_buffer_copy(dst, pv->ref[1]);
}
@@ -2013,9 +1992,6 @@ static int hb_decomb_init( hb_filter_object_t * filter,
pv->parity = PARITY_DEFAULT;
- pv->mcdeint_mode = MCDEINT_MODE_DEFAULT;
- int mcdeint_qp = MCDEINT_QP_DEFAULT;
-
if( filter->settings )
{
sscanf( filter->settings, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
@@ -2046,11 +2022,6 @@ static int hb_decomb_init( hb_filter_object_t * filter,
pv->segment_height[1] = hb_image_height(init->pix_fmt, pv->segment_height[0], 1);
pv->segment_height[2] = hb_image_height(init->pix_fmt, pv->segment_height[0], 2);
- if( pv->mode & MODE_MCDEINT )
- {
- pv->mcdeint_mode = MCDEINT_MODE_ENABLED;
- }
-
/* Allocate buffers to store comb masks. */
pv->mask = hb_frame_buffer_init(init->pix_fmt, init->width, init->height);
pv->mask_filtered = hb_frame_buffer_init(init->pix_fmt, init->width, init->height);
@@ -2450,9 +2421,6 @@ static int hb_decomb_init( hb_filter_object_t * filter,
}
}
- mcdeint_init( &pv->mcdeint, pv->mcdeint_mode, mcdeint_qp,
- init->pix_fmt, init->width, init->height );
-
return 0;
}
@@ -2530,9 +2498,6 @@ static void hb_decomb_close( hb_filter_object_t * filter )
*/
free( pv->yadif_arguments );
- /* Cleanup mcdeint specific buffers */
- mcdeint_close( &pv->mcdeint );
-
free( pv );
filter->private_data = NULL;
}
@@ -2578,9 +2543,9 @@ static int hb_decomb_work( hb_filter_object_t * filter,
tff = (pv->parity & 1) ^ 1;
}
- /* deinterlace both fields if mcdeint is enabled without bob */
+ /* deinterlace both fields if bob */
int frame, num_frames = 1;
- if (pv->mode & (MODE_MCDEINT | MODE_BOB))
+ if (pv->mode & MODE_BOB)
{
num_frames = 2;
}
@@ -2615,24 +2580,9 @@ static int hb_decomb_work( hb_filter_object_t * filter,
yadif_filter(pv, o_buf[idx], parity, tff);
- // Unfortunately, all frames must be fed to mcdeint combed or
- // not since it maintains state that is updated by each frame.
- if (pv->mcdeint_mode >= 0)
- {
- if (o_buf[idx^1] == NULL)
- {
- o_buf[idx^1] = hb_video_buffer_init(in->f.width, in->f.height);
- }
- /* Perform mcdeint filtering */
- mcdeint_filter(o_buf[idx^1], o_buf[idx], parity, &pv->mcdeint);
-
- // If frame was combed, we will use results from mcdeint
- // else we will use yadif result
- if (pv->is_combed)
- idx ^= 1;
- }
-
- // Add to list of output buffers (should be at most 2)
+ // If bob, add all frames to output
+ // else, if not combed, add frame to output
+ // else if final iteration, add frame to output
if ((pv->mode & MODE_BOB) ||
pv->is_combed == 0 ||
frame == num_frames - 1)
diff --git a/libhb/deinterlace.c b/libhb/deinterlace.c
index a7e724c02..09b92c437 100644
--- a/libhb/deinterlace.c
+++ b/libhb/deinterlace.c
@@ -19,11 +19,9 @@
#include "hb.h"
#include "hbffmpeg.h"
#include "mpeg2dec/mpeg2.h"
-#include "mcdeint.h"
#include "taskset.h"
// yadif_mode is a bit vector with the following flags
-// Note that 2PASS should be enabled when using MCDEINT
#define MODE_YADIF_ENABLE 1
#define MODE_YADIF_SPATIAL 2
#define MODE_YADIF_2PASS 4
@@ -32,9 +30,6 @@
#define YADIF_MODE_DEFAULT 0
#define YADIF_PARITY_DEFAULT -1
-#define MCDEINT_MODE_DEFAULT -1
-#define MCDEINT_QP_DEFAULT 1
-
#define ABS(a) ((a) > 0 ? (a) : (-(a)))
#define MIN3(a,b,c) MIN(MIN(a,b),c)
#define MAX3(a,b,c) MAX(MAX(a,b),c)
@@ -61,11 +56,6 @@ struct hb_filter_private_s
taskset_t yadif_taskset; // Threads for Yadif - one per CPU
yadif_arguments_t *yadif_arguments; // Arguments to thread for work
-
- int mcdeint_mode;
- mcdeint_private_t mcdeint;
-
- //hb_buffer_t * buf_out[2];
};
static int hb_deinterlace_init( hb_filter_object_t * filter,
@@ -81,7 +71,7 @@ hb_filter_object_t hb_filter_deinterlace =
{
.id = HB_FILTER_DEINTERLACE,
.enforce_order = 1,
- .name = "Deinterlace (ffmpeg or yadif/mcdeint)",
+ .name = "Deinterlace",
.settings = NULL,
.init = hb_deinterlace_init,
.work = hb_deinterlace_work,
@@ -336,16 +326,11 @@ static int hb_deinterlace_init( hb_filter_object_t * filter,
pv->yadif_mode = YADIF_MODE_DEFAULT;
pv->yadif_parity = YADIF_PARITY_DEFAULT;
- pv->mcdeint_mode = MCDEINT_MODE_DEFAULT;
- int mcdeint_qp = MCDEINT_QP_DEFAULT;
-
if( filter->settings )
{
- sscanf( filter->settings, "%d:%d:%d:%d",
+ sscanf( filter->settings, "%d:%d",
&pv->yadif_mode,
- &pv->yadif_parity,
- &pv->mcdeint_mode,
- &mcdeint_qp );
+ &pv->yadif_parity);
}
pv->cpu_count = hb_get_cpu_count();
@@ -384,9 +369,6 @@ static int hb_deinterlace_init( hb_filter_object_t * filter,
}
}
}
-
- mcdeint_init( &pv->mcdeint, pv->mcdeint_mode, mcdeint_qp,
- init->pix_fmt, init->width, init->height );
return 0;
}
@@ -413,8 +395,6 @@ static void hb_deinterlace_close( hb_filter_object_t * filter )
free( pv->yadif_arguments );
}
-
- mcdeint_close( &pv->mcdeint );
free( pv );
filter->private_data = NULL;
@@ -494,7 +474,7 @@ static int hb_deinterlace_work( hb_filter_object_t * filter,
tff = (pv->yadif_parity & 1) ^ 1;
}
- /* deinterlace both fields if mcdeint is enabled without bob */
+ /* deinterlace both fields if yadif 2 pass or bob */
int frame, num_frames = 1;
if ((pv->yadif_mode & MODE_YADIF_2PASS) ||
(pv->yadif_mode & MODE_YADIF_BOB))
@@ -506,7 +486,7 @@ static int hb_deinterlace_work( hb_filter_object_t * filter,
int idx = 0;
hb_buffer_t * o_buf[2] = {NULL,};
- /* Perform yadif and mcdeint filtering */
+ /* Perform yadif filtering */
for( frame = 0; frame < num_frames; frame++ )
{
int parity = frame ^ tff ^ 1;
@@ -517,18 +497,8 @@ static int hb_deinterlace_work( hb_filter_object_t * filter,
}
yadif_filter(pv, o_buf[idx], parity, tff);
- if (pv->mcdeint_mode >= 0)
- {
- if (o_buf[idx^1] == NULL)
- {
- o_buf[idx^1] = hb_frame_buffer_init(in->f.fmt, in->f.width, in->f.height);
- }
- mcdeint_filter( o_buf[idx^1], o_buf[idx], parity, &pv->mcdeint );
- idx ^= 1;
- }
-
// If bob, add both frames
- // else, add only second frame
+ // else, add only final frame
if (( pv->yadif_mode & MODE_YADIF_BOB ) || frame == num_frames - 1)
{
if ( out == NULL )
@@ -550,6 +520,7 @@ static int hb_deinterlace_work( hb_filter_object_t * filter,
idx ^= 1;
}
}
+
// Copy subs only to first output buffer
hb_buffer_move_subs( out, pv->yadif_ref[1] );
diff --git a/libhb/mcdeint.c b/libhb/mcdeint.c
index 9eb6f5ac0..e69de29bb 100644
--- a/libhb/mcdeint.c
+++ b/libhb/mcdeint.c
@@ -1,221 +0,0 @@
-/*
- Copyright (C) 2006 Michael Niedermayer <[email protected]>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "hb.h"
-#include "hbffmpeg.h"
-#include "mpeg2dec/mpeg2.h"
-#include "mcdeint.h"
-
-#define SUPPRESS_AV_LOG
-
-#define ABS(a) ((a) > 0 ? (a) : (-(a)))
-
-void mcdeint_init( mcdeint_private_t * pv,
- int mode,
- int qp,
- int pix_fmt,
- int width,
- int height )
-{
- pv->mcdeint_mode = mode;
- pv->mcdeint_qp = qp;
-
- /* Allocate mcdeint specific buffers */
- if( pv->mcdeint_mode >= 0 )
- {
- avcodec_register_all();
-
- AVCodec * enc = avcodec_find_encoder( AV_CODEC_ID_SNOW );
-
- // Snow ME_ITER will crash if width & height are not 16 pixel
- // aligned (or 8 pixel if CODEC_FLAG_4MV is set).
- // Fortunately, our input buffers have padding
- width = (width + 15) & ~0xf;
- height = (height + 15) & ~0xf;
-
- AVCodecContext * avctx_enc;
-
- avctx_enc = pv->mcdeint_avctx_enc = avcodec_alloc_context3( enc );
-
- avctx_enc->width = width;
- avctx_enc->height = height;
- avctx_enc->time_base = (AVRational){1,25}; // meaningless
- avctx_enc->gop_size = 300;
- avctx_enc->max_b_frames = 0;
- avctx_enc->pix_fmt = pix_fmt;
- avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
- avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
- avctx_enc->global_quality = 1;
- avctx_enc->me_cmp = FF_CMP_SAD; //SSE;
- avctx_enc->me_sub_cmp = FF_CMP_SAD; //SSE;
- avctx_enc->mb_cmp = FF_CMP_SSE;
-
- switch( pv->mcdeint_mode )
- {
- case 3:
- avctx_enc->refs = 3;
- case 2:
- avctx_enc->me_method = ME_ITER;
- case 1:
- avctx_enc->flags |= CODEC_FLAG_4MV;
- avctx_enc->dia_size =2;
- case 0:
- avctx_enc->flags |= CODEC_FLAG_QPEL;
- }
-
- hb_avcodec_open(avctx_enc, enc, NULL, 0);
-
- pv->mcdeint_frame = avcodec_alloc_frame();
- av_new_packet( &pv->mcdeint_pkt, width * height * 10 );
- }
-}
-
-void mcdeint_close( mcdeint_private_t * pv )
-{
- /* Cleanup mcdeint specific buffers */
- if( pv->mcdeint_mode >= 0 )
- {
- if( pv->mcdeint_avctx_enc )
- {
- hb_avcodec_close( pv->mcdeint_avctx_enc );
- av_freep( &pv->mcdeint_avctx_enc );
- }
- av_free_packet( &pv->mcdeint_pkt );
- }
-}
-
-void mcdeint_filter( hb_buffer_t * dst_buf,
- hb_buffer_t * src_buf,
- int parity,
- mcdeint_private_t * pv )
-{
- int x, y, i;
-
-#ifdef SUPPRESS_AV_LOG
- /* TODO: temporarily change log level to suppress obnoxious debug output */
- int loglevel = av_log_get_level();
- av_log_set_level( AV_LOG_QUIET );
-#endif
-
- for( i=0; i<3; i++ )
- {
- pv->mcdeint_frame->data[i] = src_buf->plane[i].data;
- pv->mcdeint_frame->linesize[i] = src_buf->plane[i].stride;
- }
- pv->mcdeint_avctx_enc->me_cmp = FF_CMP_SAD;
- pv->mcdeint_avctx_enc->me_sub_cmp = FF_CMP_SAD;
- pv->mcdeint_frame->quality = pv->mcdeint_qp * FF_QP2LAMBDA;
-
- int got_packet;
-
- avcodec_encode_video2( pv->mcdeint_avctx_enc,
- &pv->mcdeint_pkt, pv->mcdeint_frame, &got_packet );
-
- pv->mcdeint_frame_dec = pv->mcdeint_avctx_enc->coded_frame;
-
- for( i = 0; i < 3; i++ )
- {
- uint8_t * dst = dst_buf->plane[i].data;
- uint8_t * src = src_buf->plane[i].data;
- int w = src_buf->plane[i].stride;
- int h = src_buf->plane[i].height;
- int fils = pv->mcdeint_frame_dec->linesize[i];
- int srcs = src_buf->plane[i].stride;
-
- for (y = parity; y < h; y += 2)
- {
- for( x = 0; x < w; x++ )
- {
- if( (x-1)+(y-1)*w >= 0 && (x+1)+(y+1)*w < w*h )
- {
- uint8_t * filp =
- &pv->mcdeint_frame_dec->data[i][x + y * fils];
- uint8_t * srcp = &src[x + y * srcs];
-
- int diff0 = filp[-fils] - srcp[-srcs];
- int diff1 = filp[+fils] - srcp[+srcs];
- int spatial_score;
-
- spatial_score =
- ABS(srcp[-srcs-1] - srcp[+srcs-1]) +
- ABS(srcp[-srcs ] - srcp[+srcs ]) +
- ABS(srcp[-srcs+1] - srcp[+srcs+1]) - 1;
-
- int temp = filp[0];
-
-#define MCDEINT_CHECK(j)\
- { int score = ABS(srcp[-srcs-1+j] - srcp[+srcs-1-j])\
- + ABS(srcp[-srcs +j] - srcp[+srcs -j])\
- + ABS(srcp[-srcs+1+j] - srcp[+srcs+1-j]);\
- if( score < spatial_score ) {\
- spatial_score = score;\
- diff0 = filp[-fils+j] - srcp[-srcs+j];\
- diff1 = filp[+fils-j] - srcp[+srcs-j];
-
- if( x >= 2 && x <= w - 3 )
- {
- MCDEINT_CHECK(-1)
- if( x >= 3 && x <= w - 4 )
- {
- MCDEINT_CHECK(-2) }} }}
- }
- }
- if( x >= 2 && x <= w - 3 )
- {
- MCDEINT_CHECK(1)
- if( x >= 3 && x <= w - 4 )
- {
- MCDEINT_CHECK(2) }} }}
- }
- }
-
- if(diff0 + diff1 > 0)
- {
- temp -= (diff0 + diff1 -
- ABS( ABS(diff0) - ABS(diff1) ) / 2) / 2;
- }
- else
- {
- temp -= (diff0 + diff1 +
- ABS( ABS(diff0) - ABS(diff1) ) / 2) / 2;
- }
-
- filp[0] = dst[x + y*w] =
- temp > 255U ? ~(temp>>31) : temp;
- }
- else
- {
- dst[x + y*w] =
- pv->mcdeint_frame_dec->data[i][x + y*fils];
- }
- }
- }
-
- for( y = !parity; y < h; y += 2 )
- {
- memcpy(&pv->mcdeint_frame_dec->data[i][y * fils],
- &src[y * srcs], w);
- memcpy(&dst[y * w], &src[y * srcs], w);
- }
- }
-
-#ifdef SUPPRESS_AV_LOG
- /* TODO: restore previous log level */
- av_log_set_level(loglevel);
-#endif
-}
diff --git a/libhb/mcdeint.h b/libhb/mcdeint.h
index 621fd58e2..e69de29bb 100644
--- a/libhb/mcdeint.h
+++ b/libhb/mcdeint.h
@@ -1,35 +0,0 @@
-/* mcdeint.h
-
- Copyright (c) 2003-2013 HandBrake Team
- This file is part of the HandBrake source code
- Homepage: <http://handbrake.fr/>.
- It may be used under the terms of the GNU General Public License v2.
- For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
- */
-
-struct mcdeint_private_s
-{
- int mcdeint_mode;
- int mcdeint_qp;
-
- AVPacket mcdeint_pkt;
- AVCodecContext * mcdeint_avctx_enc;
- AVFrame * mcdeint_frame;
- AVFrame * mcdeint_frame_dec;
-};
-
-typedef struct mcdeint_private_s mcdeint_private_t;
-
-void mcdeint_init( mcdeint_private_t * pv,
- int mode,
- int qp,
- int pix_fmt,
- int width,
- int height );
-
-void mcdeint_close( mcdeint_private_t * pv );
-
-void mcdeint_filter( hb_buffer_t * dst,
- hb_buffer_t * src,
- int parity,
- mcdeint_private_t * pv );