Last active
November 27, 2018 13:56
-
-
Save francois-baptiste/d165c48627bc41c255f9a79bcda3e483 to your computer and use it in GitHub Desktop.
On the fly video overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from skvideo import io | |
vreader = io.vreader('input.mp4') | |
vwriter = io.FFmpegWriter('output.mp4') | |
for counter, frame in enumerate(vreader): | |
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) | |
alpha = 0.4 # Transparency factor. | |
cv2.putText(img=frame, | |
text="frame={}".format(counter), | |
org=(100, 500), | |
fontFace=cv2.FONT_HERSHEY_SIMPLEX, | |
fontScale=8.0, | |
color=(127, 127, 255), | |
thickness=5, | |
lineType=cv2.LINE_AA) | |
frame = cv2.addWeighted(frame, alpha, frame, 1 - alpha, 0) | |
vwriter.writeFrame(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) | |
print(counter) | |
writer.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment