Skip to content

Commit

Permalink
Add option parsing for rav1e and SVT-AV1. (AOMediaCodec#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud authored Apr 22, 2024
1 parent 4acbd23 commit ca071c4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/codec_rav1e.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ static avifResult rav1eCodecEncodeImage(avifCodec * codec,
RaFrame * rav1eFrame = NULL;

if (!codec->internal->rav1eContext) {
if (codec->csOptions->count > 0) {
// None are currently supported!
return AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;
}

const avifBool supports400 = rav1eSupports400();
RaPixelRange rav1eRange;
if (alpha) {
Expand Down Expand Up @@ -182,6 +177,14 @@ static avifResult rav1eCodecEncodeImage(avifCodec * codec,
goto cleanup;
}
}
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
if (rav1e_config_parse(rav1eConfig, entry->key, entry->value) < 0) {
avifDiagnosticsPrintf(codec->diag, "Invalid value for %s: %s.", entry->key, entry->value);
result = AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;
goto cleanup;
}
}

rav1e_config_set_color_description(rav1eConfig,
(RaMatrixCoefficients)image->matrixCoefficients,
Expand Down
17 changes: 17 additions & 0 deletions src/codec_svt.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ static avifResult svtCodecEncodeImage(avifCodec * codec,
svt_config->intra_period_length = encoder->keyframeInterval - 1;
}

#if SVT_AV1_CHECK_VERSION(0, 9, 1)
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
if (svt_av1_enc_parse_parameter(svt_config, entry->key, entry->value) < 0) {
avifDiagnosticsPrintf(codec->diag, "Invalid value for %s: %s.", entry->key, entry->value);
result = AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;
goto cleanup;
}
}
#else
if (codec->csOptions->count > 0) {
avifDiagnosticsPrintf(codec->diag, "SVT-AV1 does not support setting options");
result = AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;
goto cleanup;
}
#endif

res = svt_av1_enc_set_parameter(codec->internal->svt_encoder, svt_config);
if (res == EB_ErrorBadParameter) {
goto cleanup;
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ cleanup() {
trap cleanup EXIT

pushd ${TMP_DIR}
# Test options.
echo "Testing options"
for pair in aom,end-usage,cbr avm,end-usage,cbr rav1e,tiles,1 svt,film-grain,0; do
IFS=','; set -- $pair
if "${AVIFENC}" --help | grep $1' \['; then
"${AVIFENC}" -s 10 -q 85 -c $1 -a foo=1 "${INPUT_Y4M}" "${ENCODED_FILE}" > "${OUT_MSG}" && exit 1
"${AVIFENC}" -s 10 -q 85 -c $1 -a $2=$3 "${INPUT_Y4M}" "${ENCODED_FILE}" > "${OUT_MSG}"
fi
done

# Lossy test. The decoded pixels should be different from the original image.
echo "Testing basic lossy"
"${AVIFENC}" -s 8 "${INPUT_Y4M}" -o "${ENCODED_FILE}"
Expand Down

0 comments on commit ca071c4

Please sign in to comment.