Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Add support for gray16 and export gray12-16 to py #522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/PyNvCodec/src/PyNvCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ PYBIND11_MODULE(_PyNvCodec, m)
.value("YUV422", Pixel_Format::YUV422)
.value("P10", Pixel_Format::P10)
.value("P12", Pixel_Format::P12)
.value("GRAY12", Pixel_Format::GRAY12)
.value("GRAY16", Pixel_Format::GRAY16)
.export_values();

py::enum_<ColorSpace>(m, "ColorSpace")
Expand Down
1 change: 1 addition & 0 deletions src/TC/inc/MemoryInterfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum Pixel_Format {
YUV420_10bit = 15,
NV12_Planar = 16,
GRAY12 = 17,
GRAY16 = 18,
};

enum ColorSpace {
Expand Down
31 changes: 31 additions & 0 deletions src/TC/src/FfmpegSwDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ struct FfmpegDecodeFrame_Impl {

return true;
}

bool SaveGRAY16LE(AVFrame* pframe) {
size_t size = frame->width * frame->height * 2;

if (!dec_frame) {
dec_frame = Buffer::MakeOwnMem(size);
} else if (size != dec_frame->GetRawMemSize()) {
delete dec_frame;
dec_frame = Buffer::MakeOwnMem(size);
}

auto plane = 0U;
auto* dst = dec_frame->GetDataAs<uint8_t>();

auto* src = frame->data[plane];
auto width = frame->width;
auto height = frame->height;

for (int i = 0; i < height; i++) {
memcpy(dst, src, 2*width);
dst += 2*width;
src += frame->linesize[plane];
}

return true;
}

bool SaveYUV444(AVFrame* pframe)
{
Expand Down Expand Up @@ -297,6 +323,8 @@ struct FfmpegDecodeFrame_Impl {
return SaveYUV444(frame);
case AV_PIX_FMT_GRAY12LE:
return SaveGRAY12LE(frame);
case AV_PIX_FMT_GRAY16LE:
return SaveGRAY16LE(frame);
default:
cerr << __FUNCTION__ << ": unsupported pixel format: " << frame->format
<< endl;
Expand Down Expand Up @@ -423,6 +451,9 @@ void FfmpegDecodeFrame::GetParams(MuxingParams& params)
case AV_PIX_FMT_GRAY12LE:
params.videoContext.format = GRAY12;
break;
case AV_PIX_FMT_GRAY16LE:
params.videoContext.format = GRAY16;
break;
default:
stringstream ss;
ss << "Unsupported FFmpeg pixel format: "
Expand Down