-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat avifenc --stdin as regular file input arg #2574
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/bin/bash | ||
# Copyright 2025 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
source $(dirname "$0")/cmd_test_common.sh | ||
|
||
# Input file paths. | ||
INPUT_Y4M_STILL="${TESTDATA_DIR}/kodim03_yuv420_8bpc.y4m" | ||
INPUT_Y4M_ANIMATED="${TESTDATA_DIR}/webp_logo_animated.y4m" | ||
# Output file names. | ||
ENCODED_FILE_REGULAR="avif_test_cmd_stdin_encoded.avif" | ||
ENCODED_FILE_STDIN="avif_test_cmd_stdin_encoded_with_stdin.avif" | ||
|
||
# Cleanup | ||
cleanup() { | ||
pushd ${TMP_DIR} | ||
rm -f -- "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
popd | ||
} | ||
trap cleanup EXIT | ||
|
||
strip_header_if() { | ||
FILE="$1" | ||
STRIP_HEADER="$2" | ||
|
||
if ${STRIP_HEADER}; then | ||
# The following does not work on all platforms: | ||
# grep --text mdat "${FILE}" | ||
# awk -b -v RS='mdat' '{print length($0); exit}' "${FILE}" | ||
# Hence the hardcoded variable below. | ||
MDAT_OFFSET=1061 | ||
FILE_CONTENTS_AFTER_HEADER=$(tail -c +${MDAT_OFFSET} < "${FILE}") | ||
echo "${FILE_CONTENTS_AFTER_HEADER}" > "${FILE}" | ||
fi | ||
} | ||
|
||
test_stdin() { | ||
INPUT_Y4M="$1" | ||
STRIP_HEADER="$2" | ||
|
||
# Make sure that --stdin can be replaced with a file path and that it leads to | ||
# the same encoded bytes. | ||
|
||
"${AVIFENC}" -s 8 -o "${ENCODED_FILE_REGULAR}" "${INPUT_Y4M}" | ||
"${AVIFENC}" -s 8 -o "${ENCODED_FILE_STDIN}" --stdin < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER} | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
|
||
"${AVIFENC}" -s 9 "${INPUT_Y4M}" -o "${ENCODED_FILE_REGULAR}" | ||
"${AVIFENC}" -s 9 --stdin -o "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER} | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
|
||
"${AVIFENC}" -s 10 "${INPUT_Y4M}" "${ENCODED_FILE_REGULAR}" | ||
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER} | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
"${AVIFENC}" -s 10 "${ENCODED_FILE_STDIN}" --stdin < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
|
||
"${AVIFENC}" -s 10 "${INPUT_Y4M}" -q 90 "${ENCODED_FILE_REGULAR}" | ||
"${AVIFENC}" -s 10 --stdin -q 90 "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER} | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
"${AVIFENC}" -s 10 "${ENCODED_FILE_STDIN}" -q 90 --stdin < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" -q 90 < "${INPUT_Y4M}" | ||
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER} | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" | ||
|
||
# Negative tests. | ||
|
||
# WARNING: Trailing options with update suffix has no effect. Place them before the input you intend to apply to. | ||
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" -q:u 90 < "${INPUT_Y4M}" | ||
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" && exit 1 | ||
|
||
# ERROR: there cannot be any other input if --stdin is specified | ||
"${AVIFENC}" --stdin && exit 1 | ||
"${AVIFENC}" --stdin "${INPUT_Y4M}" "${ENCODED_FILE_STDIN}" && exit 1 | ||
"${AVIFENC}" "${INPUT_Y4M}" --stdin "${ENCODED_FILE_STDIN}" && exit 1 | ||
"${AVIFENC}" "${INPUT_Y4M}" "${ENCODED_FILE_STDIN}" --stdin && exit 1 | ||
|
||
return 0 | ||
} | ||
|
||
pushd ${TMP_DIR} | ||
test_stdin "${INPUT_Y4M_STILL}" false | ||
|
||
# The output of avifenc for animations is not deterministic because of boxes | ||
# such as mvhd and its field creation_time. Strip the whole header to compare | ||
# only the encoded samples. | ||
test_stdin "${INPUT_Y4M_ANIMATED}" true | ||
popd | ||
|
||
exit 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't read the pull request. I have a question: where is the position of this fictitious file path argument?
Here is my expectation:
-o
option, the fictitious input file path argument is right before the output file path argument.-o
option is used, the fictitious input file path argument is at the end of the command line.Is this what you implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now read the pull request. What you implemented is not exactly the same as what I expected in how the options with update suffix (i.e.,
pendingSettings
) are handled. This is perfectly fine because there are several reasonable ways to handle this. Since people's expectations may be different from what is implemented, it would be good to document somewhere how we handle the options with update suffix when--stdin
is specified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes no sense to use
:u
with--stdin
because no other input is allowed. So how:u
behaves with--stdin
does not matter, as long as nothing is silently ignored.I find it simpler to understand and to implement if
--stdin
can just be replaced with/path/to/in.y4m
with identical behavior. I do not think it has to be mentioned in--help
because there is no other input file name allowed, so it does not really matter where--stdin
is.Happy to revisit if needed though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's easier to understand if
--stdin
can be replaced with/path/to/in.y4m
with identical behavior. This simple rule is only mentioned in the changelog. It would be good to document this in the help message.Also, this rule needs to make an exception for the
avifenc out.avif --stdin
case. The exception might be worth documenting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. It does not provide any benefit as long as "No other input is allowed": since there is an ovious single input and a single output, the order of all arguments should not matter. The same behavior as if replaced by a file path is somewhat expected (besides the exception you mentioned), and if it is not the case, it does not really matter because there is a single input and a single output.
So describing that in the help message would just bring confusion in my opinion.