761 Commits

Author SHA1 Message Date
andrewlewis
990f7ef5b5 Select codecs without util methods
`findDecoder/EncoderForFormat` seem to be more restrictive than querying
`MediaCodecList` as done for playback, and it's not clear that the cases where
no codec is found correspond to actual cases that would fail given that it
seems this returns an empty string for many cases in production.

Switch to using `MediaCodecUtil` and `EncoderUtil` for querying codecs instead.

PiperOrigin-RevId: 525078321
2023-04-18 18:08:18 +01:00
kimvde
23b1cab56c Fix video timestamp 0 set to large value in some cases
PiperOrigin-RevId: 525064269
2023-04-18 18:07:19 +01:00
Googler
ffa969f97c Expose MssimCaluclator for use in Duetdev tests
Child: <unknown commit>

PiperOrigin-RevId: 524876651
2023-04-18 18:06:01 +01:00
huangdarwin
0e85491d4e Transformer: Update TODOs to use new bug link
PiperOrigin-RevId: 524349341
2023-04-17 17:12:28 +01:00
kimvde
9c5fca8e65 Fix muxer failing in test
MediaMuxer does not support out-of-order video frames API 25. Use
a test file with frames in order in
loopingTranscodedAudio_producesExpectedResult. This is necessary for
tests that transmux video samples.

PiperOrigin-RevId: 524309318
2023-04-17 17:10:03 +01:00
huangdarwin
9835e58e4c HDR: Add comment describing HDR_MODE_KEEP_HDR behavior.
PiperOrigin-RevId: 524301315
2023-04-17 17:07:53 +01:00
huangdarwin
e0314f3041 HDR: Add HDR passthrough effect pixel tests.
A passthrough effect allows for testing having an intermediate
effect injected, which uses different OpenGL shaders from having no
effects.

PiperOrigin-RevId: 524276991
2023-04-17 17:06:05 +01:00
claincly
cb28960c07 Set encoded level in DefaultDecoderFactory.
PiperOrigin-RevId: 524248369
2023-04-17 17:05:03 +01:00
andrewlewis
affc237055 Channel mix to 16-bit int not float
Previously `ChannelMixingAudioProcessor` output float because it was
implemented using the audio mixer's float mixing support.

Move the implementation over to just using the `ChannelMixingMatrix` and make
it publicly visible in the common module so it can be used by apps for both
playback and export.

Also resolve a TODO that no longer had a bug attached by implementing support
for putting multiple mixing matrices to handle different input audio channel
counts, and fix some nits in the test code.

Tested via unit tests and manually configuring a `ChannelMixingAudioProcessor`
in the transformer demo app and playing an audio stream that identifies
channels, and verifying that they are remapped as expected.

PiperOrigin-RevId: 523653901
2023-04-12 16:58:43 +01:00
huangdarwin
acdb7ee921 HDR: Add HDR pixel tests.
Implement HDR input support for texture output, and add HDR pixel tests.

PiperOrigin-RevId: 523417701
2023-04-12 16:51:51 +01:00
andrewlewis
d43fe3470f Fix audio encode timestamp off by one
Simplify the audio encoder input timestamp calculation. The new calculation
avoids drifting by tracking the total number of bytes encoded rather than
tracking the timestamp and remainder separately, and also makes the timestamps
match the decoder output buffer timestamps.

Also switch one of the export tests that was passing through AMR samples over
to using WAVE audio. The problem with using AMR is that the compressed samples
are not necessarily an integer number of audio frames and the shadow decoder
would pass them from input to output, so the audio encoder was receiving
non-integer numbers of audio frames.

Tested by logging the timestamps at the decoder output and encoder input with
forcing transcoding audio, and verifying that after this change the audio
timestamps are no longer off by one.

PiperOrigin-RevId: 523409869
2023-04-12 16:50:25 +01:00
andrewlewis
0b40bc37ab Release sample pipelines before asset loaders
The video asset loader renders decoder output to a surface texture, and if the
video sample pipeline is in the process of updating the surface texture image
at the moment when the asset loader video decoder is released this seems to
cause `MediaCodec.release` to get stuck.

Swap the release order so that we stop updating the texture before trying to
release the codec.

PiperOrigin-RevId: 523401619
2023-04-12 16:49:30 +01:00
andrewlewis
ba2c32738f Improve error logging
Log at debug level immediately when MediaCodec throws. This logging will be
output closer to the time when the error actually happened so should make it
easier to identify the order of components failing.

Downgrade logging of errors after export ends to warning level, as output may
still be fine if there was a problem after exporting completed (though it's
still worth logging a warning as the device may not be in a good state).

PiperOrigin-RevId: 523370457
2023-04-12 16:48:33 +01:00
huangdarwin
0d30edae75 Test: Add TextureOutputListener for texture output tests
Before this CL, SurfaceTexture.onFrameAvailable was used to tell whether a frame
was available in the VideoFrameProcessor's output texture. This was incorrect, as
it would rely on having the texture be written to before the
SurfaceTexture.onFrameAvailableListener is invoked, leading to null-pointer-
exceptions on timeouts.

Instead of using DefaultVideoFrameProcessor different interfaces to set that we
want to output to a texture, and get that output texture, use one interface that
sets a listener, and renders to a texture iff that listener is set. As this
listener is executed on the GL thread, this also allows us to no longer need to
expand visibility for the GL task executor and tasks.

PiperOrigin-RevId: 522362101
2023-04-11 10:34:38 +01:00
samrobinson
c3f25651bd Use AudioFormat in SilentAudioGenerator.
PiperOrigin-RevId: 521790733
2023-04-05 15:47:24 +01:00
sheenachhabra
28aa5e847b Move NAL unit utility classes into common
Need to use NAL unit util methods in muxer module.

PiperOrigin-RevId: 521772831
2023-04-05 15:45:35 +01:00
huangdarwin
167677ec84 HDR: Fix exportUnexpectedColorInfo.
PiperOrigin-RevId: 521427239
2023-04-05 15:41:37 +01:00
kimvde
0bfe43866a Add test for clipped media items concatenation
This was broken and has been fixed in <unknown commit>.

PiperOrigin-RevId: 521380415
2023-04-05 15:40:09 +01:00
kimvde
3a5c4277a7 Fix and simplify timestamps handling
Handling of the stream offset and start position was unnecessarily
complex and even incorrect. It was going to be an issue for
concatenation of video and image input.

The stream offset is the offset added before decoding/encoding to
make sure it doesn’t fail in case of negative timestamps (which do
rarely occur).
The start position is equal to the stream offset, plus the clipping
start time if the media is clipped.

Before this change:
- Samples were offset by the start position before decoding, and this
offset was removed before muxing.
- The startPosition of the first MediaItem in a sequence was used for
all the MediaItems in this sequence (which is incorrect).
- The stream offset was removed before applying the GL effects and
added back before encoding so that it was not visible to the OpenGL
processing.

After this change:
- The start position is subtracted in the AssetLoader, so that the
downstream components don’t have to deal with the stream offsets and
start positions.
- Decoded samples with negative timestamps are not passed to the
SamplePipelines. The MediaMuxer doesn’t handle negative timestamps
well. If a stream is 10 secondes long and starts at timestamp -2
seconds, the output will only contain the samples corresponding to the
first 8 (10 - 2) seconds. It won’t contain the last 2 seconds of the
stream. It seems acceptable to remove the first 2 seconds instead.

PiperOrigin-RevId: 520916464
2023-04-05 15:38:27 +01:00
kimvde
9cdf60d791 Fix emulator tests flakiness
Releasing the player once a sequence has ended seems to make our
emulator tests flaky. Comment out until we find the cause. The player
will still be released from TransformerInternal, when the export ends.

PiperOrigin-RevId: 520886181
2023-04-05 15:36:52 +01:00
kimvde
104cfc322c Clarify and fix SequenceAssetLoader threading
PiperOrigin-RevId: 520663415
2023-03-30 17:28:46 +00:00
rohks
766e7d7d35 Add media3 guide entries in README files
PiperOrigin-RevId: 520650881
2023-03-30 17:28:03 +00:00
rohks
6a928805d4 Fix javadoc links in media README files
Also fixed the javadoc link in devsite and removed javadoc links from decoder extensions as it is not published yet on developer.android.com.

#minor-release

PiperOrigin-RevId: 520636868
2023-03-30 17:26:40 +00:00
kimvde
1dbb19a44c Rollback of 7e6236cfdb
*** Original commit ***

Rollback of fc539da061

*** Original commit ***

Release SequenceAssetLoader when ended

Before, the SequenceAssetLoader was released at the end of the export.
Release resources earlier if possible.

***

***

PiperOrigin-RevId: 520036433
2023-03-30 17:18:30 +00:00
kimvde
24a164827e Fix handling of non-empty decoder end-of-stream output buffer
PiperOrigin-RevId: 520027236
2023-03-30 17:17:48 +00:00
kimvde
7e6236cfdb Rollback of fc539da061
*** Original commit ***

Release SequenceAssetLoader when ended

Before, the SequenceAssetLoader was released at the end of the export.
Release resources earlier if possible.

***

PiperOrigin-RevId: 519993003
2023-03-30 17:17:06 +00:00
kimvde
49d5955ce1 Add error code for muxer timeout
PiperOrigin-RevId: 519965132
2023-03-30 17:15:41 +00:00
kimvde
fc539da061 Release SequenceAssetLoader when ended
Before, the SequenceAssetLoader was released at the end of the export.
Release resources earlier if possible.

PiperOrigin-RevId: 519952572
2023-03-30 17:14:58 +00:00
huangdarwin
a0838771d3 HDR: Implement DefaultVideoFrameProcessor texture output for tests.
Previously, we always used ImageReader to read from the output of DefaultVideoFrameProcessor, for pixel tests. This has a limitation of not being
able to read HDR contents, so that we couldn't support HDR pixel tests.

Reading from a texture allows us to use glReadPixels to read from
DefaultVideoFrameProcessor, and build upon this to implement HDR pixel tests. We do
still want tests for surface output though, because real use-cases only will output
to Surfaces.

Also, add some tests for outputting to textures, since this test infrastructure is
a bit complex.

PiperOrigin-RevId: 519786535
2023-03-30 17:14:15 +00:00
kimvde
710b462b5f Update documentation of supported Compositions
Account for features implemented recently.

PiperOrigin-RevId: 519113898
2023-03-30 17:08:46 +00:00
kimvde
b118565730 Add an API entry point for looping a sequence
Also
- Add unit tests
- Fix bug discovered by unit tests

PiperOrigin-RevId: 519092249
2023-03-30 17:07:27 +00:00
kimvde
1f6b000219 Handle looping sequences in TransformerInternal
PiperOrigin-RevId: 518895943
2023-03-30 17:06:01 +00:00
sheenachhabra
69cece1d82 Make getMp4LocationData method inline
PiperOrigin-RevId: 518827223
2023-03-30 17:04:46 +00:00
tofunmi
8df4fd769c Log export errors that occur after export completes
PiperOrigin-RevId: 518281002
2023-03-22 10:35:05 +00:00
tofunmi
3a6ee77daf skip transformer tests if no internet connection
The failure reason (no network) will be logged in the test output, but the test will not be marked as failing, rather skipped.

PiperOrigin-RevId: 518262203
2023-03-21 14:06:11 +00:00
huangdarwin
fca9197e1c HDR: Only check for HDR encoders on API 33+.
FEATURE_HdrEditing is only available on and above API 33, so it doesn't make
sense to check for support under API 33.

PiperOrigin-RevId: 518036855
2023-03-21 14:20:01 +00:00
kimvde
aed5d62602 Remove TODOs
PiperOrigin-RevId: 517444208
2023-03-21 14:17:04 +00:00
kimvde
d41d025803 Add support for looping sequences in SequenceAssetLoader
PiperOrigin-RevId: 517418886
2023-03-21 14:16:19 +00:00
huangdarwin
e54c7a7c79 Test: Trim 4k60 test file to 300ms.
This was trimmed using the Transformer Demo, from ~4 seconds to 300ms

Otherwise, this test file will be quite large, and folks who clone the repo will
have to clone this content as well. Trimming the file also allows the test to
take less time, while still testing the core purpose of the file, to confirm that 4k extraction/decode/GL/encode/muxing works.

PiperOrigin-RevId: 517408463
2023-03-21 14:15:35 +00:00
samrobinson
78373991b8 Fix nits in FloatAudioMixingAlgorithmTest.
* Reorder methods.
* Arrange, act, assert split.

PiperOrigin-RevId: 517158351
2023-03-21 14:14:47 +00:00
samrobinson
9e66998ea4 Add test cases for mixing to mono.
PiperOrigin-RevId: 517127021
2023-03-16 15:36:09 +00:00
huangdarwin
a6479c3d10 Test: Move 4k60 test file to local from remote.
This test file used to be remote, which led to various errors in loading the file or timing out during the muxer or overall transformer.

export4k60 test timing on Pixel 7:

|Condition                 |elapsedTimeMs|AS Test "Duration" (s)|
|--------------------------|-------------|----------------------|
|local file (this CL)      |4253         |14                    |
|Remote file, googleguest  |5510         |17                    |
|Remote file, 4G           |11423        |25                    |

PiperOrigin-RevId: 516815462
2023-03-16 15:31:56 +00:00
kimvde
1ad68ffb17 Add a way in the SampleConsumer to indicate that it couldn't consume
- To support looping EditedMediaItemSequences, we need a way to tell the
AssetLoader that a sample couldn't be consumed and that it should retry
later. This is necessary in case we don't know yet whether the looping
sequence should load more samples because the other sequences haven't
made sufficient progress yet.
- The decision on whether to consume a sample is based on its timestamp
so it needs to be available.

PiperOrigin-RevId: 516546026
2023-03-16 15:29:26 +00:00
samrobinson
eabf952048 Move RepeatedTranscodeTest to mh/analysis.
This test is not run on emulator, triage or postsubmit, and does not
provide value to the library in it's current state. It could be
deleted, however it still may have use for analysis of exported files
on MH.

PiperOrigin-RevId: 516491160
2023-03-14 15:54:56 +00:00
sheenachhabra
7b8c562d7b Remove setLocation() method from Muxer interface
PiperOrigin-RevId: 516314175
2023-03-14 07:56:52 +00:00
huangdarwin
f0d91b30d5 Effect: Implement TimestampWrapper.
To allow applying an effect only on a range of timestamps.

PiperOrigin-RevId: 515615662
2023-03-14 07:52:12 +00:00
samrobinson
a3e93f74cb Remove PCM encoding from ExportResult.
PCM encoding is a property of decoded audio, however Transformer does
not output decoded audio.

PiperOrigin-RevId: 515580886
2023-03-14 07:51:26 +00:00
kimvde
1865e38108 Add test for audio and video from different sources
PiperOrigin-RevId: 515379858
2023-03-14 07:50:18 +00:00
sheenachhabra
1c9c384aaa Add support for writing MP4 location data using media muxer
PiperOrigin-RevId: 515297752
2023-03-14 07:48:20 +00:00
kimvde
6d623bfad7 Split TransformerEndToEndTest
Split test/ TransformerEndToEndTest into SingleMediaItemEndToEndTest and
SingleSequenceEndToEndTest to reduce the file size and split the tests
by category.

PiperOrigin-RevId: 515039502
2023-03-14 07:42:55 +00:00