VideoHelp Forum




+ Reply to Thread
Results 1 to 5 of 5
  1. 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

    Code:
    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()
    Output
    https://i.imgur.com/pYXkCYw.jpeg

    opencv

    Code:
    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()
    Output
    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?
    Last edited by D.LUFFY; 15th Feb 2025 at 06:52.
    Quote Quote  
  2. 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.
    Quote Quote  
  3. 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.
    Quote Quote  
  4. Thanks for the replies. I previously tried to create a script that gave the same wrong result.
    Quote Quote  
  5. I gave you all the information you need to calculate the x,y location in pixels from the x,y subtitle location.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!