# ffmpeg 大全 ## 剪輯影片片段 10:00 至 15:00 ```bash=1 ffmpeg -i src.mp4 -ss 00:10:00 -t 00:05:00 -acodec copy -vcodec copy dst.mp4 ffmpeg -i src.mp4 -ss 00:10:00 -to 00:15:00 -acodec copy -vcodec copy dst.mp4 ``` ## make video by images ```bash=1 ``` ## water mark ### make water mark png of ag roi ```python=1 import numpy as np import cv2 VIDEO_WIDTH = 1920 VIDEO_HEIGHT = 1080 shape = (VIDEO_HEIGHT, VIDEO_WIDTH, 3) empty_frame = cv2.imread("/home/ubuntu/Desktop/aeaa.jpg") empty_frame = np.zeros(shape, dtype=np.uint8) x1=0.2128787878787879 x2=0.7583333333333333 y1=0.020188425302826378 y2=0.423956931359354 xl=VIDEO_WIDTH*x1 xr=VIDEO_WIDTH*x2 yt=VIDEO_HEIGHT*y1 yb=VIDEO_HEIGHT*y2 m = int(360*VIDEO_WIDTH/2688) start_w = (xr-xl) start_h = (yb-yt)*0.8 start_yb = (yt+(yb-yt)*0.8) end_yt = (yt+(yb-yt)*0.6) end_xl=xl-m end_xr=xr+m end_w=end_xr-end_xl end_h=yb-end_yt end_xl = (end_xl if (end_xl > 0) else 0) end_yt = (end_yt if (end_yt > 0) else 0) end_w = (VIDEO_WIDTH-end_xl if (end_xl+end_w > VIDEO_WIDTH) else end_w) end_h = (VIDEO_HEIGHT-end_yt if (end_yt+end_h > VIDEO_HEIGHT) else end_h) def draw_rectangle(img, x, y, w, h, color): left_up = (x, y) right_down = (x+w, y+h) # red thickness = 2 cv2.rectangle(img, (int(x), int(y)), (int(x+w), int(y+h)), color, 2) # cv2.rectangle(img, (125, 20), (175, 40), (255, 0, 255), -1) return img print("(shape, xl, yt, start_w, start_h)", shape, xl, yt, start_w, start_h) xxx = draw_rectangle(empty_frame, xl, yt, start_w, start_h, (0, 255, 0)) xxx = draw_rectangle(empty_frame, end_xl, end_yt, end_w, end_h, (255, 0, 250)) bgr = xxx gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY) alpha = gray>0 print(alpha.sum()) ones = np.ones(gray.shape, np.uint8) ones[alpha] = 255 ones[alpha==False] = 0 result = np.dstack([bgr, ones]) cv2.imwrite( "aeaa.jpg", bgr) cv2.imwrite( "aeaa.png", result) ``` ```bash=1 ffmpeg -i /mnt/video2/2020_Kbro/aeaa3652efcc42bfadfc4a56af988515/concat/01-22/frame_aeaa_0122.mp4 -i /mnt/video2/2020_Kbro/aeaa3652efcc42bfadfc4a56af988515.png -filter_complex "overlay=W-w:H-h" -b:v 6000K /mnt/video2/2020_Kbro/aeaa3652efcc42bfadfc4a56af988515/concat/01-22/frame_aeaa_0122_roi.mp4 -y & ffmpeg -i /mnt/video2/2020_Kbro/d60bd7d598394f3f909120b5b52a35e6/concat/01-22/frame_d60b_0122.mp4 -i /mnt/video2/2020_Kbro/d60bd7d598394f3f909120b5b52a35e6.png -filter_complex "overlay=W-w:H-h" -b:v 6000K /mnt/video2/2020_Kbro/d60bd7d598394f3f909120b5b52a35e6/concat/01-22/frame_d60b_0122_roi.mp4 -y & ffmpeg -i /mnt/video2/2020_Kbro/fb51b9a2aabf4f8da34651c9369195eb/concat/01-22/frame_fb51_0122.mp4 -i /mnt/video2/2020_Kbro/fb51b9a2aabf4f8da34651c9369195eb.png -filter_complex "overlay=W-w:H-h" -b:v 6000K /mnt/video2/2020_Kbro/fb51b9a2aabf4f8da34651c9369195eb/concat/01-22/frame_fb51_0122_roi.mp4 -y & ffmpeg -i frame_aeaa_0121.mp4 -i aeaa.png -filter_complex "overlay=W-w:H-h" -framerate 15 -b:v 10000K test2.mp4 ``` #### 期間增加浮水印: ``` bash=1 ffmpeg -i input.mp4 -i image.png \ -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \ -pix_fmt yuv420p -c:a copy \ output.mp4 ``` ## concate videos: ```bash=1 cat mylist.txt file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4 ```