Merge r3152-r3153 (FFMS2 video provider YV12 fix) into the 2.1.8 branch.

Originally committed to SVN as r3173.
This commit is contained in:
Karl Blomster 2009-07-19 18:41:03 +00:00
parent a5aaea0a06
commit 08e93a8d7f
1 changed files with 10 additions and 6 deletions

View File

@ -268,10 +268,10 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType)
DstFormat = FFMS_GetPixFmt("bgr24");
DstFrame.format = FORMAT_RGB24;
} else if (FormatType & FORMAT_YV12) {
DstFormat = FFMS_GetPixFmt("yuv420p"); // may or may not work
DstFormat = FFMS_GetPixFmt("yuv420p");
DstFrame.format = FORMAT_YV12;
} else if (FormatType & FORMAT_YUY2) {
DstFormat = FFMS_GetPixFmt("yuyv422");
DstFormat = FFMS_GetPixFmt("yuyv422"); // may or may not work
DstFrame.format = FORMAT_YUY2;
} else
throw _T("FFmpegSource video provider: upstream provider requested unknown or unsupported pixel format");
@ -308,10 +308,14 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType)
DstFrame.pitch[i] = SrcFrame->Linesize[i];
DstFrame.Allocate();
// copy data to destination, skipping planes with no data in them
for (int j = 0; j < 4; j++) {
if (SrcFrame->Linesize[j] > 0)
memcpy(DstFrame.data[j], SrcFrame->Data[j], DstFrame.pitch[j] * DstFrame.h);
// copy data to destination
memcpy(DstFrame.data[0], SrcFrame->Data[0], DstFrame.pitch[0] * DstFrame.h);
// if we're dealing with YUV formats we need to copy the U and V planes as well
if (DstFrame.format == FORMAT_YUY2 || DstFrame.format == FORMAT_YV12) {
// YV12 has half the vertical U/V resolution too because of the subsampling
int UVHeight = DstFrame.format == FORMAT_YUY2 ? DstFrame.h : DstFrame.h / 2;
memcpy(DstFrame.data[1], SrcFrame->Data[1], DstFrame.pitch[1] * UVHeight);
memcpy(DstFrame.data[2], SrcFrame->Data[2], DstFrame.pitch[2] * UVHeight);
}
return DstFrame;