Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write text to video #110

Open
sugizo opened this issue Mar 16, 2024 · 1 comment
Open

write text to video #110

sugizo opened this issue Mar 16, 2024 · 1 comment
Labels
question Further information is requested

Comments

@sugizo
Copy link

sugizo commented Mar 16, 2024

objective
write text to video, e.g. using cv2.putText

code

from imageio_ffmpeg import read_frames, write_frames
import cv2
input_file = 'http://195.196.36.242/mjpg/video.mjpg'
output_file = 'rtsp.mp4'
reader = read_frames(input_file)
meta = reader.__next__()
writer = write_frames(output_file,
                      size = meta['size'], fps = meta['fps'],
                      input_params = ['-y', ],
                      output_params = ['-vf', 'scale = 720 : -2', ] )
writer.send(None)
i = 0
text = 'stifix'
font = cv2.FONT_HERSHEY_SIMPLEX
org = (00, 185)
fontScale = 1
color = (0, 0, 128)
thickness = 2
for frame in reader:
    img = np.frombuffer(frame, np.uint8).reshape(meta['size'][1],
                                                 meta['size'][0], -1)
    #put_text = cv2.putText(img, text, org, font, fontScale, color, thickness, cv2.LINE_AA, False) # not work
    put_text = np.ascontiguousarray(cv2.putText(img, text, org, font, fontScale, color, thickness, cv2.LINE_AA, False) ) # not work
    writer.send(put_text)
    if i == 9: # 100 = 6 secs
        break
    i += 1
writer.close()

result
no error occured
but output video have no text written

expected result
video output have text written

best regards

@almarklein
Copy link
Member

I'd write the frames to image files using imageio and see if the text is visible there. If not, it's likely related to the putText cal.

@almarklein almarklein added the question Further information is requested label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants