Last active
August 16, 2018 10:34
-
-
Save wwwins/587fce3321815f1ca5148581bf4629aa to your computer and use it in GitHub Desktop.
ffmpeg tips
This file contains hidden or 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
# video to image by fps | |
ffmpeg -i in.mp4 -vf fps=1/5 pic%03d.png | |
# video to image by input seeking | |
ffmpeg -ss 5 -i in.mp4 -frames:v 1 pic.png | |
# https://trac.ffmpeg.org/wiki/Seeking | |
# cut from 00:05 to 00:10 | |
ffmpeg -ss 00:05 -i in.mp4 -t 00:05 -c copy -copyts out.mp4 | |
# segment video | |
ffmpeg -i in.mp4 -c copy -f segment -segment_time 10 out%03d.mp4 | |
ffmpeg -i in.mp4 -c copy -f segment -segment_time 10 -reset_timestamps 1 out%03d.mp4 | |
ffmpeg -i in.mp4 -c copy -map 0:0 -f segment -segment_time 5 -reset_timestamps 1 out-%03d.mp4 | |
# segment video into small chunks(2s) | |
ffmpeg -i in.mp4 -segment_time 2 -g 60 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*60)" -f segment -preset veryfast out-%03d.mp4 | |
# show frames information | |
ffprobe -show_frames -pretty in.mp4 | |
# get h264 rawvideo | |
ffmpeg -i out1-000.mp4 -c copy -f h264 out1-000.h264 | |
ffmpeg -i out1-001.mp4 -c copy -f h264 out1-001.h264 | |
... | |
# concat demuxer | |
# https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg | |
# >cat files | |
# file '/Users/XXX/demo/concat/./out1-006.h264' | |
# file '/Users/XXX/demo/concat/./out2-002.h264' | |
# file '/Users/XXX/demo/concat/./out1-002.h264' | |
ffmpeg -f concat -safe 0 -i files -c copy output1.mp4 | |
# concat protocol | |
# convert to ts | |
# https://trac.ffmpeg.org/wiki/Concatenate | |
ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intro.ts | |
ffmpeg -i text1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts text1.ts | |
... | |
ffmpeg -i end.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts end.ts | |
ffmpeg -i "concat:intro.ts|text1.ts|text2.ts|text3.ts|end.ts" -c copy output.mp4 | |
# merge audio | |
# https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg | |
ffmpeg -i output1.mp4 -i audio.aac -c copy output2.mp4 | |
# convert video for iOS | |
# https://trac.ffmpeg.org/wiki/Encode/H.264 | |
ffmpeg -i output2.mp4 -preset veryfast output2-veryfast.m4v | |
# convert video for swf | |
ffmpeg -i output2.mp4 -preset veryfast output2-veryfast.swf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment