428 Commits

Author SHA1 Message Date
claincly
c910750074 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
(cherry picked from commit 6e126000993f5bbb9d1f2fd73df141158e8c7785)
2022-07-11 17:01:33 +00:00
samrobinson
3648ead231 Move Encoder quality API to VideoEncoderSettings.
Some other minor nits and adjustments to the API logic.

PiperOrigin-RevId: 459490431
(cherry picked from commit a36967c19bd9fee09b7df534befad7cae1d5453b)
2022-07-07 12:54:02 +00:00
huangdarwin
c8b0e5e89b 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
(cherry picked from commit 4230ea94e956bacc1bb3b6737686a845bc077dd9)
2022-07-06 18:11:11 +00:00
huangdarwin
e3fb3bf5de HDR: Throw error if attempting HDR editing under API 31.
HDR editing is not supported under API 31

PiperOrigin-RevId: 459211106
(cherry picked from commit 77d353b58be1e23de9eea505c6b0e7a46d4e4d0b)
2022-07-06 10:25:30 +00:00
huangdarwin
065c12caf4 HDR: Remove unused EGL_GL_COLORSPACE_KHR attribute.
PiperOrigin-RevId: 459106221
(cherry picked from commit bbbb009608c9b2fa951d664f4e2478c2cac61459)
2022-07-05 18:47:29 +00:00
samrobinson
6b5148e434 Implement device based encoder bitrate mapping.
This feature is disabled by default for now.

PiperOrigin-RevId: 458932471
(cherry picked from commit d5b02e75847eb5f062b544a52491dfe5df46a5fe)
2022-07-04 17:32:27 +00:00
hschlueter
67439206f1 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
(cherry picked from commit 474e2f2c77cad4759645ec3320f756757c0882db)
2022-07-01 18:34:02 +00:00
huangdarwin
39047b5676 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
(cherry picked from commit 53db305612a84466b6712cc355dbf918424a968d)
2022-07-01 16:57:43 +00:00
claincly
b440b556e2 Fix error in frame rate handling.
The old getString() will throw because FRAME_RATE can only be float or int.

PiperOrigin-RevId: 458481251
(cherry picked from commit 2b6f62b2a124e3a635ddcba7d9f256c52b564d89)
2022-07-01 16:05:39 +00:00
claincly
e3f1787c3a 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
(cherry picked from commit 8f89eba59c151f301d00d4fed200fd8f9359c9e2)
2022-07-01 14:58:47 +00:00
claincly
f1d4a4caab 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
(cherry picked from commit 821ab267026beee4f37e71220d930776b6ac266f)
2022-07-01 11:06:12 +00:00
hschlueter
25ece32dda 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
(cherry picked from commit f41e6796ce39469f9fc3a844ec88725ab56d3356)
2022-06-29 17:56:53 +00:00
hschlueter
3d6bed1668 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
(cherry picked from commit e5527a8addff1e35380d3383dea237c70198a63a)
2022-06-29 17:27:05 +00:00
hschlueter
47cc8aaf92 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
(cherry picked from commit c74cf1f1aaa917bad3479779dff80aeeac866493)
2022-06-29 10:28:54 +00:00
hschlueter
c812c80a2f Allow changing input pixelWidthHeightRatio for GlEffectsFrameProcessor.
pixelWidthHeightRatio is now passed to setInputFrameInfo instead of
the factory.

PiperOrigin-RevId: 457696703
(cherry picked from commit bfa663d2b13340297354ef32ea7679775cb2d4eb)
2022-06-28 11:22:45 +00:00
hschlueter
9ad2d7123e Rename setVideoFrameEffects to setVideoEffects.
PiperOrigin-RevId: 457023382
(cherry picked from commit 20d220193e4051811e307b67a7e631b290449e23)
2022-06-24 17:04:45 +01:00
hschlueter
ad7fef1641 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
(cherry picked from commit a230d59f1b72e92f41196723eb1af1d23984a048)
2022-06-24 16:31:31 +01:00
hschlueter
bd3b450244 Extract FrameProcessor interface from GlEffectsFrameProcessor.
PiperOrigin-RevId: 456814150
(cherry picked from commit 1b5dd92dec4a9742cb957595857e695d5f8dfa83)
2022-06-23 19:00:01 +01:00
hschlueter
419ff0d264 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
(cherry picked from commit d9c63c1e872cbb730417ec4624d2860c25cfddb4)
2022-06-23 15:44:02 +01:00
hschlueter
26d7037730 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
(cherry picked from commit 216fefd669ab2bfdb03c202094b35eb935272d96)
2022-06-23 13:13:56 +01:00
samrobinson
1ba723a89f Add a Builder for DefaultEncoderFactory.
PiperOrigin-RevId: 456728032
(cherry picked from commit 19bdff96ba9e053110bd701724c671ac10ae7cef)
2022-06-23 11:37:19 +01:00
hschlueter
6edd1d2a2f 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
(cherry picked from commit e25bf811959baf1066ba18adc37e8bbdaad4791a)
2022-06-22 17:16:54 +01:00
hschlueter
f96a6c71b8 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
(cherry picked from commit 3a966916545f92c5ce08a640c912054ede215152)
2022-06-22 12:03:41 +01:00
huangdarwin
4102cdbc8a FrameProcessor: Use factories instead of a builder for Presentation.
PiperOrigin-RevId: 456064021
(cherry picked from commit d1357e8b59d019fcc7200c5ff13787c5ab3e211a)
2022-06-20 14:26:12 +01:00
hschlueter
23110cd6cc 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
(cherry picked from commit c92e18ec583eccde1bc80c11842ec81c9a6fedef)
2022-06-17 16:57:46 +01:00
hschlueter
3bca195c9f Wrap processor chain executor service for better exception handling.
The wrapper
* catches exceptions for each task and notifies the
  listener (this will be used more in follow-ups when processFrame
  is split into lots of listeners and callbacks),
* removes finished tasks from the queue and signals any exceptions
  that occurred to the listener each time a new task is executed.

PiperOrigin-RevId: 455345184
(cherry picked from commit bf9fa124115abe26764e163e755ed6046c4a0114)
2022-06-16 10:41:23 +00:00
hschlueter
da7ad3716b Replace FrameProcessorChain#isEnded with listener method.
PiperOrigin-RevId: 455114693
(cherry picked from commit 10050a1e8ccca217ba7facd21ecabab2b9811f8b)
2022-06-15 13:27:35 +00:00
hschlueter
5f142c4bbe Use FrameProcessorChain#SurfaceProvider for encoder compat transform.
This change adds a SurfaceProvider interface which is necessary to
allow for texture processors whose output size becomes available
asynchronously in follow-ups.
VTSP's implementation of this interface wraps the encoder and provides
its input surface together with the output frame width, height, and
orientation as used for encoder configuration.
The FrameProcessorChain converts the output frames to the provided
orientation and resolution using a ScaleToFitTransformation and
Presentation replacing EncoderCompatibilityTransformation.

PiperOrigin-RevId: 455112598
(cherry picked from commit d20f68498666ddf1f1946799cf002a9edb573a40)
2022-06-15 13:14:56 +00:00
hschlueter
e4605583bc Check targetSdkVersion for frame dropping workaround.
Based on
https://developer.android.com/reference/android/media/MediaCodec#using-an-output-surface,
frame dropping behaviour depends on the target SDK version.
After this change transformer will only use
MediaFormat#KEY_ALLOW_FRAME_DROP if both the target and system SDK
version are at least 29 and default to its pre 29 behaviour where each
decoder output frame must be processed before a new one is rendered
to prevent frame dropping otherwise.

Also remove deprecated Transformer.Builder constructor without a
context and the context setter.

PiperOrigin-RevId: 453971097
(cherry picked from commit 3f718b0d10e1d577620cca9ec76d0af38efc542c)
2022-06-09 18:22:39 +00:00
hschlueter
9ecf722824 Make GlUtil.GlException checked and remove flag to disable it.
Transformer always enabled glAssertionsEnabled, so there should
be no functional change.

ExoPlayer previously disabled glAssertionsEnabled, so GlUtil logged
GlExceptions instead of throwing them. The GlExceptions are now
caught and logged by the callers so that there should also be no
functional change overall.

This change also replaces EGLSurfaceTexture#GlException with
GlUtil#GlException.

PiperOrigin-RevId: 453963741
(cherry picked from commit dc668f2b59bb0df12cdbb77cb88072babe0218eb)
2022-06-09 17:53:39 +00:00
claincly
092fbd6c83 Ensure re-encode on performance tests
PiperOrigin-RevId: 453933854
(cherry picked from commit fa22efb7058816444a20cd11a2a423e99e8e4837)
2022-06-09 15:41:09 +00:00
huangdarwin
a4ed533eb5 Transformer GL: Split Presentation and Crop.
This removes the prior restriction of needing to remember not to crop and set aspect ratio in the same Presentation.Builder, and makes each class a bit more targeted.

This is partially made feasible by the past work to merge consecutive
MatrixTransformations into a single MatrixTransformationFrameProcessor, which
ensures that there's no loss in quality between successive MatrixTransformations.

PiperOrigin-RevId: 453660582
(cherry picked from commit b33dc5e57b96d81f9c246a369a09fb7a23a119e2)
2022-06-08 12:51:28 +00:00
hschlueter
1086e3bfbf Mention alpha for matrix transformation background color.
PiperOrigin-RevId: 453633920
(cherry picked from commit d5e4faa9ef8da6ec0810dee14ac7d23da85c7b56)
2022-06-08 09:50:18 +00:00
hschlueter
df6c8f1d8a Implement default GlTextureProcessor in SingleFrameGlTextureProcessor.
SingleFrameGlTextureProcessor is now an abstract class containing a
default implementation of the more flexible GlTextureProcessor interface
while still exposing the same simple abstract methods for single frame
processing it previously did.

FrameProcessorChain and GlEffect will be changed to use
GlTextureProcessor in follow-ups.

PiperOrigin-RevId: 453633000
(cherry picked from commit 0b37d860d13df1ac638f5a75c7af32c840e02956)
2022-06-08 09:44:25 +00:00
hschlueter
84b46c10de Add interface for async texture processors.
Implementations of this interface will be able to drop or add frames,
change timestamps, accept multiple input frames before producing
output, and process frames on their own background thread.

A default implementation of this interface will be added to SingleFrameGlTextureProcessor in a follow-up.

PiperOrigin-RevId: 453159835
(cherry picked from commit 023d19c8c5aa54841aeec12657846ac6a889dddb)
2022-06-06 10:18:26 +00:00
hschlueter
a04cc94afd Add async error listener to transformer to avoid exception wrapping.
This internal listener avoids wrapping the TransformationExceptions
in PlaybackExceptions that are handled via the Player.Listener and
is also used for FrameProcessingExceptions which already avoided
the PlaybackException layer previously.

This listener will also be useful in follow-ups for encoder-related
TransformationExceptions that are thrown in the SurfaceProvider that
will be called on the GL thread.

PiperOrigin-RevId: 452074575
(cherry picked from commit 960422e36f22a4c76e0617672aac9b9bcef50f43)
2022-05-31 17:01:02 +00:00
hschlueter
23b0610a37 Move program initialization to texture processor constructor.
Once the more advanced GlTextureProcessor interface exists,
it will be possible to change the output size of a GlTextureProcessor
between frames. To keep the re-configuration based on the frame sizes
minimal, things indepedent of the frame size, such as the GlProgram,
can be initialized in the constructor.

PiperOrigin-RevId: 451997584
(cherry picked from commit 54d44d38b6bb4a7a5dc69ed8cfd878aebe46f4b4)
2022-05-31 09:36:18 +00:00
claincly
d411461dfa Skip BitrateAnalysisTest if device is incapable.
Add bitrate check to the "can encode" criteria.

PiperOrigin-RevId: 451868042
2022-05-30 17:57:29 +00:00
andrewlewis
84efc5e8d0 Retain stream time offsets through codecs
ExoPlayer applies a large time offset to buffers so that, if the input has negative timestamps, generally buffers seen by the decoders should have positive timestamps. Modify how the offset is handled in `Transformer` so that decoders and encoders generally see positive timestamps, by leaving the offset on samples when reading them in the base renderer (remove the code that removed the offset), and then removing the offset when muxing. Also update the frame processor chain and slow motion flattening code to retain the existing behavior after this change (these both need original media presentation timestamps)

Tested via existing end-to-end tests and manually verified that the overlay frame processor shows the expected original media timestamps.

Aside: we don't need the same logic as ExoPlayer to track stream offsets across the decoder yet, because we don't try to handle stream changes during playback in single asset editing. (There is an edge case of multi-period DASH that may not work but I doubt anyone will use that as input to `Transformer` before we change the code to handle multi-asset properly.) In future we should try to refactor interaction with the decoder to use the same code for Transformer and ExoPlayer.
PiperOrigin-RevId: 451846055
2022-05-30 17:47:03 +00:00
samrobinson
38720a6b6d Treat pixels as unsigned and correct pixel count division.
PiperOrigin-RevId: 451428202
2022-05-30 17:40:06 +00:00
huangdarwin
983e074fc9 Transformer: Add 8k24fps transform test.
Most devices won't support 8k decoding, so they'll skip this test entirely.

As the video is quite short, this test shouldn't be any longer than the nearby,
long-running 4k60 test.

PiperOrigin-RevId: 451423368
2022-05-30 17:36:38 +00:00
samrobinson
1becb45c62 Clarify variables and improve documentation of SSIM.
PiperOrigin-RevId: 451392021
2022-05-30 17:33:05 +00:00
samrobinson
a96dd2d43e Use updated test name in BUILD and docs.
PiperOrigin-RevId: 451384408
2022-05-30 17:29:11 +00:00
hschlueter
6b521b2952 Use video passthrough if clipping starts at key frame.
PiperOrigin-RevId: 451380267
2022-05-30 17:22:16 +00:00
hschlueter
89e239eed1 Expand SSIM skipping to all Nexus API 21 devices.
PiperOrigin-RevId: 451371681
2022-05-30 17:18:46 +00:00
huangdarwin
14fc3179fb Transformer: Skip SSIM in tests when fallback is applied.
SSIM calculation requires the input and output dimensions to be identical.

For devices that can't encode the input dimensions, skip SSIM calculations and
log the cause. Only apply this on tests where the encoder may not support the
input file dimensions.

PiperOrigin-RevId: 451364904
2022-05-30 17:15:25 +00:00
hschlueter
541460a01d Fix handling clipping in transformer renderers.
Decode-only video frames (needed when the frame at / first frame after the
clipping start is not a key frame) need to be decoded but not passed to
the frame processor chain or encoder.

The clipping start offset needs to be removed from the frame timestamps
in the passthrough and video pipelines.
There are no changes needed for this in the audio pipeline, as it doesn't
use the input timestamps -- it uses its own timestamps derived from the
buffer sizes instead.

Also add demo option to try this out.

#minor-release

PiperOrigin-RevId: 451353609
2022-05-30 17:11:57 +00:00
hschlueter
d37cf34131 Rename GlFrameProcessor to SingleFrameGlTextureProcessor.
Also update names of implementations to match design doc.
In follow-ups, SingleFrameGlTextureProcessor will become
an abstract implementation of a new GlTextureProcessor
interface.

Texture processor makes sense as it processes OpenGL textures.
The term frame processor will be used for something else in
follow-ups.

PiperOrigin-RevId: 451142085
2022-05-30 17:01:17 +00:00
hschlueter
2b4642f663 Skip SSIM calculation on Nexus 5 API 21.
There is a problem with the ImageReader formats used by the
SSIM helper that only occurs for Nexus 5 API 21, so as a workaround
we can skip the SSIM calculation on Nexus 5 API 21.

This skips just the SSIM calculation (by setting the value to
1.0 instead and logging). The tests still run when SSIM is skipped
so that we can detect other failures.

PiperOrigin-RevId: 450903183
2022-05-26 13:04:03 +00:00
hschlueter
52ad75c0a4 Replace 640x360 H264 test video with 320x240 H264 video.
Decoding and encoding 320x240 H264 video should be supported
on all devices from Android 5.0 based on CDD requirements.
https://source.android.com/compatibility/5.0/android-5.0-cdd#5_2_video_encoding

640x360 encoding doesn't seem to be supported on Nexus 5.

PiperOrigin-RevId: 450901715
2022-05-26 13:00:27 +00:00