Skip to content

Commit

Permalink
Added video codec extraction to parser tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
BTOdell committed Jul 20, 2021
1 parent 199edf5 commit 67e01fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"dependencies": {
"@isomp4/core": "file:../core"
},
"devDependencies": {
"@isomp4/box-moov": "file:../../boxes/moov"
},
"scripts": {
"clean": "shx rm -rf ./dist ./cjs/**/*.js ./cjs/**/*.js.map ./cjs/**/*.d.ts ./test/**/*.js ./test/**/*.js.map ./test/**/*.d.ts ./**/*.tsbuildinfo"
},
Expand Down
17 changes: 16 additions & 1 deletion packages/parser/test/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Buffer} from "buffer";
import {expect} from "chai";
import {readFileSync} from "fs";
import {join} from "path";
import {moov} from "@isomp4/box-moov";
import type {SampleDescriptionBox} from "@isomp4/box-moov";
import {avc1, getVideoCodec, mdia, minf, moov, stbl, stsd, trak} from "@isomp4/box-moov";
import type {Box, BoxHeader} from "@isomp4/core";
import {MP4Parser} from "@isomp4/parser";
import {BoxContainer} from "@isomp4/core";
Expand Down Expand Up @@ -100,4 +101,18 @@ describe("parser", () => {
it("should parse boxes (one byte at a time)", () => {
parseFragmentedVideo(oneByteAtATime);
});
it("should extract the video codec", () => {
let videoCodec: string | undefined;

const parser = new MP4Parser();
parser.registerBox(moov, trak, mdia, minf, stbl, stsd, avc1);
parser.boxEnded = (header: BoxHeader, box?: Box) => {
if (box != null && box.type === "stsd") {
videoCodec = getVideoCodec(box as SampleDescriptionBox);
}
};
parser.append(fragmentedVideo);

expect(videoCodec).eq("avc1.4d0029");
});
});

0 comments on commit 67e01fb

Please sign in to comment.