How to handle differing .mp4 file types from different sources?

我的未来我决定 提交于 2019-12-24 12:17:27

问题


If I take a .mp4 recorded on my mobile (Samsung S5) and pass it through FFmpeg with the below command, the output file (fileX.avi) is a greyscale bitmap uncompressed video file.

  • The offset values in fileX.avi (output from FFmpeg) to allow me to locate the video frame data are always 5680 bytes for the file header.

  • And 62 bytes for the inter frame header.

  • The data is uncompressed RGB24 so i can easily calculate the size of a video frame from height x width x 3.

So my C# application can access the video frames in fileX.avi always at these above offsets.
(This works great).

My FFmpeg Command is:

ffmpeg.exe -i source.mp4 -b 1150 -r 20.97 -g 120 -an -vf format=gray -f rawvideo -pixfmt gray -s 384x216 -vcodec rawvideo -y fileX.avi

However... I recently took an .mp4 file from a different source (produced by Power Director 14 instead of direct from my mobile phone) and used this as the input source.mp4. But now the structure of fileX.avi differs as the offset values of 5680 + 62 bytes from the start in fileX.avi do not land me at the start of the video data frames.

There seems to be different file formats for .mp4 - and obviously if there are my crude offset approach will not work for them all. I suspected at the time I wrote the code my method was all too easy a solution!

So can anyone advise on the approach I should take now? Should I check the original .mp4 or the output file (fileX.avi) to determine a "file type" to which I can determine the different offsets?

At the very least I need to be able to identify the "type" of .mp4 file that works so I can declare the type that will work with my software.

来源:https://stackoverflow.com/questions/46284550/how-to-handle-differing-mp4-file-types-from-different-sources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!