Permalink
Browse files

Improved cropping of the bottom 8 lines of 1088-line video.

Refs #11358.  Reverts 9d9de7b and
cleans up the bottom 8 lines by applying a crop filter to the source.
This is tested for the XVideo output method.

The VDPAU output method does not use the standard filter mechanism,
but it works fine on 1088-line video until the h.264 parser thinks the
resolution has changed from 1080 to 1088 lines.  To compensate, we
don't acknowledge a resolution change when this happens.
  • Loading branch information...
stichnot committed Feb 10, 2013
1 parent 44a7f06 commit c0bc92822fe63221ad8fc5cf52a6e661b37b6f21
@@ -3127,6 +3127,8 @@ bool AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt)
current_aspect = get_aspect(*m_h264_parser);
uint width = m_h264_parser->pictureWidth();
uint height = m_h264_parser->pictureHeight();
if (height == 1088 && current_height == 1080)
height = 1080;
float seqFPS = m_h264_parser->frameRate() * 0.001f;
bool res_changed = ((width != (uint)current_width) ||
@@ -53,11 +53,49 @@ FilterChain::~FilterChain()
filters.clear();
}
// Applies a crop filter, modifed from filter_crop.c, to crop the
// bottom 8 lines of a 1088-line frame, which often contains garbage.
static void crop1088(VideoFrame *frame)
{
if (frame->height != 1088)
return;
if (frame->width != 1920 && frame->width != 1440)
return;
if (frame->pitches[1] != frame->pitches[2])
return;
// assume input and output formats are FMT_YV12
uint64_t *ybuf = (uint64_t*) (frame->buf + frame->offsets[0]);
uint64_t *ubuf = (uint64_t*) (frame->buf + frame->offsets[1]);
uint64_t *vbuf = (uint64_t*) (frame->buf + frame->offsets[2]);
const uint64_t Y_black = 0x0000000000000000LL; // 8 bytes
const uint64_t UV_black = 0x8080808080808080LL; // 8 bytes
int y;
int sz = (frame->pitches[0] * frame->height) >> 3; // div 8 bytes
// Luma bottom
y = ((frame->height >> 4) - 1) * frame->pitches[0] << 1;
y = (y + sz) / 2;
for (; y < sz; y++)
{
ybuf[y] = Y_black;
}
// Chroma bottom
sz = (frame->pitches[1] * (frame->height >> 1)) >> 3; // div 8 bytes
y = ((frame->height >> 4) - 1) * frame->pitches[1];
y = (y + sz) / 2;
for (; y < sz; y++)
{
ubuf[y] = UV_black;
vbuf[y] = UV_black;
}
}
void FilterChain::ProcessFrame(VideoFrame *frame, FrameScanType scan)
{
if (!frame)
return;
crop1088(frame);
vector<VideoFilter*>::iterator it = filters.begin();
for (; it != filters.end(); ++it)
(*it)->filter(*it, frame, kScan_Intr2ndField == scan);
@@ -140,7 +140,6 @@ void VideoOutWindow::MoveResize(void)
}
// Apply various modifications
Apply1080Fixup();
ApplyDBScaleAndMove();
ApplyLetterboxing();
ApplyManualScaleAndMove();
@@ -153,20 +152,6 @@ void VideoOutWindow::MoveResize(void)
needrepaint = true;
}
/** \fn VideoOutWindow::Apply1080Fixup(void)
* \brief If the video is reported as 1088 lines, apply a vertical
* scaling operation to bring it effectively to 1080 lines.
*/
void VideoOutWindow::Apply1080Fixup(void)
{
if (video_dim.height() == 1088)
{
int height = display_video_rect.height();
display_video_rect.setHeight(height * 1088.0 / 1084 + 0.5);
}
}
/** \fn VideoOutWindow::ApplyDBScaleAndMove(void)
* \brief Apply scales and moves for "Overscan" and "Underscan" DB settings.
*
@@ -107,7 +107,6 @@ class VideoOutWindow
bool do_pixel_adj = true) const;
protected:
void Apply1080Fixup(void);
void ApplyDBScaleAndMove(void);
void ApplyManualScaleAndMove(void);
void ApplyLetterboxing(void);

0 comments on commit c0bc928

Please sign in to comment.