Created
July 15, 2016 19:34
-
-
Save ymauray/3f60b17af407ac5a8d7ba8f4bd3f59f2 to your computer and use it in GitHub Desktop.
How to cut a video file on black keyframes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Re-encode source video with one keyframe every 5 frames | |
ffmpeg -i source.mkv -g 5 tmp.mkv | |
# Search black frames | |
ffmpeg -i tmp.mkv -vf blackframe -f null - | |
# Use output to locate black frames right on keyframes | |
# Then cut video at those keyframes | |
ffmpeg -i tmp.mkv -ss 6.089 -to 180.263 -c copy tmp2.mkv | |
# If the audio is not in sync with the video, detect silence | |
ffmpeg -i tmp2.mkv -map 0:1 -af silencedetect=d=.1 -f null - | |
# Use output to decide where to cut the audio | |
ffmpeg -i tmp2.mkv -map 0:1 -to 173.22 -c:a copy tmp2.ogg | |
# Merge reencoded video and shortened audio back together | |
ffmpeg -i tmp2.mkv -i tmp2.ogg -map 0:0:0 -map 1:0:1 -c:a copy -c:v copy output.mkv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment