Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End-Of-Stream error when parsing some MP4 video files with parseStream #2337

Closed
2 tasks done
arnaud-martin opened this issue Jan 23, 2025 · 6 comments
Closed
2 tasks done
Labels
bug Bug, will addressed with high priority

Comments

@arnaud-martin
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

music-metadata version

7.14.0

Current Behavior

parseStream throws End-Of-Stream error on two video/mp4 files that are successfully parsed with parseBuffer

Error:

EndOfStreamError: End-Of-Stream
    at ReadStreamTokenizer.readBuffer (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/strtok3/lib/ReadStreamTokenizer.js:41:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async ReadStreamTokenizer.ignore (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/strtok3/lib/ReadStreamTokenizer.js:89:31)
    at async Object.mdat (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/music-metadata/lib/mp4/MP4Parser.js:149:17)
    at async Function.readAtom (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/music-metadata/lib/mp4/Atom.js:20:9)
    at async MP4Parser.parse (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/music-metadata/lib/mp4/MP4Parser.js:236:30)
    at async parse (/Users/arnaud/code/music-metadata-parse-stream-video-mp4-bug/node_modules/music-metadata/lib/ParserFactory.js:38:5)

Reproduction repository: https://github.com/arnaud-martin/music-metadata-parse-stream-video-mp4-bug

Assets: https://we.tl/t-lOcWURy6AR
Link expires on 2025-01-26, if you need me to reupload or prefer another file sharing method please tell me

Expected Behavior

parseStream successfully parses the video/mp4 files

Attached audio sample?

  • I have provided sufficient information to reproduce the issue
@arnaud-martin arnaud-martin added the bug Bug, will addressed with high priority label Jan 23, 2025
@arnaud-martin
Copy link
Author

Hello Borewit,

Thank you for maintaining this library!

I have two video/mp4 files that can't be parsed with parseStream.

I've seen some related issues but didn't manage to make it work:

Feel free to ask me additional information

@Borewit
Copy link
Owner

Borewit commented Jan 23, 2025

Hi @arnaud-martin, I downloaded your file.
Please be patient, I have no time to look into it the coming days, but eventually I will.

@Borewit
Copy link
Owner

Borewit commented Jan 24, 2025

Which function do you use to parse these files @arnaud-martin?
I am asking, as the following tests passed fine:

describe('Issue #2337', () => {

  it('1.mp4', async () => {

    const filePath = path.join(mp4Samples, '1.mp4');
    const {format, common} = await mm.parseFile(filePath);

    assert.strictEqual(format.container, 'mp42/mp41', 'format.container');
    assert.strictEqual(format.codec, 'MPEG-4/AAC', 'format.codec');
  });

  it('2.mp4', async () => {

    const filePath = path.join(mp4Samples, '1.mp4');
    const {format, common} = await mm.parseFile(filePath);

    assert.strictEqual(format.container, 'mp42/mp41', 'format.container');
    assert.strictEqual(format.codec, 'MPEG-4/AAC', 'format.codec');
  });

});

@arnaud-martin
Copy link
Author

Which function do you use to parse these files @arnaud-martin?

parseStream, all the following tests fail when I run them in this minimal reproduction repository:

  describe("Stream", () => {
    it("should parse video 1", async () => {
      const stream = fs.createReadStream(filepath1);

      const promise = parseStream(stream);

      await expect(promise).resolves.not.toThrow();
    });

    it("should parse video 2", async () => {
      const stream = fs.createReadStream(filepath2);

      const promise = parseStream(stream);

      await expect(promise).resolves.not.toThrow();
    });
  });

  describe("Stream with size", () => {
    it("should parse video 1 with size", async () => {
      const stream = fs.createReadStream(filepath1);
      const { size } = fs.statSync(filepath1);

      const promise = parseStream(stream, { size });

      await expect(promise).resolves.not.toThrow();
    });

    it("should parse video 2 with size", async () => {
      const stream = fs.createReadStream(filepath2);
      const { size } = fs.statSync(filepath2);

      const promise = parseStream(stream, { size });

      await expect(promise).resolves.not.toThrow();
    });
  });

@Borewit
Copy link
Owner

Borewit commented Jan 25, 2025

You are still using version 7.14.0, I missed that, it is about time to update...

Either you need to migrate your project from CommonJS to ESM, or follow these instructions: CommonJS backward compatibility.

These tests will succeed with the current version.

@arnaud-martin
Copy link
Author

arnaud-martin commented Jan 27, 2025

Thank you, I've updated and followed the CommonJS backward compatibility instructions: It works!

Have a nice day
Arnaud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, will addressed with high priority
Projects
None yet
Development

No branches or pull requests

2 participants