Harun Sasmaz
Harun Sasmaz

Reputation: 231

Golang tgbotapi v5: sendVideo has wrong aspect ratio on iOS

I am using v5.5.1 of go-telegram-bot-api to send videos with the following code. However, the actual aspect ratio 4:5 is broken and video seems as 1:1 on iOS devices.

I also have MacOS and videos have correct aspect ratio on desktop app. Can this be an app issue? Because when I download videos to my device gallery, aspect ratio seems correct.

All videos are guaranteed to have 4:5 ratio and they are .mp4 format.

import (
    tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

func SendVideo(channel int64, path string, caption string) error {
    video := tgbotapi.NewVideo(channel, tgbotapi.FilePath(path))
    video.ParseMode = "html"
    video.Caption = caption

    _, err := c.bot.Send(video)

    return err
}

Upvotes: 3

Views: 473

Answers (1)

Alexander Kuznetsov
Alexander Kuznetsov

Reputation: 46

I encountered the same problem. I think there might be something wrong with telegram endpoint itself, because if you send the exact same problematic file by yourself it's keeping the correct aspect ratio, but if you send it through the bot, then aspect ratio is broken.

I found a workaround by explicitly specifying height and width of a video in a request to the endpoint: https://core.telegram.org/bots/api#sendvideo.

In your case, you can try running ffprobe on a video file and specifying it like:

video.Height = "video height from ffprobe output"
video.Width = "video width from ffprobe output"

Run ffprobe -v error -select_streams v -show_entries stream=width,height -of json input.mkv to get height and width in a JSON format

Upvotes: 1

Related Questions