Skip to content

Commit d6345d3

Browse files
committed
Treat avifenc --stdin as regular file input arg
Consider --stdin to be a positional argument as if it was the name of the y4m file path containing the y4m standard input contents.
1 parent 49729e4 commit d6345d3

7 files changed

+323
-93
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The changes are relative to the previous release, unless the baseline is specifi
5757
avifCropRectFromCleanApertureBox() and avifCleanApertureBoxFromCropRect().
5858
* Ignore descriptive properties associated after transformative ones.
5959
* Reject non-essential transformative properties.
60+
* Treat avifenc --stdin as a regular positional file path argument.
6061

6162
## [1.1.1] - 2024-07-30
6263

apps/avifenc.c

+167-92
Large diffs are not rendered by default.

tests/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ if(AVIF_BUILD_APPS)
259259
add_test(NAME test_cmd_progressive COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test_cmd_progressive.sh ${CMAKE_BINARY_DIR}
260260
${CMAKE_CURRENT_SOURCE_DIR}/data
261261
)
262+
add_test(NAME test_cmd_stdin COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test_cmd_stdin.sh ${CMAKE_BINARY_DIR}
263+
${CMAKE_CURRENT_SOURCE_DIR}/data
264+
)
262265
add_test(NAME test_cmd_targetsize COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test_cmd_targetsize.sh ${CMAKE_BINARY_DIR}
263266
${CMAKE_CURRENT_SOURCE_DIR}/data
264267
)

tests/data/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,18 @@ License: [same as libavif](https://github.com/AOMediaCodec/libavif/blob/main/LIC
839839

840840
Source: Random frames generated with libavif.
841841

842+
### File [webp_logo_animated.y4m](webp_logo_animated.y4m)
843+
844+
![](webp_logo_animated.y4m)
845+
846+
License: [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/),
847+
[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
848+
849+
Attribution: Google LLC
850+
851+
Source: https://en.wikipedia.org/wiki/File:WebPLogo.svg with text stripped and
852+
animated effects.
853+
842854
# Other Test Files
843855

844856
### File [sRGB2014.icc](sRGB2014.icc)

tests/data/webp_logo_animated.y4m

+21
Large diffs are not rendered by default.

tests/test_cmd.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ OUT_MSG="avif_test_cmd_out_msg.txt"
3737
# Cleanup
3838
cleanup() {
3939
pushd ${TMP_DIR}
40-
rm -f -- "${ENCODED_FILE}" "${ENCODED_FILE_WITH_DASH}" "${DECODED_FILE}" "${OUT_MSG}"
40+
rm -f -- "${ENCODED_FILE}" "${ENCODED_UTF8_FILE}" "${ENCODED_FILE_REFERENCE}" \
41+
"${ENCODED_FILE_WITH_DASH}" "${DECODED_FILE}" "${DECODED_UTF8_FILE}" \
42+
"${OUT_MSG}"
4143
popd
4244
}
4345
trap cleanup EXIT

tests/test_cmd_stdin.sh

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
source $(dirname "$0")/cmd_test_common.sh
17+
18+
# Input file paths.
19+
INPUT_Y4M_STILL="${TESTDATA_DIR}/kodim03_yuv420_8bpc.y4m"
20+
INPUT_Y4M_ANIMATED="${TESTDATA_DIR}/webp_logo_animated.y4m"
21+
# Output file names.
22+
ENCODED_FILE_REGULAR="avif_test_cmd_stdin_encoded.avif"
23+
ENCODED_FILE_STDIN="avif_test_cmd_stdin_encoded_with_stdin.avif"
24+
25+
# Cleanup
26+
cleanup() {
27+
pushd ${TMP_DIR}
28+
rm -f -- "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
29+
popd
30+
}
31+
trap cleanup EXIT
32+
33+
strip_header_if() {
34+
FILE="$1"
35+
STRIP_HEADER="$2"
36+
37+
if ${STRIP_HEADER}; then
38+
grep --help
39+
grep mdat "${FILE}"
40+
grep --text mdat "${FILE}"
41+
grep --text --max-count=1 mdat "${FILE}"
42+
grep --text --max-count=1 --byte-offset mdat "${FILE}"
43+
grep --text --max-count=1 --byte-offset --only-matching mdat "${FILE}"
44+
grep --text --max-count=1 --byte-offset --only-matching --binary mdat "${FILE}"
45+
grep -o -b -a mdat "${FILE}"
46+
MDAT_OFFSET=$(grep -o -b -a mdat "${FILE}" | cut -f1 -d:)
47+
FILE_CONTENTS_AFTER_HEADER=$(tail -c +${MDAT_OFFSET} < "${FILE}")
48+
echo "${FILE_CONTENTS_AFTER_HEADER}" > "${FILE}"
49+
fi
50+
}
51+
52+
test_stdin() {
53+
INPUT_Y4M="$1"
54+
STRIP_HEADER="$2"
55+
56+
# Make sure that --stdin can be replaced with a file path and that it leads to
57+
# the same encoded bytes.
58+
59+
"${AVIFENC}" -s 8 -o "${ENCODED_FILE_REGULAR}" "${INPUT_Y4M}"
60+
"${AVIFENC}" -s 8 -o "${ENCODED_FILE_STDIN}" --stdin < "${INPUT_Y4M}"
61+
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER}
62+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
63+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
64+
65+
"${AVIFENC}" -s 9 "${INPUT_Y4M}" -o "${ENCODED_FILE_REGULAR}"
66+
"${AVIFENC}" -s 9 --stdin -o "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}"
67+
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER}
68+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
69+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
70+
71+
"${AVIFENC}" -s 10 "${INPUT_Y4M}" "${ENCODED_FILE_REGULAR}"
72+
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}"
73+
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER}
74+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
75+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
76+
"${AVIFENC}" -s 10 "${ENCODED_FILE_STDIN}" --stdin < "${INPUT_Y4M}"
77+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
78+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
79+
80+
"${AVIFENC}" -s 10 "${INPUT_Y4M}" -q 90 "${ENCODED_FILE_REGULAR}"
81+
"${AVIFENC}" -s 10 --stdin -q 90 "${ENCODED_FILE_STDIN}" < "${INPUT_Y4M}"
82+
strip_header_if "${ENCODED_FILE_REGULAR}" ${STRIP_HEADER}
83+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
84+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
85+
"${AVIFENC}" -s 10 "${ENCODED_FILE_STDIN}" -q 90 --stdin < "${INPUT_Y4M}"
86+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
87+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
88+
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" -q 90 < "${INPUT_Y4M}"
89+
strip_header_if "${ENCODED_FILE_STDIN}" ${STRIP_HEADER}
90+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}"
91+
92+
# Negative tests.
93+
94+
# WARNING: Trailing options with update suffix has no effect. Place them before the input you intend to apply to.
95+
"${AVIFENC}" -s 10 --stdin "${ENCODED_FILE_STDIN}" -q:u 90 < "${INPUT_Y4M}"
96+
cmp --silent "${ENCODED_FILE_REGULAR}" "${ENCODED_FILE_STDIN}" && exit 1
97+
98+
# ERROR: there cannot be any other input if --stdin is specified
99+
"${AVIFENC}" --stdin && exit 1
100+
"${AVIFENC}" --stdin "${ENCODED_FILE_STDIN}" "${ENCODED_FILE_STDIN}" && exit 1
101+
"${AVIFENC}" "${ENCODED_FILE_STDIN}" --stdin "${ENCODED_FILE_STDIN}" && exit 1
102+
"${AVIFENC}" "${ENCODED_FILE_STDIN}" "${ENCODED_FILE_STDIN}" --stdin && exit 1
103+
104+
return 0
105+
}
106+
107+
pushd ${TMP_DIR}
108+
test_stdin "${INPUT_Y4M_STILL}" false
109+
110+
# The output of avifenc for animations is not deterministic because of boxes
111+
# such as mvhd and its field creation_time. Strip the whole header to compare
112+
# only the encoded samples.
113+
test_stdin "${INPUT_Y4M_ANIMATED}" true
114+
popd
115+
116+
exit 0

0 commit comments

Comments
 (0)