399 Commits

Author SHA1 Message Date
samrobinson
60d6654b8d Add H265 as a parameter to SsimMapperTest.
PiperOrigin-RevId: 463452893
2022-08-08 08:13:05 +00:00
leonwind
302a742c94 Rename ContrastProcessorPixelTest and make contexts final
PiperOrigin-RevId: 463450395
2022-08-08 08:12:15 +00:00
samrobinson
4a0b07b4f7 Add an SsimMapperTest, which binary searches for 95% ssim.
This is possible because SSIM increases monotonically with bitrate.

PiperOrigin-RevId: 463434373
2022-08-08 08:11:22 +00:00
huangdarwin
a7a17dc2bb Rename findEncoderWithClosestFormatSupport.
Just a misc nit, since I found the name a bit confusing, and figured
findEncoderWithClosestSupportedFormat might be more descriptive.

PiperOrigin-RevId: 463433646
2022-08-08 08:10:23 +00:00
hschlueter
22822d8e19 Allow FrameProcessor.Factory to be set on Transformer.Builder.
Extract a FrameProcessor.Factory interface from GlEffectsFrameProcessor
and allow it to  be customized using a setter on Transformer.Builder.

PiperOrigin-RevId: 463433438
2022-08-08 08:09:33 +00:00
hschlueter
4adf199398 Replace Size with Pair in effects.
Size requires API 21. Using Pair instead will allow effects to be
used from API 18 during previewing once they are moved out of
transformer.

PiperOrigin-RevId: 463206474
2022-08-08 08:04:20 +00:00
hschlueter
5db7778ca3 Only recreate output EGLSurface when Surface changed.
PiperOrigin-RevId: 463193768
2022-08-08 08:03:28 +00:00
hschlueter
30e5bc9837 Allow stream offset passed to GlEffectsFrameProcessor to change.
This is needed for applying effects to a playlist.

The effects are applied based on the presentation time of the
frame in its corresponding media item and the offset is added
back before encoding.

Each time the offset changes, end of input stream is signalled
to the texture processors. This is needed because the texture
processors can expect monotonically increasing timestamp within
the same input stream but when the offset changes, the timstamps
jump back to 0.

PiperOrigin-RevId: 462714966
2022-08-08 07:59:56 +00:00
ibaker
2deb435625 Annotate methods that always return this with @CanIgnoreReturnValue
It's always safe to ignore the result of these methods, because the
caller already has a reference to the returned value.

PiperOrigin-RevId: 462388947
2022-08-08 07:55:25 +00:00
huangdarwin
2f977eeec9 HDR: Implement HLG EOTF and OETF.
This allows us to use BT.2020 RGB linear for intermediate shaders, which also
allows us to re-enable PeriodicVignetteProcessor, which should work properly in
linear color-spaces.

Manually tested by adding a GlEffectsWrapper, and confirming that HLG HDR editing still looks correct.

PiperOrigin-RevId: 462265821
2022-07-21 12:58:24 +00:00
olly
714edc93be Add ContrastProcessor for contrast adjustments.
PiperOrigin-RevId: 462232813
2022-07-21 12:57:07 +00:00
samrobinson
21016eaadf Don't include case statement if it falls through to default.
PiperOrigin-RevId: 461888238
2022-07-21 12:48:46 +00:00
huangdarwin
87198fe7f8 Only apply a MediaFormat-generated ColorInfo if it's valid.
Otherwise, invalid ColorInfo instances generated using faulty
MediaFormat#getInteger values could cause exceptions.

Confirmed that b/239435670 reproduces without this CL, and does not reproduce
with this CL.

PiperOrigin-RevId: 461862191
2022-07-21 12:46:55 +00:00
huangdarwin
ba9c9bb964 HDR: Use FP16 color representation for texture processors.
* Introduced `useHdr` for `GlEffect#toGlTextureProcessor`, so
  `TextureProcessor` implementations can decide how to handle HDR.
* Creating FP16 color textures for HDR input.

Tested via manual testing, adding a no-op GlEffectWrapper to the transformation to
force use of intermediate textures, adding a linear ramp to the fragment shader,
and trying to ascertain that there's a real reduction in posterization when
switching from 4-bit to 8-bit unsigned bytes, and again from 8-bit unsigned bytes
to 16-bit floating point.

PiperOrigin-RevId: 461613117
2022-07-21 12:42:32 +00:00
huangdarwin
9f7a159bc4 HDR: Throw when unexpected color transfer encountered.
This may happen when a containers' color transfer incorrectly does not match
the video's color transfer.

An example of a file with such a mismatch is the current Transformer demo HDR10
sample file.

Manually tested by confirming that no errors are emitted for SDR and HLG sample
files, and that errors are emitted for our incorrect HDR10 sample file.

PiperOrigin-RevId: 461583532
2022-07-21 12:41:33 +00:00
andrewlewis
604ab7fcda Make minor fixes to HDR handling
- Update profile selection logic to pick an HDR-compatible profile when doing HDR editing on H.264/AVC videos.
- Handle doing the capabilities check for all MIME types that support HDR (not just H.265/HEVC).
- Fix a bug where we would pass an HDR input color format to the encoder when using tone-mapping.
- Tweak how `EncoderWrapper` works so decisions at made at construction time.

Manually tested cases:
- Transformation of an SDR video.
- Transformation of an HDR video to AVC (which triggers fallback/tone-mapping on a device that doesn't support HDR editing for AVC).
- Transformation of an HDR video with HDR editing.

PiperOrigin-RevId: 461572973
2022-07-21 12:38:41 +00:00
samrobinson
b87fa45fea Add additional video files.
These are providing more variety and complexity.

All files are okay to be public.

PiperOrigin-RevId: 460935247
2022-07-15 10:19:56 +00:00
hschlueter
7954eeb3c2 Use COLOR_Format32bitABGR2101010 for HDR encoder configuration.
Also remove VideoEncoderSettings.colorProfile as there are no
concrete use cases for customizing this and it clashes with picking
the color format automatically based on SDR vs. HDR.

PiperOrigin-RevId: 460746987
2022-07-13 17:49:24 +00:00
samrobinson
f903869eb8 Fix assertion error when using high quality targeting API.
Add test that verifies SSIM with API enabled.

#minor-release

PiperOrigin-RevId: 460692420
2022-07-13 17:46:38 +00:00
samrobinson
a88426ae58 Clarify format is supported by encoder.
#cleanup
#minor-release

PiperOrigin-RevId: 460688226
2022-07-13 17:44:37 +00:00
claincly
e56219f1f6 Fix a mis-match in encoder priority.
PiperOrigin-RevId: 460500666
2022-07-13 17:39:16 +00:00
claincly
776c8a5544 Verified encoding performance, removing TODO.
PiperOrigin-RevId: 460459378
2022-07-12 15:15:03 +00:00
hschlueter
66e1229988 Set ColorInfo in decoder configuration format.
Pass the color info and HDR static metadata when configuring the decoder
using MediaFormatUtil.maybeSetColorInfo.

PiperOrigin-RevId: 460424985
2022-07-12 15:13:13 +00:00
hschlueter
a5ff4ef17f HDR: Check whether EXT_YUV_target extension is supported.
This extension is needed for editing HDR input with OpenGL, as the
ExternalTextureProcessor samples raw YUV values from the
external texture for HDR and converts them to RGB itself rather than
relying on the OpenGL driver to do this automatically as for SDR.

PiperOrigin-RevId: 460424154
2022-07-12 15:11:21 +00:00
hschlueter
7dc54efdb9 Merge MatrixTransformationProcessor and ExternalTextureProcessor.
This saves an intermediate texture copy step for use-cases
where matrix transformations are the first or only effects
in the chain.

PiperOrigin-RevId: 460239403
2022-07-12 15:09:22 +00:00
claincly
18f4068c06 Apply priority/operating rate settings for video encoding.
- Added setter to disable this feature.
- Added accompanying tests.
- Plan to run tests on the same set of settings on H265.

PiperOrigin-RevId: 460238673
2022-07-12 15:08:22 +00:00
samrobinson
91f1777741 Move Encoder quality API to VideoEncoderSettings.
Some other minor nits and adjustments to the API logic.

PiperOrigin-RevId: 459490431
2022-07-07 16:48:03 +00:00
huangdarwin
7078ce312d HDR: Remove ColorInfo.SDR constant
The SDR constant also specified a color space and range, in addition to
C.COLOR_TRANSFER_SDR. However, it turns out that SDR videos may use different color
space and range values, so following prior ExoPlayer conventions to have `null`
mean "generic SDR" is preferable here.

PiperOrigin-RevId: 459296746
2022-07-07 16:45:00 +00:00
huangdarwin
ab7747d953 HDR: Throw error if attempting HDR editing under API 31.
HDR editing is not supported under API 31

PiperOrigin-RevId: 459211106
2022-07-07 16:42:21 +00:00
huangdarwin
1869855c90 HDR: Remove unused EGL_GL_COLORSPACE_KHR attribute.
PiperOrigin-RevId: 459106221
2022-07-07 16:39:27 +00:00
samrobinson
7d2eb76019 Implement device based encoder bitrate mapping.
This feature is disabled by default for now.

PiperOrigin-RevId: 458932471
2022-07-04 19:57:36 +00:00
hschlueter
9c8dcb402b Fallback to SDR if encoder doesn't support HDR (HLG only).
If the input is HDR (HLG), check encoder capabilities for HDR support
and request tone-mapping to SDR during decoder configuration otherwise.
Capabilities are only checked for API 31 and above, as HDR editing is
not supported before.

As the encoder capabilities check needs to happen before selecting the
encoder to use (as this may depend on the resolution output by the
effects chain), the EncoderWrapper checks all candidate encoders
for the MIME type for HDR capabilities and only requests fallback to
SDR if none of them support it.

When the actual encoder is selected, the wrapper checks that it matches
one of the encoders is checked capabilities for.

PiperOrigin-RevId: 458511599
2022-07-04 19:55:45 +00:00
huangdarwin
a0870a42be HDR: Configure GL shaders and encoder.
Configure the GL shaders and encoder to take in HDR metadata.

This mostly just consists of passing the Format.colorInfo through
the VideoTranscodingSamplePipeline down to the encoder, rather than passing
the PQ-ness down to the GL step.

Due to b/237674316, this will remove HDR10+ support temporarily to introduce
support for HLG10.

Manually tested to confirm that HLG10 operations that don't affect color display
correctly after this CL with "HDR editing" in the demo checked, and continue to display incorrectly (as before this CL) without the option unchecked.

PiperOrigin-RevId: 458490810
2022-07-04 19:55:02 +00:00
claincly
deea5c927a Fix error in frame rate handling.
The old getString() will throw because FRAME_RATE can only be float or int.

PiperOrigin-RevId: 458481251
2022-07-04 19:54:06 +00:00
claincly
3df4f3eb19 Find only REGULAR_CODECS in EncoderUtil.
We used "ALL_COOECS" previously, and it is not necessary because "ALL_CODECS"
additionally the codecs that support tunneling/secure decoding, which there
is no use case in Transformer.

PiperOrigin-RevId: 458470278
2022-07-04 19:52:23 +00:00
claincly
1f47fa832c Round the frame rate in MediaFormat
Although MediaCodec claims supporting float frame rate, encoder init failed on
API21 Nexus 5. Since it's just a performance hint to the codec, it's OK to
generalize it to other API versions.

PiperOrigin-RevId: 458434650
2022-07-04 19:49:33 +00:00
hschlueter
cd0e5b99de Move DebugViewProvider out of Transformer class.
The GlEffectsFrameProcessor that will be part of the effects module
uses the DebugViewProvider. So it does not make sense for it
to be an inner interface of Transformer.

PiperOrigin-RevId: 458014932
2022-07-04 19:45:23 +00:00
hschlueter
234015cb95 FrameProcessor: Replace SurfaceInfo.Provider with setter.
The FinalMatrixTransformationProcessorWrapper ensures that the
surface is only replaced when it is not being rendered to and vice
versa.

PiperOrigin-RevId: 458007639
2022-07-04 19:44:37 +00:00
hschlueter
87beb273e4 Fix outputHeight pass-through condition.
The outputHeight in the TransformationRequest is the height of
the frame as it would be displayed (i.e., after applying any
rotation specified in the format). So pass-through should only
be used if the requested outputHeight matches the input
format's height after applying the rotation.

PiperOrigin-RevId: 457934867
2022-07-04 19:42:09 +00:00
hschlueter
b7b5f20e59 Allow changing input pixelWidthHeightRatio for GlEffectsFrameProcessor.
pixelWidthHeightRatio is now passed to setInputFrameInfo instead of
the factory.

PiperOrigin-RevId: 457696703
2022-07-04 19:39:42 +00:00
hschlueter
4819b28587 Rename setVideoFrameEffects to setVideoEffects.
PiperOrigin-RevId: 457023382
2022-06-27 10:44:17 +01:00
hschlueter
30c52c58f0 Allow FrameProcessor input surface size changes.
This will be useful for downgrading to a lower resolution during
a slow preview and for processing slide-shows once sequential
multi-asset editing is supported.

PiperOrigin-RevId: 457017255
2022-06-27 10:43:21 +01:00
hschlueter
f3893c146d Extract FrameProcessor interface from GlEffectsFrameProcessor.
PiperOrigin-RevId: 456814150
2022-06-27 10:42:00 +01:00
hschlueter
938d3c2e5b Disable flaky transformer emulator test on API 31.
videoEncoderFormatUnsupported_completesWithError() has recently
been flaky on API 31 emulators on presubmit because a different
exception than the expected exception is thrown.
This disables it on those emulators to reduce testing noise
until the underlying problem is investigated and resolved.

PiperOrigin-RevId: 456765512
2022-06-27 10:41:18 +01:00
hschlueter
709224fb1e Rename FrameProcessorChain to GlEffectsFrameProcessor.
This change is just renaming. There is no functional change intended.
The FrameProcessor interface will be created in a follow-up.

PiperOrigin-RevId: 456741628
2022-06-27 10:39:42 +01:00
samrobinson
352967f656 Add a Builder for DefaultEncoderFactory.
PiperOrigin-RevId: 456728032
2022-06-27 10:39:00 +01:00
hschlueter
69ab79418e Use GlTextureProcessor to avoid redundant copy in MediaPipeProcessor.
After this change GlEffects can use any GlTextureProcessor not just
SingleFrameGlTextureProcessor.
MediaPipeProcessor now implements GlTextureProcessor directly which
allows it to reuse MediaPipe's output texture for its output texture
and avoids an extra copy shader step.

PiperOrigin-RevId: 456530718
2022-06-27 10:37:35 +01:00
hschlueter
555ab97e34 Support chaining async GlTextureProcessors in FrameProcessorChain.
After this change, FrameProcessorChain chains any GlTextureProcessors
instead of only SingleFrameGlTextureProcessors.

The GlTextureProcessors are chained in a bidirectional manner using
ChainingGlTextureProcessorListener to feed input and output related
events forward and release events backwards.

PiperOrigin-RevId: 456478414
2022-06-27 10:36:51 +01:00
huangdarwin
f5d8800d51 FrameProcessor: Use factories instead of a builder for Presentation.
PiperOrigin-RevId: 456064021
2022-06-27 10:34:29 +01:00
hschlueter
981baae709 Implement chaining GlTextureProcessor.Listener.
In follow-ups the FrameProcessorChain will set an instance of this
listener for each GlTextureProcessor to chain it with its previous
and next GlTextureProcesssor.

PiperOrigin-RevId: 455628942
2022-06-27 10:32:38 +01:00