3

I want to check programmatically whether MP4 file is playable or not. I am very interested to solve this problem programmatically.

Manually, I can easily verify corrupted MP4 but I don't to watch 2-3hr movie for this and there are more than 500 videos in my drive.:/

What is corrupted file for Me?

Well, When I play MP4, I am getting glitches, sometimes errors while playing such as "Can not play this video". Sometime video played without throwing any error but I can't see or hear anything. This is somewhat random corruption.

I am sure, people who wrote video player they must have faced/ handled such type of issue.

How can I find such files programmatically?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Vips
  • 61
  • 1
  • 6

2 Answers2

3

There is no way to find out unless you decode the file completely. You can decode and not display. So use something like ffmpeg to decode into /dev/null. If there are no error messages and it did not abort in the middle everything is fine. if there are you know you have corruption in the file of some sort.

Generally if they are recoverable errors ffmpeg will continue. So you can get a sense of amount of errors or severity depending on number of error messages and ability to continue till the end.

av501
  • 6,645
  • 2
  • 23
  • 34
  • 1
    I agree with av501, if you want it to do it programmatically then you will need to start with opening the file with ffmpeg, then start decoding each frame and checking for errors during the process. You will be able to find them for each audio and video frame that you decode and accordingly take your decision. – praks411 May 12 '13 at 09:36
  • I encoded an MP4 file with ffmpeg, it plays in mplayer, in Chrome, but firefox refuses, saying file corrupt. I did: `ffmpeg -i -s 960x540 -c:a none -c:v libx264 -crf 18 out.mp4`. What is a SAFE way of encoding a file with ffmpeg to be played in major browsers? – Luis A. Florit Jan 24 '16 at 19:26
  • @LuisA.Florit, that is not a mp4 thing but could be a codec thing. Firefox supports h264 only if 3rd party decoder is available. https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats. So to answer your question, no, one single encode cannot work for all browsers, you need to encode differently for different browsers. I am assuming you are using html5 video tag here. – av501 Jan 25 '16 at 00:49
  • Actually, I found help here: `http://stackoverflow.com/a/24468585/1483390`. It turns out that adding `-pix_fmt yuv420p` fixed the video file, and it played nicely by Firefox. I'm not using ` – Luis A. Florit Jan 25 '16 at 18:13
  • @LuisA.Florit, that implies your input was not yuv420p. Unfortunately no way to know that without your ffmpeg output messages. Yes, 420p is the standard format needed. Some players may play 422p but that may depend too much on third party decoders. – av501 Jan 28 '16 at 02:02
1

You could start to find mp4 parser library and use it and see if it fails. There can be those which just read the moov header.

Aftershock
  • 5,205
  • 4
  • 51
  • 64