ffmpegcomputer-visionvideo-processingimagejfiji

ImageJ / Fiji shows wrong number of frames in video (FFMPEG import)


I am counting the number of animals in a an area using Fiji. I import the video through the FFMPEG plug-in (videos are mp4 with mpeg-4 codec). However, I noticed that when I import the videos Fiji uploads the wrong number of frames, and I cannot understand why and how.

An example. I have a video shot at 25fps which is 1582s long. If I do the calculations the video should have 39550 frames in total (1582*25). When I open it through a Computer vision package in R, I see that the video correctly contains 39550 frames. However, when loaded in Fiji, the shown number of frames is 49511. So Fiji is adding 9961 frames to the video. This is consistent across all videos that are recorded in 25fps, while it does not appear in videos shot at 24fps.

Curiously, I found that the ratio between the number of frames read by Fiji and the 'real' number of frames is consistent between 0.79 and 0.80. This makes me think that Fiji is expecting the video to be 30fps and (possibly) duplicating frames to adjust the video to this assumption.

Unfortunately, I discovered all this after finishing my analysis and while trying to merge this dataset with another obtained through CV. The number of frame does not match between datasets and I am not sure how to solve this.

Any help would be greatly appreciated!!

An idea is to multiply all the frame numbers by 0.8 to adjust them to the old assumption. This solution assumes that Fiji is duplicating frames throughout the video in a consistent way


Solution

  • I don't know much about Fiji but ffmpeg has a vsync parameter that can possibly cause this problem and as you mentioned it uses the ffmpeg plugin to import the video hence my hunch that it could be that (vsync basically duplicates or drops frames to sync to the audio) if it's possible to look into the ffmpeg plugin that's been used it should paint a clearer picture

    Also if you do think that Fiji needs 30fps video then you can just encode the video with ffmpeg to match the params you need for example

    ffmpeg -i yourvideo.mp4 -c:v libx264 -r 30 -vsync 2 outfile.mp4
    

    The opencv issue can be solved aswell if you match the params of all your video streams that you feed to both Fiji and cv if i am not wrong cv should work with 30fps videos aswell considering adding 5fps to every video is faster than fixing Fiji to work with 25 fps if it indeed only works with 30 fps videos