Audio Video Merge
1 | ffmpeg -i video filename -i audio filename -codec copy output MP4 filename |
mp4 video stitching
1 | ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4 |
Enable Graphics Support
1 | ffmpge -hwaccel cuvid |
Add Watermark
Movie filters in detail
1
2
3
4
5
6
7
8
9
10ffmpeg -i inputfile -vf "movie=masklogo,scale= 60: 30[watermask]; [in] [watermask] overlay=30:10 [out]" outfile
Parameter description:
marklogo: the image of the watermark to be added;
scale: the size of the watermark, the length of the watermark * the height of the watermark;
overlay: location of the watermark, distance from the left side of the screen * distance from the top side of the screen; mainW main video width, mainH main video height, overlayW watermark width, overlayH watermark height
Upper left corner overlay parameter is overlay=0:0
Upper right corner is overlay= main_w-overlay_w:0
Bottom right corner is overlay= main_w-overlay_w:main_h-overlay_h
Bottom left is overlay=0: main_h-overlay_h
The 0 on the face can be changed to 5, or 10 pixels to allow for more white space.Timed Text Watermark
1
ffmpeg -re -i test.mp4 -vf "drawtext=fontsize=60:fontfile=lazy.ttf:text='{localtime\:%Y\-%m-%d %H-%M-%S}':fontcolor=green:box=1:boxcolor=yellow:enable=lt(mod(t\, 3)\, 1)" out.mp4
Add an image watermark
1
ffmpeg -i test.mp4 -vf "movie=logo.jpg[wm];[in][wm]overlay=30:10[out]" image_out.mp4
Add four image watermarks
1
ffmpeg -i in.mp4 -i logo.png -i logo.png -filter_complex "overlay=5:5, overlay=x=W-w:y=5" in_out_mul_watermark.mp4
Add two watermarks and specify the location and start time of disappearance.
1
2
3
4# Add two watermarks, the first one is displayed in the lower center, showing time 0-20 seconds, and the second one is displayed in the upper right, showing time 20-31 seconds.
ffmpeg -i intput.mp4 -i watermark1.png -i watermark2.png -filter_complex "overlay=enable='lte(t,20)':x=(W-w)/2:y=H-h:,overlay=enable='gt( mod(t,31),20)':x=W-w:y=0" output.mp4 -y
# Same as above to add graphics card support
ffmpeg -hwaccel cuvid -i intput.mp4 -i watermark1.png -i watermark2.png -filter_complex "overlay=enable='lte(t,20)':x=(W-w)/2:y=H-h:,overlay =enable='gt(mod(t,31),20)':x=W-w:y=0" -vcodec h264_nvenc output.mp4 -yAdd two watermarks that alternate for 10 seconds
1
2
3
4
5
6
7
8
9ffmpeg -i /root/test.mp4 -i /root/videoProcessing/youtube/test.png -i /root/test.png
-filter_complex “overlay=x=if(lt(mod(t,20),10),10,NAN ):y=10,overlay=x=if(gt(mod(t,20),10),main_w-273,NAN ) :y=main_h-113,subtitles=/root/test.srt :force_style=‘Fontsize=14’” /root/test3.mp4
Add two watermarks, overlay=x=if(lt(mod(t,20),10),10,NAN ):y=10,overlay=x=if(gt(mod(t,20),10),main_w-273,NAN ) These two use a function that represents that the watermarks are alternating.
mod(t,20) represents that the current time is modeled against 20;
lt(a,b) represents a<b, then true
if(true,a,b) means if true, then return a, otherwise return b
ps:If you need to do command line splicing in your program, you must remember to escape, otherwise you will report an error.
Video Splitting
1 | ffmpeg -v quiet -y -i S4.mp4 -vcodec copy -acodec copy -ss 00:00:00 -t 00:07:12 -sn S01E01.mp4 -ss denotes the start time of video segmentation, -t denotes the segmentation duration |
rm 转mp4
1 | ffmpeg -i gdg.rmvb -vcodec libx264 -c:v h264 -c:a aac gdg.mp4 |
flv to MP4
1 | ffmpeg -i aa!.flv -vcodec libx264 -c:v h264 -c:a aac aa.mp4 |
Batch Processing Video
1 | for %%G in (*.rmvb) do ffmpeg -i "%%~G" -c:v h264 -c:a aac "%%~nG.mp4" for %%G in (*.rm) do ffmpeg -i "%%~G" -c:v h264 -c:a aac "%%~nG.mp4" |
Other formats to MP3 scripts
1 | @echo off & title |
MP4 Batch Convert Files
1 | @echo off |
video compression
View Video Parameters
ffmpeg -i 1274.mp4 -b 600k 12.mp4 -b Data bit rate, the size of data traffic transmitted per second (kb/s), the bit rate set in this command is 600k, which is one-eighth of the original video.
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment