h2non / filetype

Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature

Home Page:https://pkg.go.dev/github.com/h2non/filetype?tab=doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.mp4 file not detected

dcelasun opened this issue · comments

See attached file (Github doesn't let me upload a video, so it's in a zip).

file doesn't recognize the mime type either:

$ file --mime-type vid-20180326-wa0000.mp4
vid-20180326-wa0000.mp4: application/octet-stream
$ file vid-20180326-wa0000.mp4
vid-20180326-wa0000.mp4: ISO Media

It plays fine with VLC. Here's the part I thought looked relevant:

[00007fdae4000fa0] main input source debug: creating demux: access='file' demux='any' location='/tmp/vid-20180326-wa0000.mp4' file='/tmp/vid-20180326-wa0000.mp4'
[00007fdae4c14c50] main demux debug: looking for demux module matching "mp4": 55 candidates
[00007fdae4c01d20] mp4 stream warning: unknown box type beam (incompletely loaded)
[00007fdae4c01d20] mp4 stream debug: dumping root Box "root"
[00007fdae4c01d20] mp4 stream debug: |   + ftyp size 28 offset 0
[00007fdae4c01d20] mp4 stream debug: |   + beam size 24 offset 28 (????)
[00007fdae4c01d20] mp4 stream debug: |   + moov size 752 offset 52
[00007fdae4c01d20] mp4 stream debug: |   |   + mvhd size 108 offset 60
[00007fdae4c01d20] mp4 stream debug: |   |   + trak size 636 offset 168
[00007fdae4c01d20] mp4 stream debug: |   |   |   + tkhd size 92 offset 176
[00007fdae4c01d20] mp4 stream debug: |   |   |   + mdia size 536 offset 268
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   + mdhd size 32 offset 276
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   + hdlr size 34 offset 308
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   + minf size 462 offset 342
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   + vmhd size 20 offset 350
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   + dinf size 36 offset 370
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + dref size 28 offset 378
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   |   + url  size 12 offset 394
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   + stbl size 398 offset 406
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stsd size 134 offset 414
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   |   + avc1 size 118 offset 430
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   |   |   + avcC size 32 offset 516
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stts size 24 offset 548
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stsc size 28 offset 572
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stsz size 164 offset 600
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stco size 20 offset 764
[00007fdae4c01d20] mp4 stream debug: |   |   |   |   |   |   + stss size 20 offset 784
[00007fdae4c01d20] mp4 stream debug: |   + mdat size 230684 offset 804
[00007fdae4c14c50] mp4 demux debug: unrecognized major media specification (mp4v).
[00007fdae4c14c50] mp4 demux debug: found 1 tracks
[00007fdae4c14c50] mp4 demux debug: track[Id 0x1] read 1 chunk
[00007fdae4c14c50] mp4 demux warning: STTS table of 1 entries
[00007fdae4c14c50] mp4 demux debug: track[Id 0x1] read 36 samples length:1s
[00007fdaec000c40] main input debug: selecting program id=0
[00007fdae4c14c50] mp4 demux debug: adding track[Id 0x1] video (enable) language undef
[00007fdae4c14c50] main demux debug: using demux module "mp4"

Also ffmpeg output:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/vid-20180326-wa0000.mp4':
  Metadata:
    major_brand     : mp4v
    minor_version   : 0
    compatible_brands: mp4vmp42isom
  Duration: 00:00:01.14, start: 0.000000, bitrate: 1631 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 640x272, 1625 kb/s, 31.71 fps, 31.71 tbr, 31714 tbn, 63428 tbc (default)

We also have a similar issue where a mp4 video taken from a device isnt detected. This is the output from ffmpeg

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'WhatsAppVideo.mp4':
  Metadata:
    major_brand     : mobi
    minor_version   : 0
    compatible_brands: mobiavc1mp42isom
  Duration: 00:00:23.28, start: 0.000000, bitrate: 2540 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 2487 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : AVC Video Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 48 kb/s (default)
    Metadata:
      handler_name    : AAC Audio Handler

When we do a file on this mp4, it outputs

192:Downloads raja$ file ~/Downloads/WhatsApp\ Video.mp4 
/Users/raja/Downloads/WhatsApp Video.mp4: ISO Media, MPEG-4, MOBI format

But for a file that is accepted by a tool, the output is

192:Downloads raja$ file ~/Downloads/Client\ logged\ into\ Nisha\ PC.mp4 
/Users/raja/Downloads/Client logged into Nisha PC.mp4: ISO Media, MP4 Base Media v1 [IS0 14496-12:2003]

It looks like the MPEG-4,MOBI format isnt detectable by the tool.

Is there anything that can be done to upload these files?

I'm also facing a undetectable mp4 file

xxd sample.mp4 | head
00000000: 0000 001c 6674 7970 6e76 7231 0001 0001  ....ftypnvr1....
00000010: 6973 6f6d 6d70 3432 6e76 7231 0000 0cb0  isommp42nvr1....
00000020: 6d6f 6f76 0000 006c 6d76 6864 0000 0000  moov...lmvhd....
00000030: dd36 b336 dd36 b336 0000 2710 0000 80cd  .6.6.6.6..'.....
00000040: 0001 0000 0100 0000 0000 0000 0000 0000  ................
00000050: 0001 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0001 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 4000 0000 0000 0000 0000 0000 0000 0000  @...............
00000080: 0000 0000 0000 0000 0000 0000 0000 0003  ................
00000090: 0000 00b1 6d65 7461 0000 0021 6864 6c72  ....meta...!hdlr
$ xxd GH017513.MP4 | head
00000000: 0000 0014 6674 7970 6d70 3431 2013 1018  ....ftypmp41 ...
00000010: 6d70 3431 00c0 53d6 6d64 6174 4750 524f  mp41..S.mdatGPRO
00000020: 8402 0000 4844 392e 3031 2e30 312e 3630  ....HD9.01.01.60
00000030: 2e30 304c 424f 3031 3231 3730 3434 3031  .00LBO0121704401
00000040: 3437 3900 0000 0000 0000 0000 0000 0000  479.............
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 00d6 0572 6b63 80b4 f2af 3fa8 072c  .....rkc....?..,
00000070: 4427 e343 3334 3431 3332 3539 3432 3832  D'.C344132594282
00000080: 3000 4845 524f 3920 426c 6163 6b00 0000  0.HERO9 Black...
00000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................

$ file GH017513.MP4
GH017513.MP4: ISO Media, MP4 v1 [ISO 14496-1:ch13]

Same here.

package main

import (
	"fmt"

	"github.com/h2non/filetype"
)

func main() {
	kind, _ := filetype.MatchFile("DSC_6381.MOV")
	if kind == filetype.Unknown {
		fmt.Println("Unknown file type")
		return
	}

	fmt.Printf("File type: %s. MIME: %s\n", kind.Extension, kind.MIME.Value)
}

Output: Unknown file type
> xxd DSC_6381.MOV | head
00000000: 0000 0018 6674 7970 7174 2020 2007 0900  ....ftypqt   ...
00000010: 7174 2020 6e69 6b6f 0231 13bb 6d64 6174  qt  niko.1..mdat
00000020: 0000 0002 0910 0001 19f4 6588 8200 2fff  ..........e.../.
00000030: 7101 98ca 1f44 567a 5420 0d1d e2e7 3050  q....DVzT ....0P
00000040: 83bf b150 9a91 82c2 117a 4a07 1f75 6a58  ...P.....zJ..ujX
00000050: a1c5 4435 532b f9ad d48d 63a9 f0a0 1268  ..D5S+....c....h
00000060: e059 a0ac e5f9 46cf 9919 29eb 896b 32fb  .Y....F...)..k2.
00000070: d42f 09d0 e0e3 b210 0347 3ec4 8b63 8538  ./.......G>..c.8
00000080: d8bc 7ae1 4197 8b7d 5480 9917 3b75 8c6f  ..z.A..}T...;u.o
00000090: 307c 09cf 2b91 0088 e7f5 5267 7c19 746c  0|..+.....Rg|.tl

> file DSC_6381.MOV
DSC_6381.MOV: ISO Media, Apple QuickTime movie, Apple QuickTime (.MOV/QT)

Same here