Skip to content

Commit

Permalink
Detect both raw and BDAV versions of MPEG-2 Transport Streams (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
pasieronen committed Oct 5, 2021
1 parent 6981bdf commit 4ce6838
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion core.js
Expand Up @@ -1281,7 +1281,16 @@ class FileTypeParser {
};
}

if (this.check([0x47], {offset: 4}) && (this.check([0x47], {offset: 192}) || this.check([0x47], {offset: 196}))) {
// Raw MPEG-2 transport stream (188-byte packets)
if (this.check([0x47]) && this.check([0x47], {offset: 188})) {
return {
ext: 'mts',
mime: 'video/mp2t',
};
}

// Blu-ray Disc Audio-Video (BDAV) MPEG-2 transport stream has 4-byte TP_extra_header before each 188-byte packet
if (this.check([0x47], {offset: 4}) && this.check([0x47], {offset: 196})) {
return {
ext: 'mts',
mime: 'video/mp2t',
Expand Down
File renamed without changes.
Binary file added fixture/fixture-raw.mts
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -395,7 +395,7 @@ Returns a `Set<string>` of supported MIME types.
- [`lz`](https://en.wikipedia.org/wiki/Lzip) - Arhive file
- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Compount File Binary Format
- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format) - Material Exchange Format
- [`mts`](https://en.wikipedia.org/wiki/.m2ts) - Blu-ray Disc Audio-Video MPEG-2 Transport Stream
- [`mts`](https://en.wikipedia.org/wiki/.m2ts) - MPEG-2 Transport Stream, both raw and Blu-ray Disc Audio-Video (BDAV) versions
- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly) - WebAssembly intermediate compiled format
- [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format) - Blender project
- [`bpg`](https://bellard.org/bpg/) - Better Portable Graphics file
Expand Down
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -86,6 +86,10 @@ const names = {
'fixture-mp4v2',
'fixture-dash',
],
mts: [
'fixture-raw',
'fixture-bdav',
],
tif: [
'fixture-big-endian',
'fixture-little-endian',
Expand Down

0 comments on commit 4ce6838

Please sign in to comment.