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.