Skip to content

Commit 27624bd

Browse files
SheenaChhabracopybara-github
authored andcommitted
Use audio sample rate as timescale
This will avoid rounding errors during conversion. In the dump files, the timestamps are now exactly same as those from input file. PiperOrigin-RevId: 787040930
1 parent 7231528 commit 27624bd

File tree

12 files changed

+528
-534
lines changed

12 files changed

+528
-534
lines changed

libraries/muxer/src/main/java/androidx/media3/muxer/Track.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ public void writeSampleData(ByteBuffer byteBuffer, BufferInfo bufferInfo) {
109109
}
110110

111111
public int videoUnitTimebase() {
112-
return MimeTypes.isAudio(format.sampleMimeType)
113-
? 48_000 // TODO: b/270583563 - Update these with actual values from mediaFormat.
114-
: 90_000;
112+
// TODO: b/270583563 - Use frame rate for video tracks.
113+
return MimeTypes.isAudio(format.sampleMimeType) ? format.sampleRate : 90_000;
115114
}
116115
}

libraries/test_data/src/test/assets/muxerdumps/sample_av1.mp4.dump

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
seekMap:
22
isSeekable = true
3-
duration = 1045300
3+
duration = 1044900
44
getPosition(0) = [[timeUs=0, position=400052]]
55
getPosition(1) = [[timeUs=0, position=400052]]
6-
getPosition(522650) = [[timeUs=0, position=400052]]
7-
getPosition(1045300) = [[timeUs=0, position=400052]]
6+
getPosition(522450) = [[timeUs=0, position=400052]]
7+
getPosition(1044900) = [[timeUs=0, position=400052]]
88
numberOfTracks = 2
99
track 0:
1010
total output bytes = 69084
@@ -149,9 +149,9 @@ track 0:
149149
track 1:
150150
total output bytes = 9312
151151
sample count = 45
152-
track duration = 1045300
152+
track duration = 1044900
153153
format 0:
154-
averageBitrate = 71267
154+
averageBitrate = 71295
155155
peakBitrate = 71295
156156
id = 2
157157
containerMimeType = video/mp4
@@ -169,179 +169,179 @@ track 1:
169169
flags = 1
170170
data = length 21, hash 77102128
171171
sample 1:
172-
time = 66229
172+
time = 66219
173173
flags = 1
174174
data = length 17, hash BA75F5D4
175175
sample 2:
176-
time = 89458
176+
time = 89439
177177
flags = 1
178178
data = length 582, hash B5064B53
179179
sample 3:
180-
time = 112687
180+
time = 112659
181181
flags = 1
182182
data = length 218, hash 46000EEF
183183
sample 4:
184-
time = 135916
184+
time = 135879
185185
flags = 1
186186
data = length 206, hash 7B12EC38
187187
sample 5:
188-
time = 159145
188+
time = 159099
189189
flags = 1
190190
data = length 215, hash C05E2F91
191191
sample 6:
192-
time = 182375
192+
time = 182319
193193
flags = 1
194194
data = length 217, hash 1E457BBF
195195
sample 7:
196-
time = 205604
196+
time = 205539
197197
flags = 1
198198
data = length 195, hash DFD6F480
199199
sample 8:
200-
time = 228833
200+
time = 228759
201201
flags = 1
202202
data = length 198, hash 2BC702E
203203
sample 9:
204-
time = 252062
204+
time = 251979
205205
flags = 1
206206
data = length 216, hash ED964B3D
207207
sample 10:
208-
time = 275291
208+
time = 275199
209209
flags = 1
210210
data = length 204, hash DAF6FDC6
211211
sample 11:
212-
time = 298520
212+
time = 298419
213213
flags = 1
214214
data = length 205, hash D249FD76
215215
sample 12:
216-
time = 321750
216+
time = 321639
217217
flags = 1
218218
data = length 200, hash C8F844E4
219219
sample 13:
220-
time = 344979
220+
time = 344859
221221
flags = 1
222222
data = length 196, hash FDD0CA03
223223
sample 14:
224-
time = 368208
224+
time = 368079
225225
flags = 1
226226
data = length 196, hash E4E3A7B0
227227
sample 15:
228-
time = 391437
228+
time = 391299
229229
flags = 1
230230
data = length 207, hash 157773E3
231231
sample 16:
232-
time = 414666
232+
time = 414519
233233
flags = 1
234234
data = length 207, hash C9F46F0F
235235
sample 17:
236-
time = 437895
236+
time = 437739
237237
flags = 1
238238
data = length 210, hash 127AC739
239239
sample 18:
240-
time = 461125
240+
time = 460959
241241
flags = 1
242242
data = length 217, hash B2649830
243243
sample 19:
244-
time = 484354
244+
time = 484179
245245
flags = 1
246246
data = length 188, hash 4D280759
247247
sample 20:
248-
time = 507583
248+
time = 507399
249249
flags = 1
250250
data = length 205, hash EAE6D6AD
251251
sample 21:
252-
time = 530812
252+
time = 530619
253253
flags = 1
254254
data = length 226, hash BDD0EC44
255255
sample 22:
256-
time = 554041
256+
time = 553839
257257
flags = 1
258258
data = length 199, hash 60C719A2
259259
sample 23:
260-
time = 577270
260+
time = 577058
261261
flags = 1
262262
data = length 215, hash EDDE842F
263263
sample 24:
264-
time = 600500
264+
time = 600278
265265
flags = 1
266266
data = length 201, hash D17187B
267267
sample 25:
268-
time = 623729
268+
time = 623498
269269
flags = 1
270270
data = length 217, hash 58DD698C
271271
sample 26:
272-
time = 646958
272+
time = 646718
273273
flags = 1
274274
data = length 202, hash 5168D405
275275
sample 27:
276-
time = 670187
276+
time = 669938
277277
flags = 1
278278
data = length 194, hash 7139AF8
279279
sample 28:
280-
time = 693416
280+
time = 693158
281281
flags = 1
282282
data = length 203, hash F775D9ED
283283
sample 29:
284-
time = 716645
284+
time = 716378
285285
flags = 1
286286
data = length 200, hash 774C5045
287287
sample 30:
288-
time = 739875
288+
time = 739598
289289
flags = 1
290290
data = length 211, hash ED3C6FBC
291291
sample 31:
292-
time = 763104
292+
time = 762818
293293
flags = 1
294294
data = length 205, hash FC4754A9
295295
sample 32:
296-
time = 786333
296+
time = 786038
297297
flags = 1
298298
data = length 216, hash 72F4AF29
299299
sample 33:
300-
time = 809562
300+
time = 809258
301301
flags = 1
302302
data = length 204, hash 1AF98D40
303303
sample 34:
304-
time = 832791
304+
time = 832478
305305
flags = 1
306306
data = length 200, hash E0004171
307307
sample 35:
308-
time = 856020
308+
time = 855698
309309
flags = 1
310310
data = length 215, hash B413079A
311311
sample 36:
312-
time = 879250
312+
time = 878918
313313
flags = 1
314314
data = length 211, hash 107CEE52
315315
sample 37:
316-
time = 902479
316+
time = 902138
317317
flags = 1
318318
data = length 214, hash 1E588A0D
319319
sample 38:
320-
time = 925708
320+
time = 925358
321321
flags = 1
322322
data = length 210, hash 84E5BBBD
323323
sample 39:
324-
time = 948937
324+
time = 948578
325325
flags = 1
326326
data = length 211, hash 32D7ACAB
327327
sample 40:
328-
time = 972166
328+
time = 971798
329329
flags = 1
330330
data = length 201, hash 1567F919
331331
sample 41:
332-
time = 995395
332+
time = 995018
333333
flags = 1
334334
data = length 196, hash 2F050463
335335
sample 42:
336-
time = 1018625
336+
time = 1018238
337337
flags = 1
338338
data = length 215, hash 4BDD9C81
339339
sample 43:
340-
time = 1041854
340+
time = 1041458
341341
flags = 1
342342
data = length 242, hash DD6FD967
343343
sample 44:
344-
time = 1065083
344+
time = 1064678
345345
flags = 536870913
346346
data = length 184, hash DAFC330D
347347
tracksEnded = true

0 commit comments

Comments
 (0)