mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Merge main into release for tag v1.7.1
This commit is contained in:
@@ -8,6 +8,15 @@
|
|||||||
document.body.append(fileInput);
|
document.body.append(fileInput);
|
||||||
|
|
||||||
fileInput.addEventListener('change', async () => {
|
fileInput.addEventListener('change', async () => {
|
||||||
|
const videoUrl = "https://upload.wikimedia.org/wikipedia/commons/5/53/1941._%D0%9A%D0%BE%D0%BD%D1%91%D0%BA-%D0%B3%D0%BE%D1%80%D0%B1%D1%83%D0%BD%D0%BE%D0%BA.webm"
|
||||||
|
const source = new Mediabunny.UrlSource(videoUrl)
|
||||||
|
const input = new Mediabunny.Input({ formats: Mediabunny.ALL_FORMATS, source });
|
||||||
|
|
||||||
|
const videoTrack = await input.getPrimaryVideoTrack();
|
||||||
|
|
||||||
|
console.log(videoTrack);
|
||||||
|
|
||||||
|
/*
|
||||||
const file = fileInput.files[0];
|
const file = fileInput.files[0];
|
||||||
const source = new Mediabunny.BlobSource(file);
|
const source = new Mediabunny.BlobSource(file);
|
||||||
|
|
||||||
@@ -20,6 +29,7 @@
|
|||||||
const sink = new Mediabunny.EncodedPacketSink(audioTrack);
|
const sink = new Mediabunny.EncodedPacketSink(audioTrack);
|
||||||
|
|
||||||
console.log(await sink.getPacket(100))
|
console.log(await sink.getPacket(100))
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for await (const packet of sink.packets()) {
|
for await (const packet of sink.packets()) {
|
||||||
|
|||||||
Generated
+6
-6
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.7.0",
|
"version": "1.7.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"version": "1.7.0",
|
"version": "1.7.1",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
@@ -5900,9 +5900,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mediabunny": {
|
"node_modules/mediabunny": {
|
||||||
"version": "1.6.2",
|
"version": "1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.7.0.tgz",
|
||||||
"integrity": "sha512-c0z6lfeYHYk5M6V9kLaXD/7HqW8UjjsDhoZUwLConxHCrL/pPMnZwX5tXjXz/T8DIeuXYYbjYR9X43LnEmWacA==",
|
"integrity": "sha512-QcTdptOtvjAHb4KQpgWWWHRS0+DgGwTXelTwPWaZwQu85iYy11bzsLS4e29rfH4nLL/eq8K/dBsjj1LuApc2Qw==",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"peer": true,
|
"peer": true,
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@@ -9017,7 +9017,7 @@
|
|||||||
},
|
},
|
||||||
"packages/mp3-encoder": {
|
"packages/mp3-encoder": {
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"version": "1.7.0",
|
"version": "1.7.1",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/emscripten": "^1.40.1"
|
"@types/emscripten": "^1.40.1"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "mediabunny",
|
"name": "mediabunny",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.7.0",
|
"version": "1.7.1",
|
||||||
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@mediabunny/mp3-encoder",
|
"name": "@mediabunny/mp3-encoder",
|
||||||
"author": "Vanilagy",
|
"author": "Vanilagy",
|
||||||
"version": "1.7.0",
|
"version": "1.7.1",
|
||||||
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
||||||
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||||
|
|||||||
+1
-1
@@ -154,7 +154,7 @@ export class MatroskaInputFormat extends InputFormat {
|
|||||||
}
|
}
|
||||||
}; break;
|
}; break;
|
||||||
case EBMLId.DocType: {
|
case EBMLId.DocType: {
|
||||||
const docType = ebmlReader.readString(size);
|
const docType = ebmlReader.readAsciiString(size);
|
||||||
if (docType !== desiredDocType) {
|
if (docType !== desiredDocType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,8 +312,7 @@ export class EBMLWriter {
|
|||||||
this.writer.write(this.helper.subarray(0, pos));
|
this.writer.write(this.helper.subarray(0, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assumes the string is ASCII
|
writeAsciiString(str: string) {
|
||||||
writeString(str: string) {
|
|
||||||
this.writer.write(new Uint8Array(str.split('').map(x => x.charCodeAt(0))));
|
this.writer.write(new Uint8Array(str.split('').map(x => x.charCodeAt(0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +358,7 @@ export class EBMLWriter {
|
|||||||
this.writeUnsignedInt(data.data, size);
|
this.writeUnsignedInt(data.data, size);
|
||||||
} else if (typeof data.data === 'string') {
|
} else if (typeof data.data === 'string') {
|
||||||
this.writeVarInt(data.data.length);
|
this.writeVarInt(data.data.length);
|
||||||
this.writeString(data.data);
|
this.writeAsciiString(data.data);
|
||||||
} else if (data.data instanceof Uint8Array) {
|
} else if (data.data instanceof Uint8Array) {
|
||||||
this.writeVarInt(data.data.byteLength, data.size);
|
this.writeVarInt(data.data.byteLength, data.size);
|
||||||
this.writer.write(data.data);
|
this.writer.write(data.data);
|
||||||
@@ -495,7 +494,7 @@ export class EBMLReader {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
readString(length: number) {
|
readAsciiString(length: number) {
|
||||||
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
|
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
|
||||||
this.pos += length;
|
this.pos += length;
|
||||||
|
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ export class MatroskaDemuxer extends Demuxer {
|
|||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case EBMLId.DocType: {
|
case EBMLId.DocType: {
|
||||||
this.isWebM = reader.readString(size) === 'webm';
|
this.isWebM = reader.readAsciiString(size) === 'webm';
|
||||||
}; break;
|
}; break;
|
||||||
|
|
||||||
case EBMLId.Seek: {
|
case EBMLId.Seek: {
|
||||||
@@ -940,7 +940,7 @@ export class MatroskaDemuxer extends Demuxer {
|
|||||||
case EBMLId.CodecID: {
|
case EBMLId.CodecID: {
|
||||||
if (!this.currentTrack) break;
|
if (!this.currentTrack) break;
|
||||||
|
|
||||||
this.currentTrack.codecId = reader.readString(size);
|
this.currentTrack.codecId = reader.readAsciiString(size);
|
||||||
}; break;
|
}; break;
|
||||||
|
|
||||||
case EBMLId.CodecPrivate: {
|
case EBMLId.CodecPrivate: {
|
||||||
@@ -959,7 +959,7 @@ export class MatroskaDemuxer extends Demuxer {
|
|||||||
case EBMLId.Language: {
|
case EBMLId.Language: {
|
||||||
if (!this.currentTrack) break;
|
if (!this.currentTrack) break;
|
||||||
|
|
||||||
this.currentTrack.languageCode = reader.readString(size);
|
this.currentTrack.languageCode = reader.readAsciiString(size);
|
||||||
|
|
||||||
if (!isIso639Dash2LanguageCode(this.currentTrack.languageCode)) {
|
if (!isIso639Dash2LanguageCode(this.currentTrack.languageCode)) {
|
||||||
this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;
|
this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;
|
||||||
|
|||||||
+22
-2
@@ -164,11 +164,13 @@ export type UrlSourceOptions = {
|
|||||||
*/
|
*/
|
||||||
export class UrlSource extends Source {
|
export class UrlSource extends Source {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
private _url: string | URL;
|
private _url: URL;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
private _options: UrlSourceOptions;
|
private _options: UrlSourceOptions;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
private _fullData: ArrayBuffer | null = null;
|
private _fullData: ArrayBuffer | null = null;
|
||||||
|
/** @internal */
|
||||||
|
private _nextUrlVersion: number | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
url: string | URL,
|
url: string | URL,
|
||||||
@@ -189,7 +191,7 @@ export class UrlSource extends Source {
|
|||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._url = url;
|
this._url = url instanceof URL ? url : new URL(url);
|
||||||
this._options = options;
|
this._options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +205,11 @@ export class UrlSource extends Source {
|
|||||||
headers['Range'] = `bytes=${range.start}-${range.end - 1}`;
|
headers['Range'] = `bytes=${range.start}-${range.end - 1}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._nextUrlVersion !== null) {
|
||||||
|
this._url.searchParams.set('mediabunny_version', this._nextUrlVersion.toString());
|
||||||
|
this._nextUrlVersion++;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await retriedFetch(
|
const response = await retriedFetch(
|
||||||
this._url,
|
this._url,
|
||||||
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
||||||
@@ -218,6 +225,19 @@ export class UrlSource extends Source {
|
|||||||
|
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
|
|
||||||
|
if (
|
||||||
|
response.status === 206
|
||||||
|
&& range
|
||||||
|
&& buffer.byteLength !== range.end - range.start
|
||||||
|
&& this._nextUrlVersion === null
|
||||||
|
) {
|
||||||
|
// We did a range request but it resolved with the wrong range; in Chromium, this can be due to a caching
|
||||||
|
// bug (https://issues.chromium.org/issues/436025873). Let's circumvent the cache for the rest of the
|
||||||
|
// session by appending a version to the URL.
|
||||||
|
this._nextUrlVersion = 1;
|
||||||
|
return this._makeRequest(range);
|
||||||
|
}
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
// The server didn't return 206 Partial Content, so it's not a range response
|
// The server didn't return 206 Partial Content, so it's not a range response
|
||||||
this._fullData = buffer;
|
this._fullData = buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user