On date Tuesday 2011-05-17 12:05:34 +0800, Can Wu encoded: > Hi: > > There are HDTV channel in the broadcast here, but since lack of HDTV > program, the provider will transcode SDTV program to HDTV program, the > result black margin around the original SDTV video content. > So this filter is used for detect it. > > For the patches: > Current ffplay had not put video key_frame and pict_type to refpic, so the > first one is to add this info, for the blackmargin filter will only check if > it's key frame; > The second patch is the filter itself. > > Best Regards! > > -- > wucan
> From 81281bc59003a779442c3eebc71bda44b3b9b0e2 Mon Sep 17 00:00:00 2001 > From: Can Wu <[email protected]> > Date: Tue, 17 May 2011 11:30:19 +0800 > Subject: ffplay: fillin more video props for filter > > Maybe our video filter will use it... > --- > ffplay.c | 4 ++++ > 1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/ffplay.c b/ffplay.c > index a5dc358..d31d56a 100644 > --- a/ffplay.c > +++ b/ffplay.c > @@ -1706,6 +1706,10 @@ static int input_request_frame(AVFilterLink *link) > picref->pts = pts; > picref->pos = pkt.pos; > picref->video->pixel_aspect = > priv->is->video_st->codec->sample_aspect_ratio; > + picref->video->interlaced = priv->frame->interlaced_frame; > + picref->video->top_field_first = priv->frame->top_field_first; > + picref->video->pict_type = priv->frame->pict_type; > + picref->video->key_frame = priv->frame->key_frame; > avfilter_start_frame(link, picref); > avfilter_draw_slice(link, 0, link->h, 1); > avfilter_end_frame(link); > -- > 1.7.3.2.168.gd6b63 > > From 256eaff7d1df6cdd8a6df21ea836242e5ebc7194 Mon Sep 17 00:00:00 2001 > From: Can Wu <[email protected]> > Date: Tue, 17 May 2011 11:38:25 +0800 > Subject: libavfilter: add blackmargin filter > > Used to detect black margin around video content. [...] > +static void end_frame(AVFilterLink *inlink) > +{ > + AVFilterContext *ctx = inlink->dst; > + BlackMarginContext *blackmargin = ctx->priv; > + AVFilterBufferRef *picref = inlink->cur_buf; > + int pblack; > + int x, y; > + uint8_t *p; > + unsigned int nblack; > + int margin_top, margin_bottom, margin_left, margin_right; > + > + /* only check on key frame */ > + if (!picref->video->key_frame) > + return; > + > + /* up */ > + p = picref->data[0]; > + for (y = 0; y < (inlink->h >> 2); y++) { > + p += picref->linesize[0]; > + nblack = 0; > + for (x = 0; x < inlink->w; x++) { > + nblack += p[x] < blackmargin->bthresh; > + } > + pblack = nblack * 100 / inlink->w; > + if (pblack < blackmargin->bamount) { > + break; > + } > + } > + margin_top = y; > + > + /* down */ > + p = picref->data[0] + picref->linesize[0] * inlink->h; > + for (y = inlink->h; y > (inlink->h >> 2); y--) { > + p -= picref->linesize[0]; > + nblack = 0; > + for (x = 0; x < inlink->w; x++) { > + nblack += p[x] < blackmargin->bthresh; > + } > + pblack = nblack * 100 / inlink->w; > + if (pblack < blackmargin->bamount) { > + break; > + } > + } > + margin_bottom = (inlink->h - y); > + > + if (margin_top + margin_bottom >= inlink->h) { > + margin_left = 0; > + margin_right = 0; > + av_log(ctx, AV_LOG_WARNING, "full black frame!\n"); > + goto done; > + } > + > + /* left */ > + p = picref->data[0] + picref->linesize[0] * margin_top; > + for (x = 0; x < (inlink->w >> 2); x++) { > + p++; > + nblack = 0; > + for (y = margin_top; y < (inlink->h - margin_bottom); y++) { > + nblack += p[x + y * picref->linesize[0]] < blackmargin->bthresh; > + } > + pblack = nblack * 100 / (inlink->h - margin_top - margin_bottom); > + if (pblack < blackmargin->bamount) { > + break; > + } > + } > + margin_left = x; > + > + /* right */ > + p = picref->data[0] + picref->linesize[0] * margin_top; > + for (x = inlink->w; x > (inlink->w >> 2); x--) { > + p--; > + nblack = 0; > + for (y = margin_top; y < (inlink->h - margin_bottom); y++) { > + nblack += p[x + y * picref->linesize[0]] < blackmargin->bthresh; > + } > + pblack = nblack * 100 / (inlink->h - margin_top - margin_bottom); > + if (pblack < blackmargin->bamount) { > + break; > + } > + } > + margin_right = inlink->w - x; This code can be factorized by using a common routine, maybe the code could be shared with blackframe (and put it in the same file and save some RAM). > + > +done: > + av_log(ctx, AV_LOG_INFO, "frame:%u pos:%"PRId64" pts:%"PRId64" t:%f" > + " %d %d %d %d\n", uhm please annotate these values (e.g.: top:%d bottom:%d left:%d ...), or the user will have to read docs every time. -- Odd that we think definitions are definitive. :-) -- Larry Wall in <[email protected]> _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
