Skip to content

Commit

Permalink
ld-chroma-decoder: Added first/last field/frame line command-line opt…
Browse files Browse the repository at this point in the history
…ions, and padding command-line option.
  • Loading branch information
Ryan Holtz committed Feb 19, 2022
1 parent f40b683 commit 08f32a5
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 59 deletions.
2 changes: 1 addition & 1 deletion tools/ld-analyse/tbcsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TbcSource::TbcSource(QObject *parent) : QObject(parent)
palConfiguration.chromaFilter = PalColour::transform2DFilter;
ntscConfiguration = ntscColour.getConfiguration();
outputConfiguration.pixelFormat = OutputWriter::PixelFormat::RGB48;
outputConfiguration.usePadding = false;
outputConfiguration.paddingAmount = 1;
}

// Public methods -----------------------------------------------------------------------------------------------------
Expand Down
70 changes: 63 additions & 7 deletions tools/ld-chroma-decoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Output in black and white"));
parser.addOption(setBwModeOption);

// Option to select output padding (-pad)
QCommandLineOption outputPaddingOption(QStringList() << "pad" << "output-padding",
QCoreApplication::translate("main", "Pad the output frame to a multiple of this many pixels on both axes (1 means no padding, maximum is 32)"),
QCoreApplication::translate("main", "number"));
parser.addOption(outputPaddingOption);

// Option to select which decoder to use (-f)
QCommandLineOption decoderOption(QStringList() << "f" << "decoder",
QCoreApplication::translate("main", "Decoder to use (pal2d, transform2d, transform3d, ntsc1d, ntsc2d, ntsc3d, ntsc3dnoadapt, mono; default automatic)"),
Expand All @@ -182,10 +188,34 @@ int main(int argc, char *argv[])

// Option to select the number of threads (-t)
QCommandLineOption threadsOption(QStringList() << "t" << "threads",
QCoreApplication::translate("main", "Specify the number of concurrent threads (default number of logical CPUs)"),
QCoreApplication::translate("main", "number"));
QCoreApplication::translate("main", "Specify the number of concurrent threads (default number of logical CPUs)"),
QCoreApplication::translate("main", "number"));
parser.addOption(threadsOption);

// Option to override calculated firstActiveFieldLine in our video parameters (-ffll)
QCommandLineOption firstFieldLineOption(QStringList() << "ffll" << "first_active_field_line",
QCoreApplication::translate("main", "The first visible line of a field. Range 1-259 for NTSC (default: 20), 2-308 for PAL (default: 22)"),
QCoreApplication::translate("main", "number"));
parser.addOption(firstFieldLineOption);

// Option to override calculated lastActiveFieldLine in our video parameters (-lfll)
QCommandLineOption lastFieldLineOption(QStringList() << "lfll" << "last_active_field_line",
QCoreApplication::translate("main", "The last visible line of a field. Range 1-259 for NTSC (default: 259), 2-308 for PAL (default: 308)"),
QCoreApplication::translate("main", "number"));
parser.addOption(lastFieldLineOption);

// Option to override calculated firstActiveFrameLine in our video parameters (-ffrl)
QCommandLineOption firstFrameLineOption(QStringList() << "ffrl" << "first_active_frame_line",
QCoreApplication::translate("main", "The first visible line of a frame. Range 1-525 for NTSC (default: 40), 1-620 for PAL (default: 44)"),
QCoreApplication::translate("main", "number"));
parser.addOption(firstFrameLineOption);

// Option to override calculated lastActiveFieldLine in our video parameters (-lfll)
QCommandLineOption lastFrameLineOption(QStringList() << "lfrl" << "last_active_frame_line",
QCoreApplication::translate("main", "The last visible line of a frame. Range 1-525 for NTSC (default: 525), 1-620 for PAL (default: 620)"),
QCoreApplication::translate("main", "number"));
parser.addOption(lastFrameLineOption);

// -- NTSC decoder options --

// Option to overlay the adaptive filter map
Expand Down Expand Up @@ -247,7 +277,7 @@ int main(int argc, char *argv[])

// Positional argument to specify output video file
parser.addPositionalArgument("output", QCoreApplication::translate("main", "Specify output file (omit or - for piped output)"));

// Process the command line options and arguments given by the user
parser.process(a);

Expand Down Expand Up @@ -317,7 +347,7 @@ int main(int argc, char *argv[])
return -1;
}
}

if (parser.isSet(chromaGainOption)) {
const double value = parser.value(chromaGainOption).toDouble();
palConfig.chromaGain = value;
Expand Down Expand Up @@ -395,10 +425,26 @@ int main(int argc, char *argv[])
}
}


if (parser.isSet(ntscPhaseComp)) {
combConfig.phaseCompensation = true;
}

LdDecodeMetaData::LineParameters lineParameters;
if (parser.isSet(firstFieldLineOption)) {
lineParameters.firstActiveFieldLine = parser.value(firstFieldLineOption).toInt();
}

if (parser.isSet(lastFieldLineOption)) {
lineParameters.lastActiveFieldLine = parser.value(lastFieldLineOption).toInt();
}

if (parser.isSet(firstFrameLineOption)) {
lineParameters.firstActiveFrameLine = parser.value(firstFrameLineOption).toInt();
}

if (parser.isSet(lastFrameLineOption)) {
lineParameters.lastActiveFrameLine = parser.value(lastFrameLineOption).toInt();
}

// Work out the metadata filename
QString inputJsonFileName = inputFileName + ".json";
Expand All @@ -412,7 +458,9 @@ int main(int argc, char *argv[])
qInfo() << "Unable to open ld-decode metadata file";
return -1;
}


metaData.processLineParameters(lineParameters);

// Reverse field order if required
if (parser.isSet(setReverseOption)) {
qInfo() << "Expected field order is reversed to second field/first field";
Expand Down Expand Up @@ -440,7 +488,7 @@ int main(int argc, char *argv[])
qCritical() << "Can only show FFTs with the transform2d/transform3d decoders";
return -1;
}

// Select the decoder
QScopedPointer<Decoder> decoder;
if (decoderName == "pal2d") {
Expand Down Expand Up @@ -500,6 +548,14 @@ int main(int argc, char *argv[])
return -1;
}

if (parser.isSet(outputPaddingOption)) {
outputConfig.paddingAmount = parser.value(outputPaddingOption).toInt();
if (outputConfig.paddingAmount < 1 || outputConfig.paddingAmount > 32) {
qInfo() << "Invalid value" << outputConfig.paddingAmount << "specified for padding amount, defaulting to 8.";
outputConfig.paddingAmount = 8;
}
}

// Perform the processing
DecoderPool decoderPool(*decoder, inputFileName, metaData, outputConfig, outputFileName, startFrame, length, maxThreads);
if (!decoderPool.process()) {
Expand Down
14 changes: 8 additions & 6 deletions tools/ld-chroma-decoder/outputwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ void OutputWriter::updateConfiguration(LdDecodeMetaData::VideoParameters &_video
activeHeight = videoParameters.lastActiveFrameLine - videoParameters.firstActiveFrameLine;
outputHeight = activeHeight;

if (config.usePadding) {
// Both width and height should be divisible by 8, as video codecs expect this.
// Expand horizontal active region so the width is divisible by 8.
if (config.paddingAmount > 1) {
// Some video codecs require the width and height of a video to be divisible by
// a given number of samples on each axis.

// Expand horizontal active region so the width is divisible by the specified padding factor.
while (true) {
activeWidth = videoParameters.activeVideoEnd - videoParameters.activeVideoStart;
if ((activeWidth % 8) == 0) {
if ((activeWidth % config.paddingAmount) == 0) {
break;
}

Expand All @@ -79,10 +81,10 @@ void OutputWriter::updateConfiguration(LdDecodeMetaData::VideoParameters &_video
}
}

// Insert empty padding lines so the height is divisible by 8
// Insert empty padding lines so the height is divisible by by the specified padding factor.
while (true) {
outputHeight = topPadLines + activeHeight + bottomPadLines;
if ((outputHeight % 8) == 0) {
if ((outputHeight % config.paddingAmount) == 0) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/ld-chroma-decoder/outputwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OutputWriter {

// Output settings
struct Configuration {
bool usePadding = true;
qint32 paddingAmount = 8;
PixelFormat pixelFormat = RGB48;
bool outputY4m = false;
};
Expand Down
Loading

0 comments on commit 08f32a5

Please sign in to comment.