[x265] [PATCH 2 of 2] y4m: support variable bit depth via CXXXpDD Y4MPEG header; ie: C420p10
Steve Borho
steve at borho.org
Mon May 5 07:26:06 CEST 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1399267370 18000
# Mon May 05 00:22:50 2014 -0500
# Node ID 8bc8ad1a493c2ed4c095792f122c31d4c714a335
# Parent ec3041c034f3c3be4defd8c88e4f844c96ad8987
y4m: support variable bit depth via CXXXpDD Y4MPEG header; ie: C420p10
ffmpeg's support for this is non-standard, so you must use -strict -1, aka:
ffmpeg -i vid.avi -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | ./x265 - --y4m o.hevc
diff -r ec3041c034f3 -r 8bc8ad1a493c source/input/y4m.cpp
--- a/source/input/y4m.cpp Sun May 04 23:53:30 2014 -0500
+++ b/source/input/y4m.cpp Mon May 05 00:22:50 2014 -0500
@@ -60,6 +60,7 @@
height = info.height;
rateNum = info.fpsNum;
rateDenom = info.fpsDenom;
+ depth = info.depth;
ifs = NULL;
if (!strcmp(info.filename, "-"))
@@ -96,14 +97,15 @@
info.fpsNum = rateNum;
info.fpsDenom = rateDenom;
info.csp = colorSpace;
- info.depth = 8;
+ info.depth = depth;
info.frameCount = -1;
size_t frameSize = strlen(header) + 1;
+ size_t bytesPerPixel = depth > 8 ? 2 : 1;
for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
{
frameSize += (size_t)((width >> x265_cli_csps[colorSpace].width[i]) *
- (height >> x265_cli_csps[colorSpace].height[i]));
+ (height >> x265_cli_csps[colorSpace].height[i])) * bytesPerPixel;
}
/* try to estimate frame count, if this is not stdin */
@@ -157,18 +159,19 @@
{
for (int j = 0; j < x265_cli_csps[colorSpace].planes; j++)
{
- delete[] plane[i][j];
+ x265_free(plane[i][j]);
}
}
}
void Y4MInput::pictureAlloc(int queueindex)
{
+ size_t bytesPerPixel = depth > 8 ? 2 : 1;
for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
{
plane_stride[i] = (uint32_t)(width >> x265_cli_csps[colorSpace].width[i]);
- plane_size[i] = (uint32_t)(plane_stride[i] * (height >> x265_cli_csps[colorSpace].height[i]));
- plane[queueindex][i] = new char[plane_size[i]];
+ plane_size[i] = (uint32_t)(plane_stride[i] * (height >> x265_cli_csps[colorSpace].height[i])) * bytesPerPixel;
+ plane[queueindex][i] = X265_MALLOC(char, plane_size[i]);
if (!plane[queueindex][i])
{
x265_log(NULL, X265_LOG_ERROR, "y4m: buffer allocation failure, aborting");
@@ -317,14 +320,30 @@
{
c = ifs->get();
- if (c == ' ' || c == '\n')
+ if (c == 'p')
+ {
+ // C420p16
+ depth = 0;
+ while (!ifs->eof())
+ {
+ c = ifs->get();
+ if (c == ' ' || c == '\n')
+ break;
+ else
+ depth = depth * 10 + (c - '0');
+ }
+ break;
+ }
+ else if (c == ' ' || c == '\n')
{
break;
}
- else
+ else if (c <= '9' && c >= '0')
{
csp = csp * 10 + (c - '0');
}
+ else
+ break;
}
colorSpace = (csp == 444) ? X265_CSP_I444 : (csp == 422) ? X265_CSP_I422 : X265_CSP_I420;
@@ -406,7 +425,7 @@
if (!frameStat[curHead])
return false;
- pic.bitDepth = 8;
+ pic.bitDepth = depth;
pic.colorSpace = colorSpace;
for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
{
diff -r ec3041c034f3 -r 8bc8ad1a493c source/input/y4m.h
--- a/source/input/y4m.h Sun May 04 23:53:30 2014 -0500
+++ b/source/input/y4m.h Mon May 05 00:22:50 2014 -0500
@@ -45,6 +45,8 @@
uint32_t sarHeight;
+ int depth;
+
int width;
int height;
More information about the x265-devel
mailing list