137 Commits

Author SHA1 Message Date
sheenachhabra
1729e11159 Fix version and flags in the ctts box
The version and flags are stored in a single integer,
with the version in the higher 8 bits and the flags in
the lower 24 bits. The version should be 1 and the
flags should be 0.

Surprisingly the incorrect value was ignored by many
players and hence the bug was never caught.
With the bug, the video does not play on
`Samsung Galaxy S22 Ultra` and works well
after fixing the bug.

PiperOrigin-RevId: 684433371
2024-10-10 07:19:24 -07:00
sheenachhabra
b0b54ca018 Calculate min timestamp across tracks in the Boxes.moov method
The Boxes.moov method can do the calculation instead of caller doing
it.

PiperOrigin-RevId: 679653033
2024-09-27 11:00:52 -07:00
Googler
020ce7765c Reduce rounding error and stts table entries.
To avoid rounding errors, set the `Rounding mode` of the `uvFromVu` and `vuFromUs` results to `HALF_UP`. This `Rounding mode` rounds numbers towards the "nearest neighbor" unless both neighbors are equidistant, in which case round up.

PiperOrigin-RevId: 679003943
2024-09-25 23:19:20 -07:00
sheenachhabra
47d45a82ca Change the default value of lastSampleDurationBehavior
to
LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER_OR_DUPLICATE_PREVIOUS

This CL also combines LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER
and LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS.

The reason for combining the two enums is that, when the option
to use END_OF_STREAM_BUFFER is selected and if the EOS buffer is
not provided then the muxer anyways fallbacks to duplicate
duration behavior.

The last sample with 0 durations seems less useful so
change the default behavior to non-zero duration.
This will also match the behavior with MediaMuxer.

PiperOrigin-RevId: 675189932
2024-09-16 10:02:10 -07:00
Googler
011659b326 Add profile and level for H263 codec.
To support for 3gpp h263 codec in Mp4Muxer currently profile and level is hardcoded and provided to h263 box. Parse profile and level from MediaFormat and use those value to write h263 box.

PiperOrigin-RevId: 675004590
2024-09-15 22:09:38 -07:00
sheenachhabra
4be5b74366 Read NAL unit data as 4 byte integer
When converting NAL units from AnnexB to Avcc format,
one byte at a time was read. In fact many bytes were read
multiple times due to suboptimal logic.

Changed the logic to read 4 bytes at once and also to avoid
reading same bytes again.

This improved the time taken for writing a batch of 30
samples from 40ms to 20ms.

PiperOrigin-RevId: 673025781
2024-09-10 10:57:22 -07:00
sheenachhabra
35dc10aac8 Fix a bug to read last 3 bytes in AnnexBUtils
In the current implementation due to missing "="
operator, last three bytes were not checked for
000 or 001 sequence.

In sample_no_bframes file, few samples has extra 0 at the end.
It was working fine with the bug because muxer was writing some
harmless 0 at the end.

PiperOrigin-RevId: 672994054
2024-09-10 09:32:56 -07:00
sheenachhabra
e27c7d5d45 Use simpler timestamps in tests for readability
PiperOrigin-RevId: 670907537
2024-09-04 03:35:54 -07:00
sheenachhabra
a7788e0d60 Rename last sample duration behaviour enums
This is to improve readability.

PiperOrigin-RevId: 670563611
2024-09-03 08:15:23 -07:00
sheenachhabra
4e858f7260 Add support for setting last sample duration in Mp4Muxer
PiperOrigin-RevId: 669340763
2024-08-30 08:53:36 -07:00
sheenachhabra
791483f2d3 Remove TrackMetadataProvider interface
This interface was used by Boxes.moov. This CL removes the interface and just uses the Track object directly.

Since Track is package-private it seems fine to use it directly.
The drawback with interface is that, with every new field addition in the
Track class, we need to update the interface as well (if we need to access that field for moov box).

PiperOrigin-RevId: 669295399
2024-08-30 05:47:07 -07:00
sheenachhabra
613c7a6aa7 Change adjustLastSampleDuration() to getLastSampleDurationVu()
This is a no-op change.

PiperOrigin-RevId: 669283958
2024-08-30 04:55:40 -07:00
sheenachhabra
388d1f17b9 Clean up comments in Boxes.java
The CL aims to

1. Shorten unnecessary lengthy chatty comments.
2. Remove dead TODOs.
3. nit fixes for comment style consistency.
4. Remove usage of "we" in the comments.
5. Media3 muxer does not need to mention the behaviour of framework muxer
unless its required for some purpose, so remove them.

PiperOrigin-RevId: 668985875
2024-08-29 10:37:38 -07:00
sheenachhabra
ebd60acc95 Rename LAST_FRAME_DURATION_BEHAVIOR to LAST_SAMPLE_DURATION_BEHAVIOR
The original idea was to set duration for the last video frame, but this behavior actually applies to all tracks.

PiperOrigin-RevId: 667990099
2024-08-27 08:08:25 -07:00
sheenachhabra
52aeffbb3b Remove TODO for empty samples in muxer
There is no reason to write the empty samples so keep
the behaviour same as MediaMuxer

PiperOrigin-RevId: 667495861
2024-08-26 01:28:13 -07:00
sheenachhabra
4b7c5100f1 Move moov box generation to Boxes.java
This is a no-op change.
Like all other boxes, moov box creation can also be in
Boxes.java class.

PiperOrigin-RevId: 665359529
2024-08-20 07:47:58 -07:00
sheenachhabra
bb3948aa98 Implement interleaving of editable video tracks
The CL adds another way of writing editable video
tracks where the samples will be interleaved with the
primary track samples in the "mdat" box.

PiperOrigin-RevId: 665313751
2024-08-20 05:28:29 -07:00
sheenachhabra
ed905a6498 Refactor pending sample writing logic in Mp4Writer
The refactored method can be reused when implementing depth/editing format
interleave mode.

PiperOrigin-RevId: 663774290
2024-08-16 10:29:32 -07:00
Googler
afac17bef0 Mp4Muxer: Add support for Vp9 codec
Implement vpcCBox to provide support for muxing video encoded using the VP9 codec.

PiperOrigin-RevId: 663603654
2024-08-15 22:34:56 -07:00
sheenachhabra
7a1f3629ff Extract method to find minimum presentation timestamp across tracks
This is a ground work of implementing depth/editing format interleave mode.

PiperOrigin-RevId: 663301670
2024-08-15 07:40:27 -07:00
sheenachhabra
4df5ecb045 Rename flushPending() to writePendingTrackSamples()
The new name is more readable

PiperOrigin-RevId: 663264188
2024-08-15 04:54:19 -07:00
sheenachhabra
68eaa061e0 Add support for depth/editing file format in Mp4Extractor
PiperOrigin-RevId: 662956209
2024-08-14 09:55:01 -07:00
sheenachhabra
dbc9f5e0d1 Add EditablevideoParameter class
The parameter class will allow addition of more
parameters (link shouldInterleaveSamples), which are specific to
editable video file format.

PiperOrigin-RevId: 662923844
2024-08-14 08:13:05 -07:00
sheenachhabra
68393832b4 Use Track instead of TrackToken internally
The TrackToken is primarily for public API.
Using Track object internally will remove unnecessary
type casting at various places.

PiperOrigin-RevId: 662564224
2024-08-13 10:24:04 -07:00
sheenachhabra
96f2c7ece7 Refactor editable video track related logic
This is to reuse same logic in depth/edit file format `interleave` mode.

PiperOrigin-RevId: 662117528
2024-08-12 09:32:37 -07:00
sheenachhabra
117ac2e3f4 Create a common constant for large box size header
PiperOrigin-RevId: 661323230
2024-08-09 10:48:46 -07:00
sheenachhabra
94abb9515b Write same timestamp in edit data MP4 as in outer MP4
The exiting code ensured that the timestamp is same only when it is set by the app.

PiperOrigin-RevId: 661283124
2024-08-09 09:05:33 -07:00
kak
2202397758 Automated Code Change
PiperOrigin-RevId: 660491742
2024-08-07 12:28:25 -07:00
sheenachhabra
0530d663bc Rename muxer/Mp4Utils.java to muxer/Mp4MuxerUtil.java
PiperOrigin-RevId: 660417092
2024-08-07 09:23:53 -07:00
sheenachhabra
6a7e9132fd Write sample location key when muxing editable tracks
There are two ways to write editable tracks samples.
1. In the embedded edit data MP4.
2. Interleaved with primary tracks samples.

Initial plan was to support only option 1 but then the
decision is to support both ways. To identify between these two
an additional key will be required.

Option 2 is yet to be implemented in Mp4Muxer.

PiperOrigin-RevId: 658791214
2024-08-02 08:03:35 -07:00
sheenachhabra
86bd1df632 Move editable track type constants to container module
This is to share the constants with the extractor.

PiperOrigin-RevId: 658755661
2024-08-02 05:10:16 -07:00
Googler
aaa6561aa9 Rename tests in Boxestest
Replace the box name with Codec name in the test.

PiperOrigin-RevId: 655915063
2024-07-25 05:09:43 -07:00
Googler
d160aa2520 Modify tests in BoxesTest
Replace the string with the field from MimeType class

PiperOrigin-RevId: 655783812
2024-07-24 19:37:43 -07:00
Googler
b77f1d0f99 Add support for Audio Vorbis codec in Mp4Muxer.
Update esdsBox to support muxing of files encoded with Vorbis audio codec .

PiperOrigin-RevId: 655159074
2024-07-23 07:39:26 -07:00
Googler
3c5c81fc3e BoxesTest: Add default format builders
Move the common initialization code for format builder into separate methods to reduce code duplication.

PiperOrigin-RevId: 655118764
2024-07-23 04:54:32 -07:00
sheenachhabra
a52df6d29e Make Mp4MoovStructure.moov() method static
Creating a moov box is same as creating any other box so
there is no particular need to have a separate class for this.
In a follow up CL the method will be moved into Boxes.java along with
other box creation methods.

Made nit changes in the final fields ordering to match with
constructor parameter ordering.

PiperOrigin-RevId: 653602558
2024-07-18 06:50:42 -07:00
sheenachhabra
51d27d7575 Merge Boxes.moov() into Mp4MoovStucture.moov()
Boxes.moov() simply wraps the subboxes and this logic can be
put into main method which has all the logic of creating moov box.
This is to eventually move Mp4MoovStucture.moov() into
Boxes.java where all other box creation methods are already present.

PiperOrigin-RevId: 653319292
2024-07-17 12:15:44 -07:00
Googler
01dda6d3e5 Add support for Opus audio codec.
Implement dOpsBox to provide support for Opus audio codec

PiperOrigin-RevId: 653288049
2024-07-17 10:51:43 -07:00
Googler
951f296851 Add support for 3gpp h263 codec in Mp4Muxer.
Implement d263Box to provide support for muxing video encoded with the h263 codec.

PiperOrigin-RevId: 653188633
2024-07-17 04:53:28 -07:00
Googler
11ca78761e Add support for 3gpp amr-nb audio codec.
To support AMR audio codec(audio/3gpp) add `0x81FF` mode to create damrBox.

Add unit test and an Android end to end test.

PiperOrigin-RevId: 652438693
2024-07-15 04:48:28 -07:00
ibaker
6a9ff95bf0 Bump minSdk to 21 and remove resulting simple dead code
All other AndroidX libraries have already increased their min SDK to
21.

This change renames private symbols to remove `V21` suffixes and
similar, but doesn't change public or protected symbols with similar
names, to avoid needless breakages/churn on users of the library.

Some of the dead code removal is more complex, so I've split it out
into follow-up changes to make it easier to review.

PiperOrigin-RevId: 651776556
2024-07-12 08:11:01 -07:00
Googler
34a802ef38 Add support to MPEG4 codec in Mp4Muxer.
Add support for MPEG4 codec to enable muxing video encoded with the mp4v-es codec. Use esdsBox method to generate esds box required for Mp4v box.

PiperOrigin-RevId: 651000744
2024-07-10 06:55:00 -07:00
Googler
cf90d2624d Support for Large CodecSpecificData in ESDS box
Some external media files have CodecSpecificData greater than 128 bytes. Currently, that size
isn't fitting in one byte. Hence, added support to store large CodecSpecificDataSize, as per
ISO standard, by extending to more than one byte as required.

PiperOrigin-RevId: 650972472
2024-07-10 05:16:01 -07:00
Googler
6e18cb0053 Add support for amr-wb audio codec.
Implement damrBox to provide support for amr-wb audio codec.

Add unit test and an Android end to end test.

PiperOrigin-RevId: 650210732
2024-07-08 05:13:18 -07:00
Googler
a269355369 Refactor audioEsdsBox to esdsBox
Since the muxer supported only AAC audio codec, the esdsBox was unconditionally created within the audioSampleEntry. This CL refactors the box creation logic by moving it to the codecSpecificBox method. This is to make adding support for new audio codecs easier.

PiperOrigin-RevId: 650130935
2024-07-07 23:13:29 -07:00
sheenachhabra
3793a06bdd Add support for file format for depth/editing in Mp4Muxer
PiperOrigin-RevId: 648747038
2024-07-02 09:42:36 -07:00
Googler
3da63eeaa7 Add NAL unit parsing needed for stereo MV-HEVC playback.
Add the following NAL unit parsing utility functions that will be needed for the MV-HEVC support as proposed in Apple's HEVC stereo video interoperability profile:
- NAL unit header parsing to get the layer information needed for MV-HEVC support.
- VPS parsing, including vps_extension() needed for MV-HEVC support.
- SPS parsing modifications to support MV-HEVC.

PiperOrigin-RevId: 647329211
2024-06-27 08:39:12 -07:00
sheenachhabra
6fc0243106 Use Set instead of a List for metadata collection
All metadata entries are supposed to be unique, so Set is more appropriate.

PiperOrigin-RevId: 646907916
2024-06-26 05:29:47 -07:00
sheenachhabra
be2d68c2b3 Improve method names in Mp4Writer
PiperOrigin-RevId: 646465516
2024-06-25 07:09:12 -07:00
sheenachhabra
babc9c69c6 Remove unnecessary FileChannel from Mp4Muxer
As per the documentation, closing a `FileOutputStream`
automatically closes the associated `FileChannel`.

PiperOrigin-RevId: 646152280
2024-06-24 10:58:30 -07:00