如何将 Ogg 与 JS 连接起来?
How to concatenate Ogg with JS?
在我的 webapp 用户可以下载 OGG (vorbis),但我发现例如 VLC 显示一个文件持续时间为 35 秒,但播放了 10 分钟。
目前我构建了一个用于下载的文件:
const blob = new Blob(listOfChunksBlobs, {'type': 'audio/ogg'});
使用 xdd
我检查了 OGG 的开始 - 但我不知道如何在这里更改任何内容:
00000000: 4f67 6753 0002 0000 0000 0000 0000 0000 OggS............
00000010: 0000 0000 0000 5664 269e 011e 0176 6f72 ......Vd&....vor
00000020: 6269 7300 0000 0001 2256 0000 0000 0000 bis....."V......
00000030: 058a 0000 0000 0000 a901 4f67 6753 0000 ..........OggS..
00000040: 0000 0000 0000 0000 0000 0000 0100 0000 ................
00000050: 5096 ab47 0e16 ffff ffff ffff ffff ffff P..G............
00000060: ffff c503 766f 7262 6973 0600 0000 6666 ....vorbis....ff
00000070: 6d70 6567 0000 0000 0105 766f 7262 6973 mpeg......vorbis
00000080: 2242 4356 0100 4000 0018 4210 2a05 ad63 "BCV..@...B.*..c
00000090: 8e3a c815 218c 19a2 a042 ca29 c71d 42d0 .:..!....B.)..B.
000000a0: 21a3 2443 883a c635 c718 6347 b964 8a42 !.$C.:.5..cG.d.B
000000b0: c981 d090 5500 0040 0000 a41c 5750 7249 ....U..@....WPrI
000000c0: 2de7 9c73 a318 57cc 71e8 20e7 9c73 e520 -..s..W.q. ..s.
000000d0: 67cc 7109 25e7 9c73 8e39 e792 728e 31e7 g.q.%..s.9..r.1.
000000e0: 9c73 a318 570e 7229 2de7 9c73 8114 478a .s..W.r)-..s..G.
000000f0: 71a7 18e7 9c73 a41c 478a 71a8 18e7 9c73 q....s..G.q....s
00000100: 6d31 b792 72ce 39e7 9c73 e620 8752 72ae m1..r.9..s. .Rr.
00000110: 35e7 9c73 a418 670e 720b 25e7 9c73 c620 5..s..g.r.%..s.
00000120: 67cc 71eb 20e7 9c73 8c35 b7d4 72ce 39e7 g.q. ..s.5..r.9.
00000130: 9c73 ce39 e79c 73ce 39e7 9c73 8c31 e79c .s.9..s.9..s.1..
00000140: 73ce 39e7 9c73 6e31 e716 73ae 39e7 9c73 s.9..sn1..s.9..s
00000150: ce39 e71c 73ce 39e7 9c73 2034 6415 0090 .9..s.9..s 4d...
00000160: 0000 a0a1 288a e228 0e10 1ab2 0a00 c800 ....(..(........
00000170: 0010 4071 1447 9114 4bb1 1ccb d124 0d08 ..@q.G..K....$..
00000180: 0d59 0500 0001 0008 0000 a048 86a4 488a .Y.........H..H.
00000190: a558 8e66 699e 267a a228 9aa2 2aab b269 .X.fi.&z.(..*..i
000001a0: cab2 2ccb b2eb ba2e 101a b20a 0048 0000 ..,..........H..
000001b0: 5051 14c5 7014 0708 0d59 0500 6400 0008 PQ..p....Y..d...
000001c0: 6028 8aa3 388e e458 92a5 599e 0784 86ac `(..8..X..Y.....
000001d0: 0200 8000 0004 0000 500c 47b1 144d f124 ........P.G..M.$
000001e0: cff2 3ccf f33c cff3 3ccf f33c cff3 3ccf ..<..<..<..<..<.
000001f0: f33c cff3 3c0d 080d 5905 0020 0000 0082 .<..<...Y.. ....
00000200: 2864 1803 4243 5601 0040 0000 0821 1a19 (d..BCV..@...!..
00000210: 439d 5212 5c0a 1642 1c11 431d 42ce 43a9 C.R.\..B..C.B.C.
00000220: a583 e029 8525 63d2 53ac 4108 217c ef3d ...).%c.S.A.!|.=
00000230: f7de 7bef 81d0 9055 0000 1000 0061 1438 ..{....U.....a.8
00000240: 8881 c724 0821 8462 1427 4471 a620 0821 ...$.!.b.'Dq. .!
00000250: 84e5 2458 ca79 e824 08dd 8310 42b8 9c7b ..$X.y.$....B..{
00000260: cbb9 f7de 7b20 3464 1500 0008 00c0 2084 ....{ 4d...... .
00000270: 1042 0821 8410 4208 29a4 9452 4829 a698 .B.!..B.)..RH)..
00000280: 628a 29c7 1c73 cc31 c720 830c 32e8 a093 b.)..s.1. ..2...
00000290: 4e3a c9a4 924e 3aca 24a3 8e52 6b29 b514 N:...N:.$..Rk)..
000002a0: 534c b1e5 1663 adb5 d69c 73af 4129 638c SL...c....s.A)c.
000002b0: 31c6 1863 8c31 c618 638c 31c6 1823 080d 1..c.1..c.1..#..
000002c0: 5905 0080 0000 1006 1964 9041 0821 8414 Y........d.A.!..
000002d0: 5248 29a6 9872 cc31 c71c 0342 4356 0100 RH)..r.1...BCV..
000002e0: 8000 0002 0000 001c 4552 2447 7224 4792 ........ER$Gr$G.
000002f0: 24c9 922c 4993 3ccb b33c cbb3 3c4d d444 $..,I.<..<..<M.D
00000300: 4d15 55d5 556d d7f6 6d5f f66d dfd5 65df M.U.Um..m_.m..e.
00000310: f665 dbd5 655d 9665 ddb5 6d5d d65d 5dd7 .e..e].e..m].]].
00000320: 755d d775 5dd7 755d d775 5dd7 755d d781 u].u].u].u].u]..
00000330: d090 5500 8004 0080 8ee4 388e e438 8ee4 ..U.......8..8..
00000340: 488e a448 0a10 1ab2 0a00 9001 0010 0080 H..H............
00000350: a338 8ae3 488e e458 8e25 5992 2669 9667 .8..H..X.%Y.&i.g
00000360: 7996 a779 9aa8 891e 101a b20a 0000 0400 y..y............
00000370: 1000 0000 0000 80a2 288a a338 8e24 5996 ........(..8.$Y.
00000380: a669 9ea7 7aa2 289a aaaa 8aa6 a9aa aa6a .i..z.(........j
00000390: 9aa6 699a a669 9aa6 699a a669 9aa6 699a ..i..i..i..i..i.
000003a0: a669 9aa6 699a a669 9aa6 699a a669 9aa6 .i..i..i..i..i..
000003b0: 6902 a121 ab00 0009 0000 1dc7 711c 4771 i..!........q.Gq
000003c0: 1cc7 7124 4792 2420 3464 1500 2003 0020 ..q$G.$ 4d.. ..
000003d0: 0000 4351 1c45 722c c792 344b b33c cbd3 ..CQ.Er,..4K.<..
000003e0: 44cf f45c 5136 7553 576d 2034 6415 0000 D..\Q6uSWm 4d...
000003f0: 0800 2000 0000 0000 00c7 733c c773 3cc9 .. .......s<.s<.
00000400: 933c cb73 3cc7 933c 49d3 344d d334 4dd3 .<.s<..<I.4M.4M.
00000410: 344d d334 4dd3 344d d334 4dd3 344d d334 4M.4M.4M.4M.4M.4
00000420: 4dd3 344d d334 4dd3 344d d334 4dd3 344d M.4M.4M.4M.4M.4M
00000430: d334 4d03 4243 5602 0064 0000 1093 904a .4M.BCV..d.....J
00000440: 4eb1 5746 29c6 24b4 5e2a a414 93d4 7ba8 N.WF).$.^*....{.
00000450: 9862 4c3a eda9 4206 2907 b987 4a21 a5a0 .bL:..B.)...J!..
00000460: d3de 32a5 9052 0c7b a798 42c8 18ea a183 ..2..R.{..B.....
00000470: 9031 85b0 d7da 73cf bdf7 1e08 0d59 1100 .1....s......Y..
00000480: 4401 0000 c620 c610 63c8 3126 2583 1231 D.... ..c.1&%..1
00000490: c724 6452 22e7 9c94 4e4a 26a5 a456 5acc .$dR"...NJ&..VZ.
000004a0: a484 984a 8b91 734e 4a27 2593 525a 0ba9 ...J..sNJ'%.RZ..
000004b0: 6592 4a6b 25a6 0200 0002 1c00 0002 2c84 e.Jk%.........,.
000004c0: 4243 5604 0051 0000 8831 4829 a414 524a BCV..Q...1H)..RJ
000004d0: 31a7 9843 4a29 c794 6348 29e5 9c72 4e39 1..CJ)..cH)..rN9
000004e0: c798 7410 2ae7 1874 0e4a a494 728e 39a7 ..t.*..t.J..r.9.
000004f0: 9c73 1232 0795 730e 4226 9d00 0080 0007 .s.2..s.B&......
00000500: 0080 000b a1d0 9015 0140 9c00 0080 9073 .........@.....s
00000510: 8a31 0811 6310 4209 2985 5052 aa9c 93d2 .1..c.B.).PR....
00000520: 4149 a983 9252 49a9 c592 528c 9573 523a AI...RI...R..sR:
00000530: 0929 7512 522a 29c5 5852 8a2d a454 6369 .)u.R*).XR.-.Tci
00000540: 2dd7 d252 8d2d c69c 5b8c bd86 9462 2da9 -..R.-..[....b-.
00000550: d55a 5aab b9c5 5873 8b35 f7c8 394a 9d94 .ZZ...Xs.5..9J..
00000560: d63a 29ad a5d6 6a4d add5 da49 692d a4d6 .:)...jM...Ii-..
00000570: 6269 2dc6 d662 cd29 c69c 3329 ad85 9662 bi-..b.)..3)...b
00000580: 2ba9 c5d8 62cb 35b5 9873 692d d714 63cf +...b.5..si-..c.
00000590: 29c6 9e6b acb9 c79c 8330 add5 9c5a cb39 )..k.....0...Z.9
问题的根源是因为我的每个 ogg 都相同 serial
,例如 ogginfo
:
Note: Stream 1 has serial number 0, which is legal but may cause problems with some tools.
New logical stream (#1, serial: 00000000): type vorbis
Vorbis headers parsed for stream 1, information follows...
Version: 0
Vendor: ffmpeg
Channels: 1
Rate: 22050
Nominal bitrate: 35.333000 kb/s
Upper bitrate not set
Lower bitrate not set
Vorbis stream 1:
Total data length: 2048 bytes
Playback length: 0m:00.415s
Average bitrate: 39.435345 kb/s
Logical stream 1 ended
为了正确的 Ogg 串联,我们必须为每个文件提供唯一的 serial
,并具有正确的 crc
。我没有找到现有的 JS 片段(请随意 comment/answer 使用你的 JS),只有 C code for a few hundreds of lines 你可以在后端使用或编译为 WASM(生成的 JS 为 230K,生成的 JS 为 59K) wasm
文件) - 或者我希望有人将它重写为 JS - 我不了解 C.
Original message from Ralph Giles in Ogg mailing list:
Note if both files have the same serial number, it's impossible to
find the points where they were concatentated by bisection, and most
tools will assume they've found all the sections and calculate an
incorrect duration. They can still be played individually because
there is not concatenation boundary to find in the individual case.
If ogginfo shows the same serial (00000000) for both of your input
streams, that's likely the problem. Muxers are supposed to use a
random serial number to make conflicts unlikely. You can fix them by
rewriting the serial number so there's no conflict. Basically, you
change the serialno field in each ogg page header and then update the
crc.
更新:这是带有连续剧 11111111
和 22222222
的 gif - 我认为如果我们从相同来源以相同格式(例如 AWS Polly)获取 Oggs - 也许它会更改串行和 crc32 的硬编码位置要简单得多。
更新:是的,为每个 Ogg 块设置唯一的序列号(该块的所有 "pages")并设置正确的 CRC32(再次为每个 Ogg 的所有页面),参见 documentation of Ogg and Wikipedia page; also see 。并且不要忘记所有十六进制的长度必须为 8 个字符,因此 const hex = crc.toString(16).padStart(8, '0')
在我的 webapp 用户可以下载 OGG (vorbis),但我发现例如 VLC 显示一个文件持续时间为 35 秒,但播放了 10 分钟。
目前我构建了一个用于下载的文件:
const blob = new Blob(listOfChunksBlobs, {'type': 'audio/ogg'});
使用 xdd
我检查了 OGG 的开始 - 但我不知道如何在这里更改任何内容:
00000000: 4f67 6753 0002 0000 0000 0000 0000 0000 OggS............
00000010: 0000 0000 0000 5664 269e 011e 0176 6f72 ......Vd&....vor
00000020: 6269 7300 0000 0001 2256 0000 0000 0000 bis....."V......
00000030: 058a 0000 0000 0000 a901 4f67 6753 0000 ..........OggS..
00000040: 0000 0000 0000 0000 0000 0000 0100 0000 ................
00000050: 5096 ab47 0e16 ffff ffff ffff ffff ffff P..G............
00000060: ffff c503 766f 7262 6973 0600 0000 6666 ....vorbis....ff
00000070: 6d70 6567 0000 0000 0105 766f 7262 6973 mpeg......vorbis
00000080: 2242 4356 0100 4000 0018 4210 2a05 ad63 "BCV..@...B.*..c
00000090: 8e3a c815 218c 19a2 a042 ca29 c71d 42d0 .:..!....B.)..B.
000000a0: 21a3 2443 883a c635 c718 6347 b964 8a42 !.$C.:.5..cG.d.B
000000b0: c981 d090 5500 0040 0000 a41c 5750 7249 ....U..@....WPrI
000000c0: 2de7 9c73 a318 57cc 71e8 20e7 9c73 e520 -..s..W.q. ..s.
000000d0: 67cc 7109 25e7 9c73 8e39 e792 728e 31e7 g.q.%..s.9..r.1.
000000e0: 9c73 a318 570e 7229 2de7 9c73 8114 478a .s..W.r)-..s..G.
000000f0: 71a7 18e7 9c73 a41c 478a 71a8 18e7 9c73 q....s..G.q....s
00000100: 6d31 b792 72ce 39e7 9c73 e620 8752 72ae m1..r.9..s. .Rr.
00000110: 35e7 9c73 a418 670e 720b 25e7 9c73 c620 5..s..g.r.%..s.
00000120: 67cc 71eb 20e7 9c73 8c35 b7d4 72ce 39e7 g.q. ..s.5..r.9.
00000130: 9c73 ce39 e79c 73ce 39e7 9c73 8c31 e79c .s.9..s.9..s.1..
00000140: 73ce 39e7 9c73 6e31 e716 73ae 39e7 9c73 s.9..sn1..s.9..s
00000150: ce39 e71c 73ce 39e7 9c73 2034 6415 0090 .9..s.9..s 4d...
00000160: 0000 a0a1 288a e228 0e10 1ab2 0a00 c800 ....(..(........
00000170: 0010 4071 1447 9114 4bb1 1ccb d124 0d08 ..@q.G..K....$..
00000180: 0d59 0500 0001 0008 0000 a048 86a4 488a .Y.........H..H.
00000190: a558 8e66 699e 267a a228 9aa2 2aab b269 .X.fi.&z.(..*..i
000001a0: cab2 2ccb b2eb ba2e 101a b20a 0048 0000 ..,..........H..
000001b0: 5051 14c5 7014 0708 0d59 0500 6400 0008 PQ..p....Y..d...
000001c0: 6028 8aa3 388e e458 92a5 599e 0784 86ac `(..8..X..Y.....
000001d0: 0200 8000 0004 0000 500c 47b1 144d f124 ........P.G..M.$
000001e0: cff2 3ccf f33c cff3 3ccf f33c cff3 3ccf ..<..<..<..<..<.
000001f0: f33c cff3 3c0d 080d 5905 0020 0000 0082 .<..<...Y.. ....
00000200: 2864 1803 4243 5601 0040 0000 0821 1a19 (d..BCV..@...!..
00000210: 439d 5212 5c0a 1642 1c11 431d 42ce 43a9 C.R.\..B..C.B.C.
00000220: a583 e029 8525 63d2 53ac 4108 217c ef3d ...).%c.S.A.!|.=
00000230: f7de 7bef 81d0 9055 0000 1000 0061 1438 ..{....U.....a.8
00000240: 8881 c724 0821 8462 1427 4471 a620 0821 ...$.!.b.'Dq. .!
00000250: 84e5 2458 ca79 e824 08dd 8310 42b8 9c7b ..$X.y.$....B..{
00000260: cbb9 f7de 7b20 3464 1500 0008 00c0 2084 ....{ 4d...... .
00000270: 1042 0821 8410 4208 29a4 9452 4829 a698 .B.!..B.)..RH)..
00000280: 628a 29c7 1c73 cc31 c720 830c 32e8 a093 b.)..s.1. ..2...
00000290: 4e3a c9a4 924e 3aca 24a3 8e52 6b29 b514 N:...N:.$..Rk)..
000002a0: 534c b1e5 1663 adb5 d69c 73af 4129 638c SL...c....s.A)c.
000002b0: 31c6 1863 8c31 c618 638c 31c6 1823 080d 1..c.1..c.1..#..
000002c0: 5905 0080 0000 1006 1964 9041 0821 8414 Y........d.A.!..
000002d0: 5248 29a6 9872 cc31 c71c 0342 4356 0100 RH)..r.1...BCV..
000002e0: 8000 0002 0000 001c 4552 2447 7224 4792 ........ER$Gr$G.
000002f0: 24c9 922c 4993 3ccb b33c cbb3 3c4d d444 $..,I.<..<..<M.D
00000300: 4d15 55d5 556d d7f6 6d5f f66d dfd5 65df M.U.Um..m_.m..e.
00000310: f665 dbd5 655d 9665 ddb5 6d5d d65d 5dd7 .e..e].e..m].]].
00000320: 755d d775 5dd7 755d d775 5dd7 755d d781 u].u].u].u].u]..
00000330: d090 5500 8004 0080 8ee4 388e e438 8ee4 ..U.......8..8..
00000340: 488e a448 0a10 1ab2 0a00 9001 0010 0080 H..H............
00000350: a338 8ae3 488e e458 8e25 5992 2669 9667 .8..H..X.%Y.&i.g
00000360: 7996 a779 9aa8 891e 101a b20a 0000 0400 y..y............
00000370: 1000 0000 0000 80a2 288a a338 8e24 5996 ........(..8.$Y.
00000380: a669 9ea7 7aa2 289a aaaa 8aa6 a9aa aa6a .i..z.(........j
00000390: 9aa6 699a a669 9aa6 699a a669 9aa6 699a ..i..i..i..i..i.
000003a0: a669 9aa6 699a a669 9aa6 699a a669 9aa6 .i..i..i..i..i..
000003b0: 6902 a121 ab00 0009 0000 1dc7 711c 4771 i..!........q.Gq
000003c0: 1cc7 7124 4792 2420 3464 1500 2003 0020 ..q$G.$ 4d.. ..
000003d0: 0000 4351 1c45 722c c792 344b b33c cbd3 ..CQ.Er,..4K.<..
000003e0: 44cf f45c 5136 7553 576d 2034 6415 0000 D..\Q6uSWm 4d...
000003f0: 0800 2000 0000 0000 00c7 733c c773 3cc9 .. .......s<.s<.
00000400: 933c cb73 3cc7 933c 49d3 344d d334 4dd3 .<.s<..<I.4M.4M.
00000410: 344d d334 4dd3 344d d334 4dd3 344d d334 4M.4M.4M.4M.4M.4
00000420: 4dd3 344d d334 4dd3 344d d334 4dd3 344d M.4M.4M.4M.4M.4M
00000430: d334 4d03 4243 5602 0064 0000 1093 904a .4M.BCV..d.....J
00000440: 4eb1 5746 29c6 24b4 5e2a a414 93d4 7ba8 N.WF).$.^*....{.
00000450: 9862 4c3a eda9 4206 2907 b987 4a21 a5a0 .bL:..B.)...J!..
00000460: d3de 32a5 9052 0c7b a798 42c8 18ea a183 ..2..R.{..B.....
00000470: 9031 85b0 d7da 73cf bdf7 1e08 0d59 1100 .1....s......Y..
00000480: 4401 0000 c620 c610 63c8 3126 2583 1231 D.... ..c.1&%..1
00000490: c724 6452 22e7 9c94 4e4a 26a5 a456 5acc .$dR"...NJ&..VZ.
000004a0: a484 984a 8b91 734e 4a27 2593 525a 0ba9 ...J..sNJ'%.RZ..
000004b0: 6592 4a6b 25a6 0200 0002 1c00 0002 2c84 e.Jk%.........,.
000004c0: 4243 5604 0051 0000 8831 4829 a414 524a BCV..Q...1H)..RJ
000004d0: 31a7 9843 4a29 c794 6348 29e5 9c72 4e39 1..CJ)..cH)..rN9
000004e0: c798 7410 2ae7 1874 0e4a a494 728e 39a7 ..t.*..t.J..r.9.
000004f0: 9c73 1232 0795 730e 4226 9d00 0080 0007 .s.2..s.B&......
00000500: 0080 000b a1d0 9015 0140 9c00 0080 9073 .........@.....s
00000510: 8a31 0811 6310 4209 2985 5052 aa9c 93d2 .1..c.B.).PR....
00000520: 4149 a983 9252 49a9 c592 528c 9573 523a AI...RI...R..sR:
00000530: 0929 7512 522a 29c5 5852 8a2d a454 6369 .)u.R*).XR.-.Tci
00000540: 2dd7 d252 8d2d c69c 5b8c bd86 9462 2da9 -..R.-..[....b-.
00000550: d55a 5aab b9c5 5873 8b35 f7c8 394a 9d94 .ZZ...Xs.5..9J..
00000560: d63a 29ad a5d6 6a4d add5 da49 692d a4d6 .:)...jM...Ii-..
00000570: 6269 2dc6 d662 cd29 c69c 3329 ad85 9662 bi-..b.)..3)...b
00000580: 2ba9 c5d8 62cb 35b5 9873 692d d714 63cf +...b.5..si-..c.
00000590: 29c6 9e6b acb9 c79c 8330 add5 9c5a cb39 )..k.....0...Z.9
问题的根源是因为我的每个 ogg 都相同 serial
,例如 ogginfo
:
Note: Stream 1 has serial number 0, which is legal but may cause problems with some tools.
New logical stream (#1, serial: 00000000): type vorbis
Vorbis headers parsed for stream 1, information follows...
Version: 0
Vendor: ffmpeg
Channels: 1
Rate: 22050
Nominal bitrate: 35.333000 kb/s
Upper bitrate not set
Lower bitrate not set
Vorbis stream 1:
Total data length: 2048 bytes
Playback length: 0m:00.415s
Average bitrate: 39.435345 kb/s
Logical stream 1 ended
为了正确的 Ogg 串联,我们必须为每个文件提供唯一的 serial
,并具有正确的 crc
。我没有找到现有的 JS 片段(请随意 comment/answer 使用你的 JS),只有 C code for a few hundreds of lines 你可以在后端使用或编译为 WASM(生成的 JS 为 230K,生成的 JS 为 59K) wasm
文件) - 或者我希望有人将它重写为 JS - 我不了解 C.
Original message from Ralph Giles in Ogg mailing list:
Note if both files have the same serial number, it's impossible to find the points where they were concatentated by bisection, and most tools will assume they've found all the sections and calculate an incorrect duration. They can still be played individually because there is not concatenation boundary to find in the individual case.
If ogginfo shows the same serial (00000000) for both of your input streams, that's likely the problem. Muxers are supposed to use a random serial number to make conflicts unlikely. You can fix them by rewriting the serial number so there's no conflict. Basically, you change the serialno field in each ogg page header and then update the crc.
更新:这是带有连续剧 11111111
和 22222222
的 gif - 我认为如果我们从相同来源以相同格式(例如 AWS Polly)获取 Oggs - 也许它会更改串行和 crc32 的硬编码位置要简单得多。
更新:是的,为每个 Ogg 块设置唯一的序列号(该块的所有 "pages")并设置正确的 CRC32(再次为每个 Ogg 的所有页面),参见 documentation of Ogg and Wikipedia page; also see const hex = crc.toString(16).padStart(8, '0')