Index:
Usage
In daily test, I need to add number watermarker to the bitstream, then dump it to different yuv formats.
Opencv environment setup
Do not setup it unless you can want encouter maigc errors.
- freetype
- ffmpeg codec
- xxxx
So use docker to do it:
1 | docker run -it -v "${HOME}":"${HOME}" opencvcourses/opencv-docker /bin/bash |
read and write bitstream by frames with opencv2
1 | cap = cv2.VideoCapture(args.input) |
use freetype to render the string and add to frame
1 | def add_watermark_to_frame(frame, txt, text_height,offset): |
Show new frame with opencv2
1 | cv2.imshow("Video", frame) |
font load note
- the code will auto load “UbuntuMono-Regular.ttf” to render the picture with freetype, please put this font to the script dir
- the code need opencv2 support, install it by yourself
Usage Guide
Code Help:

Basic Usage:
It will get first 10 frames and add number watermarker in each frame, then save to output.mp4 file.
1 | python3 cv_watermark.py -i origin.mp4 -o output.mp4 -n 10 |

Advanced Usage:
It will get first 10 frames and add number watermarker in each frame, then save to output.mp4 file.
1 | python3 ./cv_watermark.py -i Mix_BostonHarbor_MainStreet_GrandBendPatio_1920x1088.mp4 -prefix "AMD is awesome: " -s |

Parameters Guide
| parameter | description |
|---|---|
| test | tset |
| i | input bitstream file name |
| n | frame number |
| o | output bitstream file name |
| ox | watermarker offset x in target bitstream |
| oy | watermarker offset y in target bitstream |
| prefix | prefix info in front of the number watermarker |
| s | show the picture frame by frame, q: exit ; space : next frame |
| th | watermarker text height |
Talk is cheap, show me the code
1 | #!/usr/bin/env python3 |