I have a text subtitle srt with coordinates example 270,270 video + sub srt
https://mega.nz/folder/WgYHzBaQ#OzYZ7xL0K1r-nZacjGI_Nw
Result
When using "Pillow" or "opencv" or "tkinter" It gives you not the same coordinates. How can I get the same coordinates "{\pos(270,270)}Test" In the pictures above
Pillow
OutputCode:from PIL import Image, ImageDraw, ImageFont # Load the image image = Image.open("1.jpg") # Create a drawing context draw = ImageDraw.Draw(image) # Define the text properties font = ImageFont.truetype("Arial.ttf", 36) text = "test" text_color = (255, 255, 255) # Calculate the position to center the text text_length = draw.textlength(text, font) x = 270 y = 270 # Add text to the image draw.text((x, y), text, fill=text_color, font=font) image.show()
https://i.imgur.com/pYXkCYw.jpeg
opencv
OutputCode:import cv2 myimg = "1.jpg" img = cv2.imread(myimg) f_face = cv2.FONT_HERSHEY_PLAIN f_size = 1 f_color = (255,255,255) f_thickness = 2 text = 'Test' x,y = 270,270 img = cv2.putText(img, text, (x,y), f_face, f_size, f_color, f_thickness) cv2.imshow("Test", img) cv2.waitKey(0) cv2.destroyAllWindows()
https://i.imgur.com/96Quqvo.jpeg
tkinter
Code:import tkinter as tk my_w = tk.Tk() my_w.geometry("640x360") # Size of the window l1=tk.Label(my_w,text='x=270,y=270',bg='yellow') l1.place(x=270,y=270) my_w.mainloop() # Keep the window open
Output
https://i.imgur.com/sugBA8h.jpeg
Does the pip modules give you the correct coordinates?
+ Reply to Thread
Results 1 to 5 of 5
-
Last edited by D.LUFFY; 15th Feb 2025 at 06:52.
-
All three examples were actually working, it placed text in about that 270x270 mark.
And your results also, it is where it suppose to be, not at that posted "Test" mark.
So your question is how to make a player to force srt exactly to those coordinates?
Respecting:
1
00:00:00,000 --> 00:00:28,000
{\pos(270,270)}Test
I don't know, not sure if srt can do it at all, more like some animated format, I'm no expert though.Last edited by _Al_; 15th Feb 2025 at 16:32.
-
Many players do not respond to tags like that in SRT files. Especially outside a Windows computer. They are not part of the SRT specification.
https://en.wikipedia.org/wiki/.srt
For players that do support the \pos tag, I've found:
Players appear to use a scaling system where 0,0 is the top left of the frame, and ~400x300 is the bottom right. So the absolute location they appear depends on the frame size of the video.
The subs are drawn so that the center of the text (horizontally) and the bottom of the text (vertically) is at the specified location. So the absolute location they appear varies with the length and height of the text. -
Thanks for the replies. I previously tried to create a script that gave the same wrong result.
-
I gave you all the information you need to calculate the x,y location in pixels from the x,y subtitle location.
Similar Threads
-
Distinguish Images with Text
By Subtitles in forum EditingReplies: 6Last Post: 13th Apr 2024, 08:15 -
Batch method to find images that contains only text !
By zyck in forum SubtitleReplies: 7Last Post: 19th Oct 2021, 21:52 -
Time of video and local mouse coordinates with MPV
By Gabrivolea in forum ProgrammingReplies: 6Last Post: 24th May 2021, 12:16 -
Aegisub - Correct workflow when importing a text file
By dynamique in forum SubtitleReplies: 1Last Post: 7th Jul 2020, 12:31 -
How do we remove video parts shown as text images
By jraju in forum Newbie / General discussionsReplies: 6Last Post: 27th Jun 2020, 22:20