Skip to content

Commit

Permalink
Added more pixel formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Feb 18, 2024
1 parent 8bf521a commit 16a48ef
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions lib/tlIO/FFmpegWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,38 @@ namespace tl
AVPixelFormat parsePixelFormat(const std::string& s)
{
AVPixelFormat o = AV_PIX_FMT_YUV420P;
if (s == "YUV422P")

if (s == "YUV420P")
o = AV_PIX_FMT_YUV420P;
else if (s == "YUVA420P")
o = AV_PIX_FMT_YUVA420P;
else if (s == "YUV422P")
o = AV_PIX_FMT_YUV422P;
else if (s == "YUV444P")
o = AV_PIX_FMT_YUV444P;

else if (s == "YUV420P10LE")
o = AV_PIX_FMT_YUV420P10LE;
else if (s == "YUV422P10LE")
o = AV_PIX_FMT_YUV422P10LE;
else if (s == "YUV444P10LE")
o = AV_PIX_FMT_YUV444P10LE;
else if (s == "RGB")
o = AV_PIX_FMT_RGB24;
else if (s == "YUV420P10LE")
o = AV_PIX_FMT_YUV420P10LE;
else if (s == "YUV422P10LE")
o = AV_PIX_FMT_YUV422P10LE;
else if (s == "YUV444P10LE")
o = AV_PIX_FMT_YUV444P10LE;

else if (s == "GBRP")
o = AV_PIX_FMT_GBRP;
else if (s == "GBRP10LE")
o = AV_PIX_FMT_GBRP10LE;
else if (s == "GBRP")
o = AV_PIX_FMT_GBRP12LE;
else
throw std::runtime_error(
string::Format("Unknown pixel format {0}").arg(s));
// else if (s == "RGB10")
// return AV_PIX_FMT_RGB10;
// else if (s == "RGB12")
Expand Down Expand Up @@ -791,7 +811,6 @@ namespace tl
const auto rational = time::toRational(p.speed);
p.avCodecContext->time_base = { rational.second, rational.first };
p.avCodecContext->framerate = { rational.first, rational.second };
p.avCodecContext->profile = avProfile;

p.avCodecContext->color_range = AVCOL_RANGE_MPEG; // Equivalent to -color_range tv
p.avCodecContext->colorspace = AVCOL_SPC_BT709; // Equivalent to -colorspace bt709
Expand All @@ -818,7 +837,26 @@ namespace tl
AVPixelFormat pix_fmt = parsePixelFormat(pixelFormat);
pix_fmt = choosePixelFormat(avCodec, pix_fmt);
p.avCodecContext->pix_fmt = pix_fmt;

if (profile == Profile::H264)
{
switch(pix_fmt)
{
case AV_PIX_FMT_YUV420P10LE:
avProfile = FF_PROFILE_H264_HIGH_10;
break;
case AV_PIX_FMT_YUV422P10LE:
avProfile = FF_PROFILE_H264_HIGH_422;
break;
case AV_PIX_FMT_YUV444P10LE:
avProfile = FF_PROFILE_H264_HIGH_444;
break;
default:
avProfile = FF_PROFILE_H264_HIGH;
}
}

p.avCodecContext->profile = avProfile;
AVDictionary* codecOptions = NULL;

std::string presetFile;
Expand Down Expand Up @@ -939,17 +977,6 @@ namespace tl
throw std::runtime_error(string::Format("{0}: Incompatible pixel type").arg(p.fileName));
break;
}
/*p.swsContext = sws_getContext(
videoInfo.size.w,
videoInfo.size.h,
p.avPixelFormatIn,
videoInfo.size.w,
videoInfo.size.h,
p.avCodecContext->pix_fmt,
swsScaleFlags,
0,
0,
0);*/
p.swsContext = sws_alloc_context();
if (!p.swsContext)
{
Expand Down

0 comments on commit 16a48ef

Please sign in to comment.