-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to seek to and cut from a frame in ffmpeg? #1216
Comments
when I used normal cut, but not keyframe cut if you cut it wrong you get black frames if you cut from the wrong place because the keyframe got cut out Why do I have to use the normal cut? Because I want to cut off some trailing frames at the end, since that's not an issue (we have the previous keyframe, just cutting more frames off won't always be problematic) So you may want to treat "beginning" segments and "ending" markers differently |
Hi, Thanks for your reply on #717. I deleted my post because I said something wrong. My goal is to use the split method from losslesscut to cut exactly a video in 2. However this does not work well since it is not cutting exactly at the same place for both segments. Meaning that if you concat the 2 segments you will have at the trim position, duplicate frames, not always near each other. I try to reproduce the behavior of losslesscut and try other things. I used smart cut.
Here a reproducible example with bash Maybe this can be useful ... in.mp4 is from a Gopro11, codec was converted to h264 (it was h265), this is the only thing I did with the original video. Here the code and console output: Lets take a random keyframe from in.mp4:
kf=$(ffprobe -v error -select_streams v -show_frames -print_format csv in.mp4 | grep 'frame,video,0,1' | head -20 | tail -1 | perl -pe 's|frame,video,0,1,.?,(.?),.*|\1|') Lets select keyframe at 3.803792. Here are the timestamps of the all the frames from in.mp4 around this keyframe.
Lets compare 2 methods of split: actual losslesscut 3.53.0 and another one Method 1 - Losslesscutif I use the split method at timeframe 3.803792 it will run
Timestamps of in_seg1.mp4:
we see that it is taking 1 or 2 frames too much,always at least the KF Method 2The only good solution and reproducible that I found it to set the -t to 2 frames before the keyframe wanted kf2=$(ffprobe -v error -select_streams v -show_frames -print_format csv in.mp4 | perl -pe 's|frame,video,0,.,.?,(.?),.*|\1|' | grep --color -B 2 3.803792 | head -1)
Lets take then 3.770417 instead of 3.803792
now it it stopping just before the keyframe 3.803792. Concat seg1 and seg2 from each method to compare.
Lets check the frame MD5 to see the difference between the 2 methods:
lastframe from in_seg1b.mp4 is df14f6ef759edaf25ce112301ca804d9 in_seg1.md5
in_seg1b.md5
in.md5
Lets check the next frame after lastframe in in.mp4 and find it again in the combine seg1 and seg2 in each method. lastframe from in.mp4 is e9c6c1edea17faf8157fb42dd4b78f46 out.md5
outb.md5
This one is not found in either of both ... Duplicates in out.mp4
Duplicates in outb.mp4
|
next nightly build will have a new Export Option called "Shift all start times", it can be used to automatically shift all segment start times forward by one or more frames when cutting. This can be useful if the output video starts from the wrong (preceding) keyframe. |
Is this already implemented ? I was looking everywhere in v3.64.0.0 but did not find it ? did I missed it ? |
You need to enable the export cofnrim dialog. Then it should be under «advanced» |
I tried the options and did not get what I wanted but I am actually not sure what you expect and which condition. |
This is the age-old question that I have not yet found a definite answer to:
How does seeking (
-ss
) actually work in ffmpeg?More specifically:
-c copy
)This has been discussed in #13 #1087 #126 #330 #1513 #1585 #1855. This also affects smart cut.
To complicate further:
Concerns:
ffprobe show_entries packet=pts_time,flags
are correct. Or should we instead usebest_effort_timestamp_time
?Options:
The text was updated successfully, but these errors were encountered: