-
Notifications
You must be signed in to change notification settings - Fork 210
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
Support changing frame size during encoding #1069
base: main
Are you sure you want to change the base?
Conversation
Yuan: I just merged my cleanup pull request #1070. Please rebase this pull request and then I will take a look at the crash. Thanks. |
b46dfa9
to
054b138
Compare
054b138
to
864c34e
Compare
I tried to run asan and here is the report:
The function in question seems related to ssim, but if I set
|
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.
Yuan: I reviewed everything except the avifRWStreamWrite parts of src/write.c and the decoder part of the new test in avifchangesettingtest.cc. I believe your changes to src/codec_aom.c. So this looks like a libaom bug that certain arrays are allocated to the size of the initial values of cfg.g_w
and cfg.g_h
.
src/write.c
Outdated
lastEncoder->minQuantizer = encoder->minQuantizer; | ||
lastEncoder->maxQuantizer = encoder->maxQuantizer; | ||
lastEncoder->minQuantizerAlpha = encoder->minQuantizerAlpha; | ||
lastEncoder->maxQuantizerAlpha = encoder->maxQuantizerAlpha; | ||
lastEncoder->tileRowsLog2 = encoder->tileRowsLog2; | ||
lastEncoder->tileColsLog2 = encoder->tileColsLog2; | ||
lastEncoder->speed = encoder->speed; |
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.
Delete this. This line has been moved to line 334.
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.
Done
@@ -1046,6 +1046,9 @@ struct avifCodecSpecificOptions; | |||
// image in less bytes. AVIF_SPEED_DEFAULT means "Leave the AV1 codec to its default speed settings"./ | |||
// If avifEncoder uses rav1e, the speed value is directly passed through (0-10). If libaom is used, | |||
// a combination of settings are tweaked to simulate this speed range. | |||
// * Width and height: width and height of encoded image. Default value 0 means infer from first frame. | |||
// For grid image, this is the size of one cell. Value must not be smaller than the largest frame | |||
// to be encoded. |
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 need to think about what this value means for grid images.
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.
This is the easiest choice: encoder->width
and encoder-height
overrides image->width
and image->height
, if present.
Alternatively this can be defined as size of the whole grid, and we verify and compute size of each cell internally.
src/write.c
Outdated
imageWidth = imageMetadata->width * item->gridCols; | ||
imageHeight = imageMetadata->height * item->gridRows; | ||
imageWidth = imageWidth * item->gridCols; | ||
imageHeight = imageHeight * item->gridRows; |
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.
Optional: Should we use the *=
notation?
imageWidth *= item->gridCols;
imageHeight *= item->gridRows;
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.
This looks better. Done.
Yuan: Please test this libaom patch. It is likely to be incomplete (e.g., the VMAF and BUTTERAUGLI code may also need the same changes).
|
I discussed this issue with my colleague Marco Paniconi, who works on real-time encoding and SVC in libaom. Marco told me that they don't use Although AVIF allows the images in an image sequence to have different sizes, the libavif encoder does not need to support that. (The libavif decoder supports that.) |
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.
Please test this libaom patch
Thaks for the patch. I confirm that after patch libaom encodes correctly.
let libaom downscale the frames internally for certain spatial layers
Actually I'm planning to support both. Use libaom internal scaler is more convenient for basic usage with only one input image, but if user wants more flexibility (e.g. using small blurred "thumbnail" as first layer) input image of different size can be both more efficient and convenient.
Earlier this year I reported two bugs in libaom's internal scaler. I see aomedia:3210 is fixed by a recent commit https://aomedia-review.googlesource.com/c/aom/+/161961. For aomedia:3203 I have an old CL, but I can't figure out how to update it because it's targeting master branch, so I created a new one instead.
@@ -1046,6 +1046,9 @@ struct avifCodecSpecificOptions; | |||
// image in less bytes. AVIF_SPEED_DEFAULT means "Leave the AV1 codec to its default speed settings"./ | |||
// If avifEncoder uses rav1e, the speed value is directly passed through (0-10). If libaom is used, | |||
// a combination of settings are tweaked to simulate this speed range. | |||
// * Width and height: width and height of encoded image. Default value 0 means infer from first frame. | |||
// For grid image, this is the size of one cell. Value must not be smaller than the largest frame | |||
// to be encoded. |
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.
This is the easiest choice: encoder->width
and encoder-height
overrides image->width
and image->height
, if present.
Alternatively this can be defined as size of the whole grid, and we verify and compute size of each cell internally.
# Conflicts: # include/avif/avif.h # src/write.c
3eeb8c1
to
4011553
Compare
4011553
to
d7fe311
Compare
With the latest tip of libaom all added test cases passes.
AVIF use case is different here: we want to use different images for each layer (like the low resolution blurry preview example I mentioned) - instead of sending the same frame many times to encode scalable video. So the SVC approach puts user into an awkward situation: they need to upscale the first layer to match frame size, and then libaom downscales it back. This is inefficient, and upscale-downscale roundtrip can be lossy. |
7a7bbf1
to
4761eb5
Compare
4761eb5
to
5e208db
Compare
# Conflicts: # include/avif/avif.h # src/codec_aom.c # src/codec_rav1e.c # src/write.c
Based on the libavif avifchangedimensiontest AOMDecreasing/ChangeDimensionTest.EncodeDecode/0 in AOMediaCodec/libavif#1069 by Yuan Tong. Test: test_libaom --gtest_filter=*DimensionDecreasing \ --gtest_also_run_disabled_tests Bug: aomedia:3348 Change-Id: I8be3c092234f99402c02aa03340c916f629ce0f2
Based on the libavif avifchangedimensiontest AOMDecreasing/ChangeDimensionTest.EncodeDecode/0 in AOMediaCodec/libavif#1069 by Yuan Tong. Test: test_libaom --gtest_filter=*DimensionDecreasing \ --gtest_also_run_disabled_tests Bug: aomedia:3348 Change-Id: I79aea87012cc3bea43d565911ac88816c860e737
Based on the libavif avifchangedimensiontest AOMDecreasing/ChangeDimensionTest.EncodeDecode/0 in AOMediaCodec/libavif#1069 by Yuan Tong. Test: test_libaom --gtest_filter=*DimensionDecreasing \ --gtest_also_run_disabled_tests Bug: aomedia:3348 Change-Id: I79aea87012cc3bea43d565911ac88816c860e737
This is the second part for #761.
@wantehchang, I wrote a simple test
ChangeSettingTest.ChangeDimension
that encodes a 256x256 frame following by a 512x512 frame, with seq header dimension set to 512x512, but it crashes in theaom_codec_destroy
call. Could you take a look if there's something wrong in my usage, or it's a bug in libaom?