VideoHelp Forum
+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 31 to 34 of 34
Thread
  1. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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:

    Code:
    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"
    COMMAND LINE USES 1 '%', FOR CUT TIME, BATCH FILE USES 2

    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:

    Image
    [Attachment 66378 - Click to enlarge]


    as a text file:
    frame,1,0,0.000000,Iside_data,
    frame,1,128000,10.000000,I
    frame,1,256000,20.000000,I
    frame,1,384000,30.000000,I

    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.
    Quote Quote  
  2. Originally Posted by BosseB View Post
    So I am back again with the most basic question:
    QUESTION:
    Is there a command (ffmpeg or ffprobe), which can be used to find the closest frame border before or on the given cut start point?
    You can find it with clever FFmpeg-GUI.
    Load your file, click main, click cut, insert your desired start point and click Key Frames.
    The programm will show you the exact cut point.

    Image
    [Attachment 66379 - Click to enlarge]
    Quote Quote  
  3. Member
    Join Date
    Feb 2021
    Location
    Sweden
    Search Comp PM
    Originally Posted by ProWo View Post
    You can find it with clever FFmpeg-GUI.
    Load your file, click main, click cut, insert your desired start point and click Key Frames.
    The program will show you the exact cut point.
    Well, I need to script it on Linux (Ubuntu 20.04 LTS server) so a GUI style program will not really work.
    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.
    Big difference.
    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.

    EDIT:
    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 12:46. Reason: Tested suggested solution with bad result
    Quote Quote  
  4. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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
    0,400,0.033367,B
    0,800,0.066733,P
    0,1200,0.100100,B
    0,1600,0.133467,B
    0,2000,0.166834,B

    -vframes is more accurate but may likely end on an incorrect frame during normal common IBBBPBBBPI sequence "
    0,0,0.000000,B
    0,400,0.033367,B
    0,800,0.066733,P
    0,1200,0.100100,B
    0,1600,0.133467,B
    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.

    Image
    [Attachment 66428 - Click to enlarge]

    Image
    [Attachment 66429 - Click to enlarge]



    (Cut at 5 and 80 seconds /30FPS/250 GOP)
    1,0,0.000000,I
    1,100000,8.341675,I
    1,200000,16.683350,I
    1,300000,25.025025,I
    1,900000,75.075075,I
    1,1000000,83.416750,I
    1,1100000,91.758425,I
    1,1200000,100.100100,I

    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.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!