From fe1ffdb959f155fcd732fdeebf66ac1400654ca5 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Thu, 23 Dec 2021 15:38:36 +0000 Subject: [PATCH] Throw when inferred sample MIME type is not supported by the muxer. This is better than silently dropping tracks as done previously. Later, we will implement fallback to transcoding to a supported MIME type. PiperOrigin-RevId: 418006258 --- .../amr/sample_nb.amr.aac.dump | 1315 +++++++++++++++++ .../mkv/sample_with_srt.mkv.dump | 237 ++- .../mp4/sample_18byte_nclx_colr.mp4.dump | 198 +++ .../transformer/TransformationException.java | 24 + .../media3/transformer/Transformer.java | 6 +- .../transformer/TransformerBaseRenderer.java | 85 +- .../media3/transformer/TransformerTest.java | 103 +- 7 files changed, 1883 insertions(+), 85 deletions(-) create mode 100644 libraries/test_data/src/test/assets/transformerdumps/amr/sample_nb.amr.aac.dump create mode 100644 libraries/test_data/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.dump diff --git a/libraries/test_data/src/test/assets/transformerdumps/amr/sample_nb.amr.aac.dump b/libraries/test_data/src/test/assets/transformerdumps/amr/sample_nb.amr.aac.dump new file mode 100644 index 0000000000..e885cab915 --- /dev/null +++ b/libraries/test_data/src/test/assets/transformerdumps/amr/sample_nb.amr.aac.dump @@ -0,0 +1,1315 @@ +containerMimeType = video/mp4 +format 0: + sampleMimeType = audio/mp4a-latm + channelCount = 1 + sampleRate = 8000 + pcmEncoding = 2 +sample: + trackIndex = 0 + dataHashCode = 924517484 + size = 13 + isKeyFrame = true + presentationTimeUs = 0 +sample: + trackIndex = 0 + dataHashCode = -835666085 + size = 13 + isKeyFrame = true + presentationTimeUs = 813 +sample: + trackIndex = 0 + dataHashCode = 430283125 + size = 13 + isKeyFrame = true + presentationTimeUs = 1625 +sample: + trackIndex = 0 + dataHashCode = 1215919932 + size = 13 + isKeyFrame = true + presentationTimeUs = 2438 +sample: + trackIndex = 0 + dataHashCode = -386387943 + size = 13 + isKeyFrame = true + presentationTimeUs = 3250 +sample: + trackIndex = 0 + dataHashCode = -765080119 + size = 13 + isKeyFrame = true + presentationTimeUs = 4063 +sample: + trackIndex = 0 + dataHashCode = -1855636054 + size = 13 + isKeyFrame = true + presentationTimeUs = 4875 +sample: + trackIndex = 0 + dataHashCode = -946579722 + size = 13 + isKeyFrame = true + presentationTimeUs = 5688 +sample: + trackIndex = 0 + dataHashCode = -841202654 + size = 13 + isKeyFrame = true + presentationTimeUs = 6500 +sample: + trackIndex = 0 + dataHashCode = -638764303 + size = 13 + isKeyFrame = true + presentationTimeUs = 7313 +sample: + trackIndex = 0 + dataHashCode = -1162388941 + size = 13 + isKeyFrame = true + presentationTimeUs = 8125 +sample: + trackIndex = 0 + dataHashCode = 572634367 + size = 13 + isKeyFrame = true + presentationTimeUs = 8938 +sample: + trackIndex = 0 + dataHashCode = -1774188021 + size = 13 + isKeyFrame = true + presentationTimeUs = 9750 +sample: + trackIndex = 0 + dataHashCode = 92464891 + size = 13 + isKeyFrame = true + presentationTimeUs = 10563 +sample: + trackIndex = 0 + dataHashCode = -991397659 + size = 13 + isKeyFrame = true + presentationTimeUs = 11375 +sample: + trackIndex = 0 + dataHashCode = -934698563 + size = 13 + isKeyFrame = true + presentationTimeUs = 12188 +sample: + trackIndex = 0 + dataHashCode = -811030035 + size = 13 + isKeyFrame = true + presentationTimeUs = 13000 +sample: + trackIndex = 0 + dataHashCode = 1892305159 + size = 13 + isKeyFrame = true + presentationTimeUs = 13813 +sample: + trackIndex = 0 + dataHashCode = -1266858924 + size = 13 + isKeyFrame = true + presentationTimeUs = 14625 +sample: + trackIndex = 0 + dataHashCode = 673814721 + size = 13 + isKeyFrame = true + presentationTimeUs = 15438 +sample: + trackIndex = 0 + dataHashCode = 1061124709 + size = 13 + isKeyFrame = true + presentationTimeUs = 16250 +sample: + trackIndex = 0 + dataHashCode = -869356712 + size = 13 + isKeyFrame = true + presentationTimeUs = 17063 +sample: + trackIndex = 0 + dataHashCode = 664729362 + size = 13 + isKeyFrame = true + presentationTimeUs = 17875 +sample: + trackIndex = 0 + dataHashCode = -1439741143 + size = 13 + isKeyFrame = true + presentationTimeUs = 18688 +sample: + trackIndex = 0 + dataHashCode = -151627580 + size = 13 + isKeyFrame = true + presentationTimeUs = 19500 +sample: + trackIndex = 0 + dataHashCode = -673268457 + size = 13 + isKeyFrame = true + presentationTimeUs = 20313 +sample: + trackIndex = 0 + dataHashCode = 1839962647 + size = 13 + isKeyFrame = true + presentationTimeUs = 21125 +sample: + trackIndex = 0 + dataHashCode = 1858999665 + size = 13 + isKeyFrame = true + presentationTimeUs = 21938 +sample: + trackIndex = 0 + dataHashCode = -1278193537 + size = 13 + isKeyFrame = true + presentationTimeUs = 22750 +sample: + trackIndex = 0 + dataHashCode = 568547001 + size = 13 + isKeyFrame = true + presentationTimeUs = 23563 +sample: + trackIndex = 0 + dataHashCode = 68217362 + size = 13 + isKeyFrame = true + presentationTimeUs = 24375 +sample: + trackIndex = 0 + dataHashCode = 1396217256 + size = 13 + isKeyFrame = true + presentationTimeUs = 25188 +sample: + trackIndex = 0 + dataHashCode = -971293094 + size = 13 + isKeyFrame = true + presentationTimeUs = 26000 +sample: + trackIndex = 0 + dataHashCode = -1742638874 + size = 13 + isKeyFrame = true + presentationTimeUs = 26813 +sample: + trackIndex = 0 + dataHashCode = 2047109317 + size = 13 + isKeyFrame = true + presentationTimeUs = 27625 +sample: + trackIndex = 0 + dataHashCode = -1668945241 + size = 13 + isKeyFrame = true + presentationTimeUs = 28438 +sample: + trackIndex = 0 + dataHashCode = -1229766218 + size = 13 + isKeyFrame = true + presentationTimeUs = 29250 +sample: + trackIndex = 0 + dataHashCode = 1765233454 + size = 13 + isKeyFrame = true + presentationTimeUs = 30063 +sample: + trackIndex = 0 + dataHashCode = -1930255456 + size = 13 + isKeyFrame = true + presentationTimeUs = 30875 +sample: + trackIndex = 0 + dataHashCode = -764925242 + size = 13 + isKeyFrame = true + presentationTimeUs = 31688 +sample: + trackIndex = 0 + dataHashCode = -1144688369 + size = 13 + isKeyFrame = true + presentationTimeUs = 32500 +sample: + trackIndex = 0 + dataHashCode = 1493699436 + size = 13 + isKeyFrame = true + presentationTimeUs = 33313 +sample: + trackIndex = 0 + dataHashCode = -468614511 + size = 13 + isKeyFrame = true + presentationTimeUs = 34125 +sample: + trackIndex = 0 + dataHashCode = -1578782058 + size = 13 + isKeyFrame = true + presentationTimeUs = 34938 +sample: + trackIndex = 0 + dataHashCode = -675743397 + size = 13 + isKeyFrame = true + presentationTimeUs = 35750 +sample: + trackIndex = 0 + dataHashCode = -863790111 + size = 13 + isKeyFrame = true + presentationTimeUs = 36563 +sample: + trackIndex = 0 + dataHashCode = -732307506 + size = 13 + isKeyFrame = true + presentationTimeUs = 37375 +sample: + trackIndex = 0 + dataHashCode = -693298708 + size = 13 + isKeyFrame = true + presentationTimeUs = 38188 +sample: + trackIndex = 0 + dataHashCode = -799131843 + size = 13 + isKeyFrame = true + presentationTimeUs = 39000 +sample: + trackIndex = 0 + dataHashCode = 1782866119 + size = 13 + isKeyFrame = true + presentationTimeUs = 39813 +sample: + trackIndex = 0 + dataHashCode = -912205505 + size = 13 + isKeyFrame = true + presentationTimeUs = 40625 +sample: + trackIndex = 0 + dataHashCode = 1067981287 + size = 13 + isKeyFrame = true + presentationTimeUs = 41438 +sample: + trackIndex = 0 + dataHashCode = 490520060 + size = 13 + isKeyFrame = true + presentationTimeUs = 42250 +sample: + trackIndex = 0 + dataHashCode = -1950632957 + size = 13 + isKeyFrame = true + presentationTimeUs = 43063 +sample: + trackIndex = 0 + dataHashCode = 565485817 + size = 13 + isKeyFrame = true + presentationTimeUs = 43875 +sample: + trackIndex = 0 + dataHashCode = -1057414703 + size = 13 + isKeyFrame = true + presentationTimeUs = 44688 +sample: + trackIndex = 0 + dataHashCode = 1568746155 + size = 13 + isKeyFrame = true + presentationTimeUs = 45500 +sample: + trackIndex = 0 + dataHashCode = 1355412472 + size = 13 + isKeyFrame = true + presentationTimeUs = 46313 +sample: + trackIndex = 0 + dataHashCode = 1546368465 + size = 13 + isKeyFrame = true + presentationTimeUs = 47125 +sample: + trackIndex = 0 + dataHashCode = 1811529381 + size = 13 + isKeyFrame = true + presentationTimeUs = 47938 +sample: + trackIndex = 0 + dataHashCode = 658031078 + size = 13 + isKeyFrame = true + presentationTimeUs = 48750 +sample: + trackIndex = 0 + dataHashCode = 1606584486 + size = 13 + isKeyFrame = true + presentationTimeUs = 49563 +sample: + trackIndex = 0 + dataHashCode = 2123252778 + size = 13 + isKeyFrame = true + presentationTimeUs = 50375 +sample: + trackIndex = 0 + dataHashCode = -1364579398 + size = 13 + isKeyFrame = true + presentationTimeUs = 51188 +sample: + trackIndex = 0 + dataHashCode = 1311427887 + size = 13 + isKeyFrame = true + presentationTimeUs = 52000 +sample: + trackIndex = 0 + dataHashCode = -691467569 + size = 13 + isKeyFrame = true + presentationTimeUs = 52813 +sample: + trackIndex = 0 + dataHashCode = 1876470084 + size = 13 + isKeyFrame = true + presentationTimeUs = 53625 +sample: + trackIndex = 0 + dataHashCode = -1472873479 + size = 13 + isKeyFrame = true + presentationTimeUs = 54438 +sample: + trackIndex = 0 + dataHashCode = -143574992 + size = 13 + isKeyFrame = true + presentationTimeUs = 55250 +sample: + trackIndex = 0 + dataHashCode = 984180453 + size = 13 + isKeyFrame = true + presentationTimeUs = 56063 +sample: + trackIndex = 0 + dataHashCode = -113645527 + size = 13 + isKeyFrame = true + presentationTimeUs = 56875 +sample: + trackIndex = 0 + dataHashCode = 1987501641 + size = 13 + isKeyFrame = true + presentationTimeUs = 57688 +sample: + trackIndex = 0 + dataHashCode = -1816426230 + size = 13 + isKeyFrame = true + presentationTimeUs = 58500 +sample: + trackIndex = 0 + dataHashCode = -1250050360 + size = 13 + isKeyFrame = true + presentationTimeUs = 59313 +sample: + trackIndex = 0 + dataHashCode = 1722852790 + size = 13 + isKeyFrame = true + presentationTimeUs = 60125 +sample: + trackIndex = 0 + dataHashCode = 225656333 + size = 13 + isKeyFrame = true + presentationTimeUs = 60938 +sample: + trackIndex = 0 + dataHashCode = -2137778394 + size = 13 + isKeyFrame = true + presentationTimeUs = 61750 +sample: + trackIndex = 0 + dataHashCode = 1433327155 + size = 13 + isKeyFrame = true + presentationTimeUs = 62563 +sample: + trackIndex = 0 + dataHashCode = -974261023 + size = 13 + isKeyFrame = true + presentationTimeUs = 63375 +sample: + trackIndex = 0 + dataHashCode = 1797813317 + size = 13 + isKeyFrame = true + presentationTimeUs = 64188 +sample: + trackIndex = 0 + dataHashCode = -594033497 + size = 13 + isKeyFrame = true + presentationTimeUs = 65000 +sample: + trackIndex = 0 + dataHashCode = -628310540 + size = 13 + isKeyFrame = true + presentationTimeUs = 65813 +sample: + trackIndex = 0 + dataHashCode = 1868627831 + size = 13 + isKeyFrame = true + presentationTimeUs = 66625 +sample: + trackIndex = 0 + dataHashCode = 1051863958 + size = 13 + isKeyFrame = true + presentationTimeUs = 67438 +sample: + trackIndex = 0 + dataHashCode = -1279059211 + size = 13 + isKeyFrame = true + presentationTimeUs = 68250 +sample: + trackIndex = 0 + dataHashCode = 408201874 + size = 13 + isKeyFrame = true + presentationTimeUs = 69063 +sample: + trackIndex = 0 + dataHashCode = 1686644299 + size = 13 + isKeyFrame = true + presentationTimeUs = 69875 +sample: + trackIndex = 0 + dataHashCode = 1288226241 + size = 13 + isKeyFrame = true + presentationTimeUs = 70688 +sample: + trackIndex = 0 + dataHashCode = 432829731 + size = 13 + isKeyFrame = true + presentationTimeUs = 71500 +sample: + trackIndex = 0 + dataHashCode = -1679312600 + size = 13 + isKeyFrame = true + presentationTimeUs = 72313 +sample: + trackIndex = 0 + dataHashCode = 1206680829 + size = 13 + isKeyFrame = true + presentationTimeUs = 73125 +sample: + trackIndex = 0 + dataHashCode = -325844704 + size = 13 + isKeyFrame = true + presentationTimeUs = 73938 +sample: + trackIndex = 0 + dataHashCode = 1941808848 + size = 13 + isKeyFrame = true + presentationTimeUs = 74750 +sample: + trackIndex = 0 + dataHashCode = -87346412 + size = 13 + isKeyFrame = true + presentationTimeUs = 75563 +sample: + trackIndex = 0 + dataHashCode = -329133765 + size = 13 + isKeyFrame = true + presentationTimeUs = 76375 +sample: + trackIndex = 0 + dataHashCode = -1299416212 + size = 13 + isKeyFrame = true + presentationTimeUs = 77188 +sample: + trackIndex = 0 + dataHashCode = -1314599219 + size = 13 + isKeyFrame = true + presentationTimeUs = 78000 +sample: + trackIndex = 0 + dataHashCode = 1456741286 + size = 13 + isKeyFrame = true + presentationTimeUs = 78813 +sample: + trackIndex = 0 + dataHashCode = 151296500 + size = 13 + isKeyFrame = true + presentationTimeUs = 79625 +sample: + trackIndex = 0 + dataHashCode = 1708763603 + size = 13 + isKeyFrame = true + presentationTimeUs = 80438 +sample: + trackIndex = 0 + dataHashCode = 227542220 + size = 13 + isKeyFrame = true + presentationTimeUs = 81250 +sample: + trackIndex = 0 + dataHashCode = 1094305517 + size = 13 + isKeyFrame = true + presentationTimeUs = 82063 +sample: + trackIndex = 0 + dataHashCode = -990377604 + size = 13 + isKeyFrame = true + presentationTimeUs = 82875 +sample: + trackIndex = 0 + dataHashCode = -1798036230 + size = 13 + isKeyFrame = true + presentationTimeUs = 83688 +sample: + trackIndex = 0 + dataHashCode = -1027148291 + size = 13 + isKeyFrame = true + presentationTimeUs = 84500 +sample: + trackIndex = 0 + dataHashCode = 359763976 + size = 13 + isKeyFrame = true + presentationTimeUs = 85313 +sample: + trackIndex = 0 + dataHashCode = 1332016420 + size = 13 + isKeyFrame = true + presentationTimeUs = 86125 +sample: + trackIndex = 0 + dataHashCode = -102753250 + size = 13 + isKeyFrame = true + presentationTimeUs = 86938 +sample: + trackIndex = 0 + dataHashCode = 1959063156 + size = 13 + isKeyFrame = true + presentationTimeUs = 87750 +sample: + trackIndex = 0 + dataHashCode = 2129089853 + size = 13 + isKeyFrame = true + presentationTimeUs = 88563 +sample: + trackIndex = 0 + dataHashCode = 1658742073 + size = 13 + isKeyFrame = true + presentationTimeUs = 89375 +sample: + trackIndex = 0 + dataHashCode = 2136916514 + size = 13 + isKeyFrame = true + presentationTimeUs = 90188 +sample: + trackIndex = 0 + dataHashCode = 105121407 + size = 13 + isKeyFrame = true + presentationTimeUs = 91000 +sample: + trackIndex = 0 + dataHashCode = -839464484 + size = 13 + isKeyFrame = true + presentationTimeUs = 91813 +sample: + trackIndex = 0 + dataHashCode = -1956791168 + size = 13 + isKeyFrame = true + presentationTimeUs = 92625 +sample: + trackIndex = 0 + dataHashCode = -1387546109 + size = 13 + isKeyFrame = true + presentationTimeUs = 93438 +sample: + trackIndex = 0 + dataHashCode = 128410432 + size = 13 + isKeyFrame = true + presentationTimeUs = 94250 +sample: + trackIndex = 0 + dataHashCode = 907081136 + size = 13 + isKeyFrame = true + presentationTimeUs = 95063 +sample: + trackIndex = 0 + dataHashCode = 1124845067 + size = 13 + isKeyFrame = true + presentationTimeUs = 95875 +sample: + trackIndex = 0 + dataHashCode = -1714479962 + size = 13 + isKeyFrame = true + presentationTimeUs = 96688 +sample: + trackIndex = 0 + dataHashCode = 322029323 + size = 13 + isKeyFrame = true + presentationTimeUs = 97500 +sample: + trackIndex = 0 + dataHashCode = -1116281187 + size = 13 + isKeyFrame = true + presentationTimeUs = 98313 +sample: + trackIndex = 0 + dataHashCode = 1571181228 + size = 13 + isKeyFrame = true + presentationTimeUs = 99125 +sample: + trackIndex = 0 + dataHashCode = 997979854 + size = 13 + isKeyFrame = true + presentationTimeUs = 99938 +sample: + trackIndex = 0 + dataHashCode = -1413492413 + size = 13 + isKeyFrame = true + presentationTimeUs = 100750 +sample: + trackIndex = 0 + dataHashCode = -381390490 + size = 13 + isKeyFrame = true + presentationTimeUs = 101563 +sample: + trackIndex = 0 + dataHashCode = -331348340 + size = 13 + isKeyFrame = true + presentationTimeUs = 102375 +sample: + trackIndex = 0 + dataHashCode = -1568238592 + size = 13 + isKeyFrame = true + presentationTimeUs = 103188 +sample: + trackIndex = 0 + dataHashCode = -941591445 + size = 13 + isKeyFrame = true + presentationTimeUs = 104000 +sample: + trackIndex = 0 + dataHashCode = 1616911281 + size = 13 + isKeyFrame = true + presentationTimeUs = 104813 +sample: + trackIndex = 0 + dataHashCode = -1755664741 + size = 13 + isKeyFrame = true + presentationTimeUs = 105625 +sample: + trackIndex = 0 + dataHashCode = -1950609742 + size = 13 + isKeyFrame = true + presentationTimeUs = 106438 +sample: + trackIndex = 0 + dataHashCode = 1476082149 + size = 13 + isKeyFrame = true + presentationTimeUs = 107250 +sample: + trackIndex = 0 + dataHashCode = 1289547483 + size = 13 + isKeyFrame = true + presentationTimeUs = 108063 +sample: + trackIndex = 0 + dataHashCode = -367599018 + size = 13 + isKeyFrame = true + presentationTimeUs = 108875 +sample: + trackIndex = 0 + dataHashCode = 679378334 + size = 13 + isKeyFrame = true + presentationTimeUs = 109688 +sample: + trackIndex = 0 + dataHashCode = 1437306809 + size = 13 + isKeyFrame = true + presentationTimeUs = 110500 +sample: + trackIndex = 0 + dataHashCode = 311988463 + size = 13 + isKeyFrame = true + presentationTimeUs = 111313 +sample: + trackIndex = 0 + dataHashCode = -1870442665 + size = 13 + isKeyFrame = true + presentationTimeUs = 112125 +sample: + trackIndex = 0 + dataHashCode = 1530013920 + size = 13 + isKeyFrame = true + presentationTimeUs = 112938 +sample: + trackIndex = 0 + dataHashCode = -585506443 + size = 13 + isKeyFrame = true + presentationTimeUs = 113750 +sample: + trackIndex = 0 + dataHashCode = -293690558 + size = 13 + isKeyFrame = true + presentationTimeUs = 114563 +sample: + trackIndex = 0 + dataHashCode = -616893325 + size = 13 + isKeyFrame = true + presentationTimeUs = 115375 +sample: + trackIndex = 0 + dataHashCode = 632210495 + size = 13 + isKeyFrame = true + presentationTimeUs = 116188 +sample: + trackIndex = 0 + dataHashCode = -291767937 + size = 13 + isKeyFrame = true + presentationTimeUs = 117000 +sample: + trackIndex = 0 + dataHashCode = -270265 + size = 13 + isKeyFrame = true + presentationTimeUs = 117813 +sample: + trackIndex = 0 + dataHashCode = -1095959376 + size = 13 + isKeyFrame = true + presentationTimeUs = 118625 +sample: + trackIndex = 0 + dataHashCode = -1363867284 + size = 13 + isKeyFrame = true + presentationTimeUs = 119438 +sample: + trackIndex = 0 + dataHashCode = 185415707 + size = 13 + isKeyFrame = true + presentationTimeUs = 120250 +sample: + trackIndex = 0 + dataHashCode = 1033720098 + size = 13 + isKeyFrame = true + presentationTimeUs = 121063 +sample: + trackIndex = 0 + dataHashCode = 1813896085 + size = 13 + isKeyFrame = true + presentationTimeUs = 121875 +sample: + trackIndex = 0 + dataHashCode = -1381192241 + size = 13 + isKeyFrame = true + presentationTimeUs = 122688 +sample: + trackIndex = 0 + dataHashCode = 362689054 + size = 13 + isKeyFrame = true + presentationTimeUs = 123500 +sample: + trackIndex = 0 + dataHashCode = -1320787356 + size = 13 + isKeyFrame = true + presentationTimeUs = 124313 +sample: + trackIndex = 0 + dataHashCode = 1306489379 + size = 13 + isKeyFrame = true + presentationTimeUs = 125125 +sample: + trackIndex = 0 + dataHashCode = -910313430 + size = 13 + isKeyFrame = true + presentationTimeUs = 125938 +sample: + trackIndex = 0 + dataHashCode = -1533334115 + size = 13 + isKeyFrame = true + presentationTimeUs = 126750 +sample: + trackIndex = 0 + dataHashCode = -700061723 + size = 13 + isKeyFrame = true + presentationTimeUs = 127563 +sample: + trackIndex = 0 + dataHashCode = 474100444 + size = 13 + isKeyFrame = true + presentationTimeUs = 128375 +sample: + trackIndex = 0 + dataHashCode = -2096659943 + size = 13 + isKeyFrame = true + presentationTimeUs = 129188 +sample: + trackIndex = 0 + dataHashCode = -690442126 + size = 13 + isKeyFrame = true + presentationTimeUs = 130000 +sample: + trackIndex = 0 + dataHashCode = 158718784 + size = 13 + isKeyFrame = true + presentationTimeUs = 130813 +sample: + trackIndex = 0 + dataHashCode = -1587553019 + size = 13 + isKeyFrame = true + presentationTimeUs = 131625 +sample: + trackIndex = 0 + dataHashCode = 1266916929 + size = 13 + isKeyFrame = true + presentationTimeUs = 132438 +sample: + trackIndex = 0 + dataHashCode = 1947792537 + size = 13 + isKeyFrame = true + presentationTimeUs = 133250 +sample: + trackIndex = 0 + dataHashCode = 2051622372 + size = 13 + isKeyFrame = true + presentationTimeUs = 134063 +sample: + trackIndex = 0 + dataHashCode = 1648973196 + size = 13 + isKeyFrame = true + presentationTimeUs = 134875 +sample: + trackIndex = 0 + dataHashCode = -1119069213 + size = 13 + isKeyFrame = true + presentationTimeUs = 135688 +sample: + trackIndex = 0 + dataHashCode = -1162670307 + size = 13 + isKeyFrame = true + presentationTimeUs = 136500 +sample: + trackIndex = 0 + dataHashCode = 505180178 + size = 13 + isKeyFrame = true + presentationTimeUs = 137313 +sample: + trackIndex = 0 + dataHashCode = -1707111799 + size = 13 + isKeyFrame = true + presentationTimeUs = 138125 +sample: + trackIndex = 0 + dataHashCode = 549350779 + size = 13 + isKeyFrame = true + presentationTimeUs = 138938 +sample: + trackIndex = 0 + dataHashCode = -895461091 + size = 13 + isKeyFrame = true + presentationTimeUs = 139750 +sample: + trackIndex = 0 + dataHashCode = 1834306839 + size = 13 + isKeyFrame = true + presentationTimeUs = 140563 +sample: + trackIndex = 0 + dataHashCode = -646169807 + size = 13 + isKeyFrame = true + presentationTimeUs = 141375 +sample: + trackIndex = 0 + dataHashCode = 123454915 + size = 13 + isKeyFrame = true + presentationTimeUs = 142188 +sample: + trackIndex = 0 + dataHashCode = 2074179659 + size = 13 + isKeyFrame = true + presentationTimeUs = 143000 +sample: + trackIndex = 0 + dataHashCode = 488070546 + size = 13 + isKeyFrame = true + presentationTimeUs = 143813 +sample: + trackIndex = 0 + dataHashCode = -1379245827 + size = 13 + isKeyFrame = true + presentationTimeUs = 144625 +sample: + trackIndex = 0 + dataHashCode = 922846867 + size = 13 + isKeyFrame = true + presentationTimeUs = 145438 +sample: + trackIndex = 0 + dataHashCode = 1163092079 + size = 13 + isKeyFrame = true + presentationTimeUs = 146250 +sample: + trackIndex = 0 + dataHashCode = -817674907 + size = 13 + isKeyFrame = true + presentationTimeUs = 147063 +sample: + trackIndex = 0 + dataHashCode = -765143209 + size = 13 + isKeyFrame = true + presentationTimeUs = 147875 +sample: + trackIndex = 0 + dataHashCode = 1337234415 + size = 13 + isKeyFrame = true + presentationTimeUs = 148688 +sample: + trackIndex = 0 + dataHashCode = 152696122 + size = 13 + isKeyFrame = true + presentationTimeUs = 149500 +sample: + trackIndex = 0 + dataHashCode = -1037369189 + size = 13 + isKeyFrame = true + presentationTimeUs = 150313 +sample: + trackIndex = 0 + dataHashCode = 93852784 + size = 13 + isKeyFrame = true + presentationTimeUs = 151125 +sample: + trackIndex = 0 + dataHashCode = -1512860804 + size = 13 + isKeyFrame = true + presentationTimeUs = 151938 +sample: + trackIndex = 0 + dataHashCode = -1571797975 + size = 13 + isKeyFrame = true + presentationTimeUs = 152750 +sample: + trackIndex = 0 + dataHashCode = -1390710594 + size = 13 + isKeyFrame = true + presentationTimeUs = 153563 +sample: + trackIndex = 0 + dataHashCode = 775548254 + size = 13 + isKeyFrame = true + presentationTimeUs = 154375 +sample: + trackIndex = 0 + dataHashCode = 329825934 + size = 13 + isKeyFrame = true + presentationTimeUs = 155188 +sample: + trackIndex = 0 + dataHashCode = 449672203 + size = 13 + isKeyFrame = true + presentationTimeUs = 156000 +sample: + trackIndex = 0 + dataHashCode = 135215283 + size = 13 + isKeyFrame = true + presentationTimeUs = 156813 +sample: + trackIndex = 0 + dataHashCode = -627202145 + size = 13 + isKeyFrame = true + presentationTimeUs = 157625 +sample: + trackIndex = 0 + dataHashCode = 565795710 + size = 13 + isKeyFrame = true + presentationTimeUs = 158438 +sample: + trackIndex = 0 + dataHashCode = -853390981 + size = 13 + isKeyFrame = true + presentationTimeUs = 159250 +sample: + trackIndex = 0 + dataHashCode = 1904980829 + size = 13 + isKeyFrame = true + presentationTimeUs = 160063 +sample: + trackIndex = 0 + dataHashCode = 1772857005 + size = 13 + isKeyFrame = true + presentationTimeUs = 160875 +sample: + trackIndex = 0 + dataHashCode = -1159621303 + size = 13 + isKeyFrame = true + presentationTimeUs = 161688 +sample: + trackIndex = 0 + dataHashCode = 712585139 + size = 13 + isKeyFrame = true + presentationTimeUs = 162500 +sample: + trackIndex = 0 + dataHashCode = 7470296 + size = 13 + isKeyFrame = true + presentationTimeUs = 163313 +sample: + trackIndex = 0 + dataHashCode = 1154659763 + size = 13 + isKeyFrame = true + presentationTimeUs = 164125 +sample: + trackIndex = 0 + dataHashCode = 512209179 + size = 13 + isKeyFrame = true + presentationTimeUs = 164938 +sample: + trackIndex = 0 + dataHashCode = 2026712081 + size = 13 + isKeyFrame = true + presentationTimeUs = 165750 +sample: + trackIndex = 0 + dataHashCode = -1625715216 + size = 13 + isKeyFrame = true + presentationTimeUs = 166563 +sample: + trackIndex = 0 + dataHashCode = -1299058326 + size = 13 + isKeyFrame = true + presentationTimeUs = 167375 +sample: + trackIndex = 0 + dataHashCode = -813560096 + size = 13 + isKeyFrame = true + presentationTimeUs = 168188 +sample: + trackIndex = 0 + dataHashCode = 1311045251 + size = 13 + isKeyFrame = true + presentationTimeUs = 169000 +sample: + trackIndex = 0 + dataHashCode = 1388107407 + size = 13 + isKeyFrame = true + presentationTimeUs = 169813 +sample: + trackIndex = 0 + dataHashCode = 1113099440 + size = 13 + isKeyFrame = true + presentationTimeUs = 170625 +sample: + trackIndex = 0 + dataHashCode = -339743582 + size = 13 + isKeyFrame = true + presentationTimeUs = 171438 +sample: + trackIndex = 0 + dataHashCode = -1055895345 + size = 13 + isKeyFrame = true + presentationTimeUs = 172250 +sample: + trackIndex = 0 + dataHashCode = 1869841923 + size = 13 + isKeyFrame = true + presentationTimeUs = 173063 +sample: + trackIndex = 0 + dataHashCode = 229443301 + size = 13 + isKeyFrame = true + presentationTimeUs = 173875 +sample: + trackIndex = 0 + dataHashCode = 1526951012 + size = 13 + isKeyFrame = true + presentationTimeUs = 174688 +sample: + trackIndex = 0 + dataHashCode = -1517436626 + size = 13 + isKeyFrame = true + presentationTimeUs = 175500 +sample: + trackIndex = 0 + dataHashCode = -1403405700 + size = 13 + isKeyFrame = true + presentationTimeUs = 176313 +released = true diff --git a/libraries/test_data/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump b/libraries/test_data/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump index bf39e2d187..e8c74ad532 100644 --- a/libraries/test_data/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump +++ b/libraries/test_data/src/test/assets/transformerdumps/mkv/sample_with_srt.mkv.dump @@ -1,5 +1,10 @@ containerMimeType = video/mp4 format 0: + sampleMimeType = audio/mp4a-latm + channelCount = 1 + sampleRate = 44100 + pcmEncoding = 2 +format 1: id = 1 sampleMimeType = video/avc codecs = avc1.640034 @@ -11,181 +16,355 @@ format 0: data = length 30, hash F6F3D010 data = length 10, hash 7A0D0F2B sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -252482306 size = 36477 isKeyFrame = true presentationTimeUs = 0 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 67864034 size = 5341 isKeyFrame = false presentationTimeUs = 67000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 897273234 size = 596 isKeyFrame = false presentationTimeUs = 33000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1549870586 size = 7704 isKeyFrame = false presentationTimeUs = 200000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 672384813 size = 989 isKeyFrame = false presentationTimeUs = 133000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -988996493 size = 721 isKeyFrame = false presentationTimeUs = 100000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1711151377 size = 519 isKeyFrame = false presentationTimeUs = 167000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -506806036 size = 6160 isKeyFrame = false presentationTimeUs = 333000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1902167649 size = 953 isKeyFrame = false presentationTimeUs = 267000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 2054873212 size = 620 isKeyFrame = false presentationTimeUs = 233000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1556608231 size = 405 isKeyFrame = false presentationTimeUs = 300000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1648978019 size = 4852 isKeyFrame = false presentationTimeUs = 433000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -484808327 size = 547 isKeyFrame = false presentationTimeUs = 400000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -20706048 size = 570 isKeyFrame = false presentationTimeUs = 367000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 2085064574 size = 5525 isKeyFrame = false presentationTimeUs = 567000 sample: trackIndex = 0 + dataHashCode = 555688582 + size = 416 + isKeyFrame = true + presentationTimeUs = 0 +sample: + trackIndex = 0 + dataHashCode = 2000837254 + size = 418 + isKeyFrame = true + presentationTimeUs = 4717 +sample: + trackIndex = 0 + dataHashCode = -1593942879 + size = 418 + isKeyFrame = true + presentationTimeUs = 9456 +sample: + trackIndex = 0 + dataHashCode = 587837542 + size = 418 + isKeyFrame = true + presentationTimeUs = 14196 +sample: + trackIndex = 0 + dataHashCode = -1836423877 + size = 418 + isKeyFrame = true + presentationTimeUs = 18935 +sample: + trackIndex = 0 + dataHashCode = 874705099 + size = 418 + isKeyFrame = true + presentationTimeUs = 23674 +sample: + trackIndex = 0 + dataHashCode = -269206181 + size = 418 + isKeyFrame = true + presentationTimeUs = 28413 +sample: + trackIndex = 0 + dataHashCode = -58682425 + size = 418 + isKeyFrame = true + presentationTimeUs = 33152 +sample: + trackIndex = 0 + dataHashCode = -859796970 + size = 418 + isKeyFrame = true + presentationTimeUs = 37892 +sample: + trackIndex = 0 + dataHashCode = 711911523 + size = 418 + isKeyFrame = true + presentationTimeUs = 42631 +sample: + trackIndex = 0 + dataHashCode = -694513071 + size = 418 + isKeyFrame = true + presentationTimeUs = 47370 +sample: + trackIndex = 0 + dataHashCode = -1124371059 + size = 418 + isKeyFrame = true + presentationTimeUs = 52109 +sample: + trackIndex = 0 + dataHashCode = 297166745 + size = 418 + isKeyFrame = true + presentationTimeUs = 56849 +sample: + trackIndex = 0 + dataHashCode = -937110638 + size = 418 + isKeyFrame = true + presentationTimeUs = 61588 +sample: + trackIndex = 0 + dataHashCode = -1050158990 + size = 418 + isKeyFrame = true + presentationTimeUs = 66327 +sample: + trackIndex = 0 + dataHashCode = 1109510229 + size = 418 + isKeyFrame = true + presentationTimeUs = 71066 +sample: + trackIndex = 0 + dataHashCode = 1297086772 + size = 418 + isKeyFrame = true + presentationTimeUs = 75805 +sample: + trackIndex = 0 + dataHashCode = -1739939803 + size = 418 + isKeyFrame = true + presentationTimeUs = 80545 +sample: + trackIndex = 0 + dataHashCode = -1149727930 + size = 418 + isKeyFrame = true + presentationTimeUs = 85284 +sample: + trackIndex = 0 + dataHashCode = -1627652713 + size = 418 + isKeyFrame = true + presentationTimeUs = 90023 +sample: + trackIndex = 0 + dataHashCode = -551926260 + size = 418 + isKeyFrame = true + presentationTimeUs = 94762 +sample: + trackIndex = 0 + dataHashCode = 45987178 + size = 418 + isKeyFrame = true + presentationTimeUs = 99502 +sample: + trackIndex = 0 + dataHashCode = -903675808 + size = 418 + isKeyFrame = true + presentationTimeUs = 104241 +sample: + trackIndex = 0 + dataHashCode = -755916991 + size = 418 + isKeyFrame = true + presentationTimeUs = 108980 +sample: + trackIndex = 0 + dataHashCode = -1355207303 + size = 418 + isKeyFrame = true + presentationTimeUs = 113719 +sample: + trackIndex = 0 + dataHashCode = -975703389 + size = 418 + isKeyFrame = true + presentationTimeUs = 118459 +sample: + trackIndex = 0 + dataHashCode = 1933194670 + size = 418 + isKeyFrame = true + presentationTimeUs = 123198 +sample: + trackIndex = 0 + dataHashCode = -565778989 + size = 418 + isKeyFrame = true + presentationTimeUs = 127937 +sample: + trackIndex = 0 + dataHashCode = 1454083383 + size = 418 + isKeyFrame = true + presentationTimeUs = 132676 +sample: + trackIndex = 1 dataHashCode = -637074022 size = 1082 isKeyFrame = false presentationTimeUs = 500000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1824027029 size = 807 isKeyFrame = false presentationTimeUs = 467000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1701945306 size = 744 isKeyFrame = false presentationTimeUs = 533000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -952425536 size = 4732 isKeyFrame = false presentationTimeUs = 700000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1978031576 size = 1004 isKeyFrame = false presentationTimeUs = 633000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -2128215508 size = 794 isKeyFrame = false presentationTimeUs = 600000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -259850011 size = 645 isKeyFrame = false presentationTimeUs = 667000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1920983928 size = 2684 isKeyFrame = false presentationTimeUs = 833000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1100642337 size = 787 isKeyFrame = false presentationTimeUs = 767000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 1544917830 size = 649 isKeyFrame = false presentationTimeUs = 733000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -116205995 size = 509 isKeyFrame = false presentationTimeUs = 800000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = 696343585 size = 1226 isKeyFrame = false presentationTimeUs = 967000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -644371190 size = 898 isKeyFrame = false presentationTimeUs = 900000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -1606273467 size = 476 isKeyFrame = false presentationTimeUs = 867000 sample: - trackIndex = 0 + trackIndex = 1 dataHashCode = -571265861 size = 486 isKeyFrame = false diff --git a/libraries/test_data/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.dump b/libraries/test_data/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.dump new file mode 100644 index 0000000000..b8105aafea --- /dev/null +++ b/libraries/test_data/src/test/assets/transformerdumps/mp4/sample_18byte_nclx_colr.mp4.dump @@ -0,0 +1,198 @@ +containerMimeType = video/mp4 +format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B +sample: + trackIndex = 0 + dataHashCode = -770308242 + size = 36692 + isKeyFrame = true + presentationTimeUs = 0 +sample: + trackIndex = 0 + dataHashCode = -732087136 + size = 5312 + isKeyFrame = false + presentationTimeUs = 66733 +sample: + trackIndex = 0 + dataHashCode = 468156717 + size = 599 + isKeyFrame = false + presentationTimeUs = 33366 +sample: + trackIndex = 0 + dataHashCode = 1150349584 + size = 7735 + isKeyFrame = false + presentationTimeUs = 200200 +sample: + trackIndex = 0 + dataHashCode = 1443582006 + size = 987 + isKeyFrame = false + presentationTimeUs = 133466 +sample: + trackIndex = 0 + dataHashCode = -310585145 + size = 673 + isKeyFrame = false + presentationTimeUs = 100100 +sample: + trackIndex = 0 + dataHashCode = 807460688 + size = 523 + isKeyFrame = false + presentationTimeUs = 166833 +sample: + trackIndex = 0 + dataHashCode = 1936487090 + size = 6061 + isKeyFrame = false + presentationTimeUs = 333666 +sample: + trackIndex = 0 + dataHashCode = -32297181 + size = 992 + isKeyFrame = false + presentationTimeUs = 266933 +sample: + trackIndex = 0 + dataHashCode = 1529616406 + size = 623 + isKeyFrame = false + presentationTimeUs = 233566 +sample: + trackIndex = 0 + dataHashCode = 1949198785 + size = 421 + isKeyFrame = false + presentationTimeUs = 300300 +sample: + trackIndex = 0 + dataHashCode = -147880287 + size = 4899 + isKeyFrame = false + presentationTimeUs = 433766 +sample: + trackIndex = 0 + dataHashCode = 1369083472 + size = 568 + isKeyFrame = false + presentationTimeUs = 400400 +sample: + trackIndex = 0 + dataHashCode = 965782073 + size = 620 + isKeyFrame = false + presentationTimeUs = 367033 +sample: + trackIndex = 0 + dataHashCode = -261176150 + size = 5450 + isKeyFrame = false + presentationTimeUs = 567233 +sample: + trackIndex = 0 + dataHashCode = -1830836678 + size = 1051 + isKeyFrame = false + presentationTimeUs = 500500 +sample: + trackIndex = 0 + dataHashCode = 1767407540 + size = 874 + isKeyFrame = false + presentationTimeUs = 467133 +sample: + trackIndex = 0 + dataHashCode = 918440283 + size = 781 + isKeyFrame = false + presentationTimeUs = 533866 +sample: + trackIndex = 0 + dataHashCode = -1408463661 + size = 4725 + isKeyFrame = false + presentationTimeUs = 700700 +sample: + trackIndex = 0 + dataHashCode = 1569455924 + size = 1022 + isKeyFrame = false + presentationTimeUs = 633966 +sample: + trackIndex = 0 + dataHashCode = -1723778407 + size = 790 + isKeyFrame = false + presentationTimeUs = 600600 +sample: + trackIndex = 0 + dataHashCode = 1578275472 + size = 610 + isKeyFrame = false + presentationTimeUs = 667333 +sample: + trackIndex = 0 + dataHashCode = 1989768395 + size = 2751 + isKeyFrame = false + presentationTimeUs = 834166 +sample: + trackIndex = 0 + dataHashCode = -1215674502 + size = 745 + isKeyFrame = false + presentationTimeUs = 767433 +sample: + trackIndex = 0 + dataHashCode = -814473606 + size = 621 + isKeyFrame = false + presentationTimeUs = 734066 +sample: + trackIndex = 0 + dataHashCode = 498370894 + size = 505 + isKeyFrame = false + presentationTimeUs = 800800 +sample: + trackIndex = 0 + dataHashCode = -1051506468 + size = 1268 + isKeyFrame = false + presentationTimeUs = 967633 +sample: + trackIndex = 0 + dataHashCode = -1025604144 + size = 880 + isKeyFrame = false + presentationTimeUs = 900900 +sample: + trackIndex = 0 + dataHashCode = -913586520 + size = 530 + isKeyFrame = false + presentationTimeUs = 867533 +sample: + trackIndex = 0 + dataHashCode = 1340459242 + size = 568 + isKeyFrame = false + presentationTimeUs = 934266 +released = true diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationException.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationException.java index 4a8f86cdd8..721f9d66fe 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationException.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationException.java @@ -161,6 +161,16 @@ public final class TransformationException extends Exception { /** Caused by an audio processor initialization failure. */ public static final int ERROR_CODE_AUDIO_PROCESSOR_INIT_FAILED = 6001; + // Muxing errors (7xxx). + + /** + * Caused by an output sample MIME type inferred from the input not being supported by the muxer. + * + *

Use {@link TransformationRequest.Builder#setAudioMimeType(String)} or {@link + * TransformationRequest.Builder#setVideoMimeType(String)} to transcode to a supported MIME type. + */ + public static final int ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED = 7001; + private static final ImmutableBiMap NAME_TO_ERROR_CODE = new ImmutableBiMap.Builder() .put("ERROR_CODE_FAILED_RUNTIME_CHECK", ERROR_CODE_FAILED_RUNTIME_CHECK) @@ -182,6 +192,9 @@ public final class TransformationException extends Exception { .put("ERROR_CODE_GL_INIT_FAILED", ERROR_CODE_GL_INIT_FAILED) .put("ERROR_CODE_GL_PROCESSING_FAILED", ERROR_CODE_GL_PROCESSING_FAILED) .put("ERROR_CODE_AUDIO_PROCESSOR_INIT_FAILED", ERROR_CODE_AUDIO_PROCESSOR_INIT_FAILED) + .put( + "ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED", + ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED) .buildOrThrow(); /** Returns the {@code errorCode} for a given name. */ @@ -232,6 +245,17 @@ public final class TransformationException extends Exception { componentName + " error, audio_format = " + audioFormat, cause, errorCode); } + /** + * Creates an instance for a muxer related exception. + * + * @param cause The cause of the failure. + * @param errorCode See {@link #errorCode}. + * @return The created instance. + */ + /* package */ static TransformationException createForMuxer(Throwable cause, int errorCode) { + return new TransformationException("Muxer error", cause, errorCode); + } + /** * Creates an instance for an unexpected exception. * diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java index a95ea82720..c46956b722 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/Transformer.java @@ -808,13 +808,9 @@ public final class Transformer { @Override public void onTracksInfoChanged(TracksInfo tracksInfo) { if (muxerWrapper.getTrackCount() == 0) { - // TODO(b/209469847): Do not silently drop unsupported tracks and throw a more specific - // exception earlier. handleTransformationEnded( TransformationException.createForUnexpected( - new IllegalStateException( - "The output does not contain any tracks. Check that at least one of the input" - + " sample formats is supported."))); + new IllegalStateException("The output does not contain any tracks."))); } } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerBaseRenderer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerBaseRenderer.java index e460e253d5..07cf87343e 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerBaseRenderer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerBaseRenderer.java @@ -16,6 +16,7 @@ package androidx.media3.transformer; +import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkStateNotNull; import androidx.annotation.Nullable; @@ -57,26 +58,46 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; this.transformationRequest = transformationRequest; } + /** + * Returns whether the renderer supports the track type of the given input format. + * + * @param inputFormat The input format. + * @return The {@link Capabilities} for this format. + * @throws ExoPlaybackException If the muxer does not support the output sample MIME type derived + * from the input {@code format} and {@link TransformationRequest}. + */ @Override - @C.FormatSupport - public final int supportsFormat(Format format) { - @Nullable String sampleMimeType = format.sampleMimeType; - if (MimeTypes.getTrackType(sampleMimeType) != getTrackType()) { + @Capabilities + public final int supportsFormat(Format inputFormat) throws ExoPlaybackException { + @Nullable String inputSampleMimeType = inputFormat.sampleMimeType; + if (inputSampleMimeType == null + || MimeTypes.getTrackType(inputSampleMimeType) != getTrackType()) { return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_TYPE); - } else if ((MimeTypes.isAudio(sampleMimeType) - && muxerWrapper.supportsSampleMimeType( - transformationRequest.audioMimeType == null - ? sampleMimeType - : transformationRequest.audioMimeType)) - || (MimeTypes.isVideo(sampleMimeType) - && muxerWrapper.supportsSampleMimeType( - transformationRequest.videoMimeType == null - ? sampleMimeType - : transformationRequest.videoMimeType))) { - return RendererCapabilities.create(C.FORMAT_HANDLED); - } else { - return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE); } + + // If the output sample MIME type is given in the transformationRequest it has already been + // validated by the builder. + if (MimeTypes.isAudio(inputSampleMimeType) && transformationRequest.audioMimeType != null) { + checkState(muxerWrapper.supportsSampleMimeType(transformationRequest.audioMimeType)); + return RendererCapabilities.create(C.FORMAT_HANDLED); + } + if (MimeTypes.isVideo(inputSampleMimeType) && transformationRequest.videoMimeType != null) { + checkState(muxerWrapper.supportsSampleMimeType(transformationRequest.videoMimeType)); + return RendererCapabilities.create(C.FORMAT_HANDLED); + } + + // When the output sample MIME type is not given in the transformationRequest, it is inferred + // from the input. + if (muxerWrapper.supportsSampleMimeType(inputSampleMimeType)) { + return RendererCapabilities.create(C.FORMAT_HANDLED); + } + throw wrapTransformationException( + TransformationException.createForMuxer( + new IllegalArgumentException( + "The sample MIME inferred from the input is not supported by the muxer. " + + "Input sample MIME type: " + + inputSampleMimeType), + TransformationException.ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED)); } @Override @@ -103,16 +124,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; while (feedMuxerFromPipeline() || samplePipeline.processData() || feedPipelineFromInput()) {} } catch (TransformationException e) { - // Transformer extracts the TransformationException from this ExoPlaybackException again. This - // temporary wrapping is needed due to the dependence on ExoPlayer's BaseRenderer. - throw ExoPlaybackException.createForRenderer( - e, - "Transformer", - getIndex(), - /* rendererFormat= */ null, - C.FORMAT_HANDLED, - /* isRecoverable= */ false, - PlaybackException.ERROR_CODE_UNSPECIFIED); + throw wrapTransformationException(e); } } @@ -226,4 +238,23 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; return false; } } + + /** + * Returns an {@link ExoPlaybackException} wrapping the {@link TransformationException}. + * + *

This temporary wrapping is needed due to the dependence on ExoPlayer's BaseRenderer. {@link + * Transformer} extracts the {@link TransformationException} from this {@link + * ExoPlaybackException} again. + */ + private ExoPlaybackException wrapTransformationException( + TransformationException transformationException) { + return ExoPlaybackException.createForRenderer( + transformationException, + "Transformer", + getIndex(), + /* rendererFormat= */ null, + C.FORMAT_HANDLED, + /* isRecoverable= */ false, + PlaybackException.ERROR_CODE_UNSPECIFIED); + } } diff --git a/libraries/transformer/src/test/java/androidx/media3/transformer/TransformerTest.java b/libraries/transformer/src/test/java/androidx/media3/transformer/TransformerTest.java index d223328ba6..ad4f7bbcc8 100644 --- a/libraries/transformer/src/test/java/androidx/media3/transformer/TransformerTest.java +++ b/libraries/transformer/src/test/java/androidx/media3/transformer/TransformerTest.java @@ -62,12 +62,14 @@ import org.robolectric.shadows.ShadowMediaCodec; public final class TransformerTest { private static final String URI_PREFIX = "asset:///media/"; - private static final String FILE_VIDEO_ONLY = "mkv/sample.mkv"; - private static final String FILE_AUDIO_ONLY = "amr/sample_nb.amr"; + private static final String FILE_VIDEO_ONLY = "mp4/sample_18byte_nclx_colr.mp4"; private static final String FILE_AUDIO_VIDEO = "mp4/sample.mp4"; private static final String FILE_WITH_SUBTITLES = "mkv/sample_with_srt.mkv"; private static final String FILE_WITH_SEF_SLOW_MOTION = "mp4/sample_sef_slow_motion.mp4"; - private static final String FILE_WITH_ALL_SAMPLE_FORMATS_UNSUPPORTED = "mp4/sample_ac3.mp4"; + private static final String FILE_AUDIO_UNSUPPORTED_BY_DECODER = "amr/sample_wb.amr"; + private static final String FILE_AUDIO_UNSUPPORTED_BY_ENCODER = "amr/sample_nb.amr"; + private static final String FILE_AUDIO_UNSUPPORTED_BY_MUXER = "mp4/sample_ac3.mp4"; + private static final String FILE_VIDEO_UNSUPPORTED = "vp9/bear-vp9.webm"; private static final String FILE_UNKNOWN_DURATION = "mp4/sample_fragmented.mp4"; public static final String DUMP_FILE_OUTPUT_DIRECTORY = "transformerdumps"; public static final String DUMP_FILE_EXTENSION = "dump"; @@ -94,7 +96,7 @@ public final class TransformerTest { } @Test - public void startTransformation_videoOnly_completesSuccessfully() throws Exception { + public void startTransformation_videoOnlyPassthrough_completesSuccessfully() throws Exception { Transformer transformer = new Transformer.Builder(context) .setClock(clock) @@ -109,18 +111,40 @@ public final class TransformerTest { } @Test - public void startTransformation_audioOnly_completesSuccessfully() throws Exception { + public void startTransformation_audioOnlyPassthrough_completesSuccessfully() throws Exception { Transformer transformer = new Transformer.Builder(context) .setClock(clock) .setMuxerFactory(new TestMuxerFactory()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_ONLY); + + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_ENCODER); transformer.startTransformation(mediaItem, outputPath); TransformerTestRunner.runUntilCompleted(transformer); - DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_ONLY)); + DumpFileAsserts.assertOutput( + context, testMuxer, getDumpFileName(FILE_AUDIO_UNSUPPORTED_BY_ENCODER)); + } + + @Test + public void startTransformation_audioOnlyTranscoding_completesSuccessfully() throws Exception { + Transformer transformer = + new Transformer.Builder(context) + .setClock(clock) + .setMuxerFactory(new TestMuxerFactory()) + .setTransformationRequest( + new TransformationRequest.Builder() + .setAudioMimeType(MimeTypes.AUDIO_AAC) // supported by encoder and muxer + .build()) + .build(); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_ENCODER); + + transformer.startTransformation(mediaItem, outputPath); + TransformerTestRunner.runUntilCompleted(transformer); + + DumpFileAsserts.assertOutput( + context, testMuxer, getDumpFileName(FILE_AUDIO_UNSUPPORTED_BY_ENCODER + ".aac")); } @Test @@ -144,6 +168,8 @@ public final class TransformerTest { new Transformer.Builder(context) .setClock(clock) .setMuxerFactory(new TestMuxerFactory()) + .setTransformationRequest( + new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build()) .build(); MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_SUBTITLES); @@ -161,7 +187,7 @@ public final class TransformerTest { .setClock(clock) .setMuxerFactory(new TestMuxerFactory()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO); // Transform first media item. transformer.startTransformation(mediaItem, outputPath); @@ -172,7 +198,7 @@ public final class TransformerTest { transformer.startTransformation(mediaItem, outputPath); TransformerTestRunner.runUntilCompleted(transformer); - DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_VIDEO_ONLY)); + DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO)); } @Test @@ -246,10 +272,11 @@ public final class TransformerTest { .setMuxerFactory(new TestMuxerFactory()) .setTransformationRequest( new TransformationRequest.Builder() - .setAudioMimeType(MimeTypes.AUDIO_AMR_WB) // unsupported encoder MIME type + .setAudioMimeType( + MimeTypes.AUDIO_AMR_NB) // unsupported by encoder, supported by muxer .build()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_ONLY); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER); transformer.startTransformation(mediaItem, outputPath); TransformationException exception = TransformerTestRunner.runUntilError(transformer); @@ -268,10 +295,10 @@ public final class TransformerTest { .setMuxerFactory(new TestMuxerFactory()) .setTransformationRequest( new TransformationRequest.Builder() - .setAudioMimeType(MimeTypes.AUDIO_AAC) // supported encoder MIME type + .setAudioMimeType(MimeTypes.AUDIO_AAC) // supported by encoder and muxer .build()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_ALL_SAMPLE_FORMATS_UNSUPPORTED); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_DECODER); transformer.startTransformation(mediaItem, outputPath); TransformationException exception = TransformerTestRunner.runUntilError(transformer); @@ -315,15 +342,41 @@ public final class TransformerTest { } @Test - public void startTransformation_withAllSampleFormatsUnsupported_completesWithError() + public void startTransformation_withAudioMuxerFormatUnsupported_completesWithError() throws Exception { - Transformer transformer = new Transformer.Builder(context).setClock(clock).build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_WITH_ALL_SAMPLE_FORMATS_UNSUPPORTED); + Transformer transformer = + new Transformer.Builder(context) + .setClock(clock) + .setMuxerFactory(new TestMuxerFactory()) + .build(); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER); transformer.startTransformation(mediaItem, outputPath); TransformationException exception = TransformerTestRunner.runUntilError(transformer); - assertThat(exception).hasCauseThat().isInstanceOf(IllegalStateException.class); + assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); + assertThat(exception).hasCauseThat().hasMessageThat().contains("audio"); + assertThat(exception.errorCode) + .isEqualTo(TransformationException.ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED); + } + + @Test + public void startTransformation_withVideoMuxerFormatUnsupported_completesWithError() + throws Exception { + Transformer transformer = + new Transformer.Builder(context) + .setClock(clock) + .setMuxerFactory(new TestMuxerFactory()) + .build(); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_UNSUPPORTED); + + transformer.startTransformation(mediaItem, outputPath); + TransformationException exception = TransformerTestRunner.runUntilError(transformer); + + assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); + assertThat(exception).hasCauseThat().hasMessageThat().contains("video"); + assertThat(exception.errorCode) + .isEqualTo(TransformationException.ERROR_CODE_MUXER_SAMPLE_MIME_TYPE_UNSUPPORTED); } @Test @@ -333,7 +386,7 @@ public final class TransformerTest { .setClock(clock) .setMuxerFactory(new TestMuxerFactory()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO); transformer.startTransformation(mediaItem, outputPath); transformer.cancel(); @@ -343,7 +396,7 @@ public final class TransformerTest { transformer.startTransformation(mediaItem, outputPath); TransformerTestRunner.runUntilCompleted(transformer); - DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_VIDEO_ONLY)); + DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO)); } @Test @@ -357,7 +410,7 @@ public final class TransformerTest { .setClock(clock) .setMuxerFactory(new TestMuxerFactory()) .build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_ONLY); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO); AtomicReference exception = new AtomicReference<>(); CountDownLatch countDownLatch = new CountDownLatch(1); @@ -376,13 +429,13 @@ public final class TransformerTest { countDownLatch.await(); assertThat(exception.get()).isNull(); - DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_ONLY)); + DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO)); } @Test public void startTransformation_fromWrongThread_throwsError() throws Exception { Transformer transformer = new Transformer.Builder(context).setClock(clock).build(); - MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_ONLY); + MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO); HandlerThread anotherThread = new HandlerThread("AnotherThread"); AtomicReference illegalStateException = new AtomicReference<>(); CountDownLatch countDownLatch = new CountDownLatch(1); @@ -609,6 +662,7 @@ public final class TransformerTest { /* outputBufferSize= */ 10_000, /* codec= */ (in, out) -> out.put(in)); ShadowMediaCodec.addDecoder(MimeTypes.AUDIO_AAC, codecConfig); + ShadowMediaCodec.addDecoder(MimeTypes.AUDIO_AC3, codecConfig); ShadowMediaCodec.addDecoder(MimeTypes.AUDIO_AMR_NB, codecConfig); ShadowMediaCodec.addEncoder(MimeTypes.AUDIO_AAC, codecConfig); @@ -632,8 +686,9 @@ public final class TransformerTest { throw new IllegalArgumentException("Format unsupported"); } }); - ShadowMediaCodec.addDecoder(MimeTypes.AUDIO_AC3, throwingCodecConfig); - ShadowMediaCodec.addEncoder(MimeTypes.AUDIO_AMR_WB, throwingCodecConfig); + + ShadowMediaCodec.addDecoder(MimeTypes.AUDIO_AMR_WB, throwingCodecConfig); + ShadowMediaCodec.addEncoder(MimeTypes.AUDIO_AMR_NB, throwingCodecConfig); ShadowMediaCodec.addEncoder(MimeTypes.VIDEO_H263, throwingCodecConfig); }