I want to find the number of frames in a video named 00028.MTS
The program "MediaInfo" gives the following information:
Duration: 3 min 20 s
Frame Rate: 25.000 FPS
Reference Frames: 2
I multiplied 3 min 20 s to by the frame rate get the number of frames (200 seconds * 25 = 5000 frames)
Then I used the program "ffprobe", entering the following on the command line:
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv 00028.MTS
This resulted in a count of 5018 frames
Even if the Reference Frames are included in the MediaInfo result, the two counts don't match (I don't know what Reference Frames are).
Can anyone tell me why the results are different, and how I might be sure to get the correct frame count for the video?
Thank you.
+ Reply to Thread
Results 1 to 10 of 10
-
-
Virtualdub2 or Avisynth+ can give accurate frame counts.
-
You have to take the various reports from FFPROBE, MediaInfo, FFMPEG, Players, etc. carefully. In the image below you can see that the video PTS starts at 0.0800000 and the last frame is 33.200000. 828th frame 0->828 = 829 frames) times .04 = 33.12 which is 33.200000 - .08 start PTS. The last frame then starts at 33.12 and ends 0.04 seconds later for a total length of 33.160.
I have no idea why MediaInfor shows 33m 250ms since even if you add the 33.160 and the 0.080 start pts, its only 33.240. Pdersonally I use MediaInfo as a reference and ffprobe for the actual data I need: You can drag and drop on the following cmd file to get that information in a text file. as below. You almost have to find the tool you wish to use and use or adjust its accuracy.
Code:setlocal enabledelayedexpansion @echo off ::for %%a in (*.mp4,*.mpg,*.flv) Do ( for %%a in ("%~dpnx1") Do ( set /a count=0 cd %%~dpa echo frame,media_type,stream_index,key_frame,pkt_pts,pkt_pts_time,pkt_dts,pkt_dts_time,best_effort_timestamp,^ best_effort_timestamp_time,pkt_duration,pkt_duration_time,pkt_pos,pkt_size,^ Width,Height,pix_fmt,sample_aspect_ratio,pict_type,coded_picture_number,display_picture_number,^ interlaced_frame,top_field_first,repeat_pict,color_range,color_space,color_primaries,color_transfer,^ chroma_location > "%%~na_ffprobe.csv" echo No. pts_time type > "%%~na_AllFrames.txt" ver > nul set /a Number=0 ffprobe.exe -v quiet -select_streams v:0 -print_format csv -show_entries frame "%%~nxa" >> "%%~na_ffprobe.csv" for /F "tokens=4,6,18,19 delims=," %%b in ('findstr "video" "%%~na_ffprobe.csv"') do ( set "x=%%b" set "y=%%c" set "z=%%d" set "w=%%e" set "v=%%f" set "u=%%g" set sort=!y:~0,-7! ::if !sort! GEQ 0 if !sort! LEQ 10 echo !count! !y:~0,13! !x! !w:~0,1! >> "%%~na_AllFrames.txt" echo !count! !y:~0,13! !x! !w:~0,1! >> "%%~na_AllFrames.txt" set /a count+=1 set /a ekko=count%%100 if !ekko! EQU 0 echo Frame !count! processed ) ) rem pause
[Attachment 59497 - Click to enlarge] -
Thanks, butterw, for your advice. I couln't get avisynth to work with my Windows 7 PC.
VirtualDub2 said the video had 5016 frames, so now I have 3 different counts:
MediaInfo says 5000 frames
ffprobe says 5018 frames
VirtualDub 2 says 5016 frames
Budman1's advice looks helpful, but as a newcomer to video editing it may take a while for me to understand the code. -
MediaInfo only shows the duration to the nearest second (truncated, not rounded) when the length exceeds 1 minute. So that calculation isn't accurate.
Reference frames aren't something that's added to the frame count. It simply additional information about the frames -- it means the predicted frames can reference as many as two other frames.
Looking at a short AVC MTS file I have here: Opening the video in VirtualDub2 shows 1092 frames. ffprobe shows 1095 frames. Opening the video in AviSynth with LWlibavVideo source shows 1095 frames. Comparing the frames opened by VirtualDub2 and AviSynth shows that VirtualDub2 is leaving out the last three frames. ffprobe shows those last three frames are BBP. Since AviSynth and ffprobe agree, and AviSynth can display three more frames than VirtualDub2, I would say AviSynth and ffprobe are correct.Last edited by jagabo; 23rd Jun 2021 at 10:53.
-
These responses have been very helpful. It seems obtaining an accurate frame count might best be acheived by using ffprobe, then confirming the result with avisynth. (I found avisynth worked if I changed the "encoding", written with Notepad, to ANSI).
As well as a basic frame count, budman1's code gives extra information which prompts 2 questions:
(1) Results are displayed in 4 columns, but there are only 3 headings (frame no., pts_time, type)
In the following extract, what does column 3 represent? (It's usually 0 or 1)
No. pts_time type
0 1.040000 0 B
(2) I'm confused by the first entry, where pts_time is 1.04 seconds.
The value for each subsequent frame increases by 0.04 seconds, so why isn't the first entry zero or 0.04 seconds? -
The 0 or 1 column is because some "I" frames are not always key frames. The 1 verifies that it is recognized as a key frame. So the 1 I, 0 B, 0 P go together as frame type.
The first frame is not always 0.000000. FFprobe reports what it actually is. Each frames after that should be 1/fps increase.
1.04 is because the first frame is a B frame. This video will include B frame up to the next I frame in some players and other players will not display it.
The first frame is normally 0.000000 up to several frame times. E.G. 0.022057.
1.04 first frame pts needs fixed or problems may occurLast edited by Budman1; 29th Jun 2021 at 10:08.
-
No problem... i use thqe script a lot for problems encountered with cutting,splicing, etc.
If you open the CSV file, it shows a lot more infirmation about the file
Similar Threads
-
Possible New frame accurate cut/merge Program
By Budman1 in forum EditingReplies: 2Last Post: 1st Feb 2020, 03:14 -
ffmpeg vs ffprobe frame count speed
By Anime4000 in forum Newbie / General discussionsReplies: 6Last Post: 12th May 2019, 05:05 -
How can I check the frame count of my video (without MediaInfo)?
By synnchan in forum Newbie / General discussionsReplies: 10Last Post: 26th Dec 2018, 20:13 -
Frame accurate H264 Editor
By 557953 in forum EditingReplies: 5Last Post: 24th May 2018, 15:15 -
Frame-accurate trimmer with subtitle support
By Schmengland in forum EditingReplies: 20Last Post: 9th May 2018, 16:43