What started out to be a standard use of FFmpeg turns into something slightly different.
Most Digital Video Recorders are designed to capture an event. Unfortunately, the analysis of a recorded event is often hindered by the type of recording method and format used. Whilst working with some AVF Files, this issue was clearly displayed.
The Disk came with a common structure of files, player and codec-install.
For some reason the folder containing the video files was named AVI rather than AVF.
Running the player loads a common user interface, but asks for a ‘floder’!!
I am not going to attempt to use that instcodec.exe – I have no idea what its going to do!
Playback of the video worked fine, but I needed to know more – time to understand it….
MediaInfo revealed that they were mpeg4 files and the FFprobe report confirmed this, reporting 1212 frames, and their true recorded size.
codec_long_name=MPEG-4 part 2
After this I attempted a common FFmpeg rewrap. Unusually, it failed with an error.
A few tests were completed and although it was possible to transcode, all attempts to keep the original codec but just drop the duplicates failed.
An uncompressed RGB file was created. This served the purpose of creating a file that could be utilised further. Secondly, it was possible to extract all the I frames from the video.
ffmpeg -i input.avf -vsync drop -vf select='eq(pict_type\,I)' -f image2 -pix_fmt rgb24 framesfolder\frame%05d.tiff
However, during the analysis, there were questions raised regarding the motion in the video and the nature of how it was being presented. In order to understand more we need to go back to the original AVF file.
gSpot reveals some interesting frame level analysis:
To understand and verify what this is telling us, an why its saying a lot more frames than MediaInfo, it is necessary to use some other tools, namely Defraser and FFprobe.
Defraser confirmed and verified all the Keyframes that had been extracted using FFmpeg but also mirrored the pattern of the GOP structure as identified by Gspot.
Lastly, by completing a full frame report using FFprobe, the entire structure was output.
ffprobe -show_frames -print_format xml -v quiet inputfile.avf > out.xml
To explain why the original rewrap was failing and then to understand the strange motion being presented by the video is a little hard to do – but I will do my best!
It is not, as was previously reported by gSpot, a 25 frame GOP. It doesn’t actually have 2524 frames. It is a 12 Frame GOP with only 1212 Frames. The frames after each coded picture are not coded frames. They are markers to hold the previously coded frame for a period of 40 milliseconds each.
The unusual thing is the pattern.
I have only shown the PTS (Presentation Time Stamp) here as the Decode Time Stamp shows the same pattern but obviously prior to the PTS.
Each GOP lasts 1000 milliseconds. The encoding states that each frame is 40 milliseconds. However, the times between each PTS are not all 40 milliseconds. Some are 80, some are 120 and one is 160 milliseconds. In this case, the video holds the frame until the next one has been decoded and is due to be presented. This is why there are 25 40ms frames identified.
The reason why FFmpeg suffered errors when trying to drop duplicates from the file during the rewrap, is that these ‘duplicates’ actually form part of the video and as such, trying to get rid of them but keep the encoding will not work.
The pattern of frame presentation now makes it clear why motion in the video appeared erratic. Being able to identify this timing structure may be rare when dealing with proprietary video but having an awareness of it will help when analysing an object in motion.
There is a fair bit online regarding mpeg4 and PTS / DTS and I have found some good technical documents available from Textronix, in particular MPEG Fundamentals.
July 2013 Update: Be careful if using the inbuilt convert to AVI function that comes with a few of these AVFplayback.exe’s. Although the DVR’s are set to PAL, they only record at field level to save space. I have seen both 720 x 288 and also, as in the case detailed above, 704 x 288. The problem though, and the reason for this update, is that some of the AVI converters then turn your PAL footage into NTSC. Obviously this can can cause you all sorts of problems!!