Not sure how your programming is used but I routinely obtain a list of cut points of key index points in order to accurately join segments without 'artifacts' at cut point.
I f you used the following for a suggested cut at 9 seconds:
COMMAND LINE USES 1 '%', FOR CUT TIME, BATCH FILE USES 2Code:C:\UsersFull path to\ffprobe.exe -i "C:\Full path to\video.mp4" -select_streams v:0 -print_format csv -skip_frame nokey -show_entries frame=pkt_pts,pkt_pts_time,pict_type,key_frame -read_intervals 9.000000%+#1000 >> "C:\full path to\ffprobe.csv"
The format for this, if you are not familiar is:
-select_streams v:0 = use stream 0 video
-print_format csv = output as a csv speadsheet (it is also a text file separated by ',')
-skip_frame nokey = skip all frames that are not key frames
-show_entries frame=pkt_pts,pkt_pts_time,pict_type,key_frame = show only key frame indicator, the actual pts of that frame, the frame type and a time packet pts time.
-read_intervals 9.000000%+#1000 = read intervals from 9 seconds until a 1000 frames after. Since the key frames on my test video was 0,10,20,30 it will show the preceding key frame and 1000 frames after. The reason i use 1000 is the maximum normal GOP distance between key frames in an AVS (Most common) encoding is 250 so this gives you the preceding key frame and 3 after. You can shorten it to 251 so you include only the preceding and the following if you wish.
you will get a list of all frames in a spreadsheet format:
[Attachment 66378 - Click to enlarge]
as a text file:
FRAME = 'i'M A FRAME
1= I'M REALLY A KEY FRAME
128000 = PACKET PRESENTATION TIME
0.000000 and 10.000000 = pts OR KEY FRAME TIME (POSSIBLE CUT TIME before and after 9 seconds)
i = PICTURE (FRAME DESIGNATED TYPE)
One thing I might point out that I have found and use during cut/paste is that Cutting with ffmpeg will arbitrarily change the last pts time to sometimes twice the duration if the last frame of the sequence is a 'B' frame or not a true 'P' frame. The best method is to cut at the 'P' frame just before the next 'I' frame.
Ths can be checked by omitting the -skip_frame nokey and you will get all the frames information for 1000 frames:
frame 1 0 0 Iside_data
frame 0 512 0.04 B
frame 0 1024 0.08 B
frame 0 1536 0.12 B
frame 0 2048 0.16 P
frame 0 125440 9.8 P
frame 0 125952 9.84 B
frame 0 126464 9.88 P
frame 0 126976 9.92 B
frame 0 127488 9.96 P
frame 1 128000 10 I
I hope you can use this information is of use.
+ Reply to Thread
Results 31 to 34 of 34
Each video file I process has about 6-8 sections to extract and concat. So there are that many position,length time pairs for each.
But I have also found out that there is no good way to run the cut extraction and concat in a single ffmpeg command using exact cut points.
I can do it like that with the original cut points but then the video is re-rendered even though all cuts come from the same video file.
Re-rendering takes a long time, up to 10-15 minutes for my kind of videos.
By just extracting and then concat with copy via a file containing the video snippets file names, the operation just takes a few seconds.
I had hoped that by extracting on the frame borders it would be possible to get rid of the artifacts and still use the quick copy concat.
Seems not possible.
Tried the program you suggested anyway and it immediately crashed when I had given it the start/end as 00:27 and 15:29.
Really bad that one cannot enter the times in decimal seconds, makes for a lot of clicking...
Last edited by BosseB; 23rd Aug 2022 at 11:46. Reason: Tested suggested solution with bad result
I will try again to explain as succinctly as possible (I tend to use pictures) why you have been unsuccessful up to now.
1. You use -ss starttime PRECEDING your -i input. This causes ffmpeg to seek to the PRECEDING Key frame (I frame)
If you use -ss AFTER the -i input, ffmpeg will generally seek to the I frame AFTER the cut point
Start cuts must be specified exactly e.g.:
0 0.000000 1 I
250 8.341675 1 I
500 16.683350 1 I
750 25.025025 1 I
1000 33.366700 1 I
2. You use -t or -to for your length. FFmpeg will cut approximately where you want but the last frame of the cut may be incorrect in its presentation time causing a glitch when added to a following segement:
0,0,0.000000,B (NOT VALID I FRAME TO START
-vframes is more accurate but may likely end on an incorrect frame during normal common IBBBPBBBPI sequence "
0,2400,0.200200,P (pts IS DOUBLE FROm PRECEDING FRAME CAUSING FREEZE FRAME AFTER CONCAT)
The only reliable way to cut and paste videos is to cut exactly at an I frame and end on a valid P frame (Closed GOP). In order to do this, you must use several operations.
The above data and previous post data was extracted with drag/drop CMD files
1. Get the key frame before and after your cut to see if you can live with either. If not, the segment must be encoded.
2. Make sure the end point is exactly on a valid P frame.
[Attachment 66428 - Click to enlarge]
[Attachment 66429 - Click to enlarge]
(Cut at 5 and 80 seconds /30FPS/250 GOP)
frame video 0 0 98800 8.241575 B
frame video 0 0 99200 8.274942 B
frame video 0 0 99600 8.308308 P
frame video 0 1 100000 8.341675 I
You can do this in several separate CMD operations or try to use specifically designed GUI.
Many of the GUI programs to cut/paste are also not frame accurate since many use ffmpeg as their engine.