视频加图像水印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))`, "-vsync", "0", "-y", path.Join(dst, `%05d.jpg`), } ffmpeg -i -vf "select=(gte(t\,0))*(isnan(prev_selected_t)+gte(t-prev_selected_t\,21))" -vsync 0 image_%05d.jpg ffmpeg -i -vf "select=(gte(t\,120))*(isnan(prev_selected_t)+gte(t-prev_selected_t\,120))" -vsync 0 image_%05d.jpg上面命令中的120的单位是s，指每120s提取视频中的一帧图像视频信息获取获取帧总量ffprobe -i .\data\1_cut.mp4 -select_streams v -show_entries stream=nb_frames -of default=nk=1:nw=1 -v quiet获取视频总时长ffprobe -select_streams v -show_entries stream=duration -of default=nk=1:nw=1 -v quiet视频切图ffmpeg -i 2332103105.mp4 -vf "crop=540:540:0:420" -s "384x216" -y out.jpg 缩小视频并且加上水印ffmpeg -i demo.mp4 -vf "movie=preview.watermark.png [watermark]; [in]scale=640:360 [scale]; [scale][watermark] overlay=0:0" c.mp4 多轨道视频叠加[0]表示第一个输入，[1]表示第二个输入，大写W表示第一个宽，小写w表示第二个宽ffmpeg -i a.mp4 -i b.mov -filter_complex "[1]scale=iw*0.5:-1[open];[0][open]overlay=W/2:H/2" -vcodec libx264 -acodec aac out.mp4 -y # repeatlast表示不统一长度，该结束就结束 ffmpeg -i 1.mp4 -i open.mov -t 10 -filter_complex "amix=inputs=2:duration=longest;[1]scale=640:-1[open];[0][open]overlay=x=0:y=0:repeatlast=0, subtitles=1.ass" out.mp4 -y删除所有音轨ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4加黑边 ffmpeg -i demo.mp4 -vf 'scale=1080:608,pad=1080:810:0:106:black' y.mp4缩放裁剪ffmpeg -i 1-1080p.mp4 -vf "scale='3413:1920',crop='1080:1920:1160:0'" -c copy -threads 4 -vcodec libx264 -y 1-1080p-h.mp4给视频加高斯模糊边框ffmpeg -i 2.mp4 -vf "split[a][b];[a]scale=3413:1920,crop=1080:1920:1160:0,boxblur=15:15[1];[b]scale=1080:608[2];[1][2]overlay=0:(1920-608)/2" -c copy -threads 4 -vcodec libx264 -y 2-out.mp4生成静音音频ffmpeg -f lavfi -t 10 -i anullsrc test.aac -y`-bsf:v`, `h264_mp4toannexb`,给视频图片加上文字水印ffmpeg -i 640.jpg -filter_complex "[0]scale=220:-1[img];[img]drawtext=text='07\:43':x=w-tw-10:y=h-th-10:fontsize=24:fontcolor=white:borderw=2:bordercolor=black" o-3.jpg -y# 封面添加文字 ffmpeg -i 1.png -filter_complex "[0]scale=1920:1080[img];[img]drawtext=x=(w-tw)/2:y=(h-th)/2:fontfile=1.ttf:fontsize=160:fontcolor=white:borderw=10:bordercolor=orange@0.8:box=0:boxborderw=5:boxcolor=black:shadowcolor=red:textfile=1.txt:line_spacing=80" o.jpg -y滚动文字 ffmpeg -i 1.mp4 -t 10 -vf "drawtext=text=string1 string2 string3 string4 string5 string6 string7 :expansion=normal:fontfile=1.ttf: y=h-line_h-10:x=(mod(5*n\,w+tw)-tw): fontcolor=white: fontsize=40: shadowx=2: shadowy=2" output.mp4 ffmpeg -i 1.png -filter_complex "[0]scale=1920:1080[img];[img]drawtext=x=(w-tw)/2:y=(h-th)/2:fontfile=font/fonts/25.ttf:fontsize=140:fontcolor=white:borderw=14:bordercolor=orange@0.9:box=0:boxborderw=5:boxcolor=black:shadowcolor=red:textfile=1.txt:line_spacing=40" o.jpg -y视频封面生成# https://blog.csdn.net/toopoo/article/details/105603154 ffmpeg -i a.mp4 -frames:v 1 -y a.jpg生成纯黑视频 ffmpeg -f lavfi -i color=black:1920x1080:d=3 -format rgb32 -f matroska -vcodec libx264 test1.mp4延长视频时间# 调整视频流速度的setpts和调整音频流的atempo应是互为倒数的， # 这样才能保证新视频里画面和声音同步。 # 只缩放视频 ffmpeg -i open.mov -filter_complex "setpts=2*PTS" open2.mov # 声画同步 ffmpeg -i input.MOV -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" video.mp4ff录屏ffmpeg -y -f gdigrab -t 25 -r 30 -i desktop -draw_mouse 0 -c:v h264_amf 1.mp4pix_fmt yuv420p缩放裁剪视频// 裁剪视频，缩放裁剪视频到1080p func (t *VideoTask) cropVideo(srcPath, dstPath string, width, height int64) error { //计算视频尺寸 j := lib.GetFileParam(srcPath, "video") videoWidth := j.Get("width").Int() videoHeight := j.Get("height").Int() lib.ReportLog(t.task.Id, fmt.Sprintf("协程[%d] 视频原始尺寸：%dx%d, 缩放裁剪到：%dx%d \n", t.taskId, videoWidth, videoHeight, width, height)) // 如果视频尺寸和目标尺寸相同，直接返回 if videoWidth == width && videoWidth == height { lib.CopyFile(dstPath, srcPath) return nil } var format string = "" videoRate := float64(videoWidth) / float64(videoHeight) dstRate := float64(width) / float64(height) if videoRate == dstRate { // 等比例的直接缩放 format = fmt.Sprintf("scale=%d:%d", width, height) } else if videoRate > dstRate { // 如果原视频的宽高比大于目标视频，则说明原视频宽度有多余，缩放高，裁剪宽 dstVideoWidth := float64(height) / float64(videoHeight) * float64(videoWidth) beginWidth := (dstVideoWidth - float64(width)) / 2 format = fmt.Sprintf("scale=-1:%d,crop=%d:%d:%d:0", height, width, height, int(beginWidth)) } else { // 如果原视频的宽高比小于目标视频，则说明原视频高度有多余，缩放宽，裁剪高 dstVideoHeight := float64(width) / float64(videoWidth) * float64(videoHeight) beginHeight := (dstVideoHeight - float64(height)) / 2 format = fmt.Sprintf("scale=%d:-1,crop=%d:%d:0:%d", width, width, height, int(beginHeight)) } commands := []string{ "-i", srcPath, "-filter_complex", format, "-acodec", "mp3", "-vcodec", "libx264", "-pix_fmt", "yuv420p", "-y", dstPath, } cmd := exec.Command("ffmpeg", commands...) b, err := cmd.CombinedOutput() if err != nil { log.Printf(string(b)) log.Println(commands) lib.ReportLog(t.task.Id, fmt.Sprintf("协程[%d] 命令:%s\n异常:\n%s", t.taskId, commands, string(b))) return err } return nil }ffmpeg 重复，延长时间ffmpeg -i in.mp4 -vf tpad=stop_mode=clone:stop_duration=2 out.mp4 ffmpeg -i i1.mp4 -filter_complex "[0]scale=640:360[o1];[o1]tpad=start_mode=clone:start_duration=3" -y ddd.mp4png转movffmpeg -r 80 -i img/%03d.png -vf fps=60 -vcodec qtrle out.mov -y叠加水印并把图像转成视频ffmpeg -i 1.png -i 2.png -filter_complex "overlay=0:0[o1];[o1]tpad=start_mode=clone:start_duration=5" -vcodec libx264 -r 32 -y 3.mp4视频是否异常ffmpeg -i 1.mp4 -v error -f null -合并视频ffmpeg -f concat -i filelist.txt -c copy -y z1.mp4png转rgbaffmpeg -i demo.png -filter_complex "format=rgba" demo1.png -y