半醉残影 - ffmpeg
type: channel
link: https://mars.dengyb.com/tag/ffmpeg/
items: ffmeg常用命令

ffmeg常用命令
type: item
date: 2021-10-29T13:14:00+08:00
description: 视频加图像水印ffmpeg -i a.mp4 -i b.png -filter_complex overlay=x=0:y=0 out.mp4 # 每个30s 加3s水印 ffmpeg -i 1.mp4 -i 123.png -filter_complex "overlay=x=0:y=0:enable='lt(mod(t,30),3)'" -y out.mp4 ffmpeg -i 1.mp4 -i header1.mov -t 15 -filter_complex "amix=inputs=2:duration=longest;[1]scale=iw*0.5:-1[open];[0][open]overlay=x=0:y=0:repeatlast=0[o1];movie=water.png [watermark];[o1][watermark]overlay=x=0:y=0:enable='gte(t,4)'[o1];[o1]subtitles=y2.ass[o1]" -map "[o1]" ooo.mp4图片给合成视频ffmpeg -f image2 -i image%d.jpg video.mpg ffmpeg -f image2 -r 60 -i output_%05d.png 1080p.mp4 ffprobe jsonffprobe -v quiet -print_format json -show_format -show_streams a.mp4 ffprobe -v quiet -print_format json -show_format -show_streams -i 2.mp4 视频截取裁剪视频按时间ffmpeg -i 1.mp4 -vcodec copy -acodec copy -ss 00:01:00 -to 00:02:59 ./1_cut.mp4 -y ffmpeg -ss [start] -t [duration] -i [in].mp4 -c:v libx264 -c:a aac -strict experimental -b:a 98k [out].mp4 def split_by_time(self, index, s, e): dst = os.path.join(self.cache_video, "%s.mp4" % index) args = ["ffmpeg", "-accurate_seek", "-i", self.media_path, "-ss", str(s), "-to", str(e), "-c:v", "libx264","-c:a", "copy", "-strict","experimental","-avoid_negative_ts", "1",dst, "-y"] r = subprocess.run(args=args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") if r.returncode != 0: print(r) return print("success %s" % dst)按帧ffmpeg -i ./input.mp4 -vf "select=between(n\,20\,200)" -y -acodec copy ./output.mp4提取视频中的帧ffmpeg -i data/1_cut.mp4 -s 480x270 -vf "select=between(n\,5\,3569)*not(mod(n\,5))" -vsync 0 "data/sc/image-%05d.jpg"主体是一个select 的过滤语句：其中：between(n,*) 是指 从第几帧到第几帧之间进行提取...not(mode(n, K))是指每隔几帧输出一帧。使用between可以指定需要提取开始帧和结束帧的位置，如果想要对视频中所有的帧进行间隔采样，命令如下command_extract = "select=(gte(n\,%d))*not(mod(n\,%d))"%(60,60) com_str = 'ffmpeg -i ' + video_path + ' -vf "%s" -vsync 0 '%command_extract + save_jpg_tmp_path + '/%06d.jpg'按时间间隔取帧 commands := []string{ `-i`, src, "-s", "192x108", "-vf", `select=(gte(t\,0))*(isnan(prev_selected_t)+gte(t-prev_selected_t\,1)…