10

Which video format can be used in Telegram Bot API sendVideo method?

On the page they only mention "H.264/MPEG-4 AVC"

So if I convert a video (without sound) with

ffmpeg -i input -an -c:v libx264 -crf 26 out.m4v

I get an ok:true as response but I can't see the preview (blurred still image) in the Telegram client.

Seyfi
  • 1,832
  • 1
  • 20
  • 35
Andy
  • 7,931
  • 4
  • 25
  • 45

2 Answers2

22

This was really driving me nuts: It's important that the file extension is ".mp4". If you upload a video with ".m4v" extension you'll not see a preview window and the video is opened in an external player.

So here is my final command to reencode and resize a video and send it to the bot using curl:

ffmpeg -i input -an -c:v libx264 -crf 26 -vf scale=640:-1 out.mp4
curl -v -F chat_id=CHATID -F video=@out.mp4 -F caption=foobar https://api.telegram.org/bot<TOKEN>/sendVideo
Andy
  • 7,931
  • 4
  • 25
  • 45
  • I am not sure where the problem is but using the exact same command generates videos that can be read by the desktop app but not with the android app. Any hint on why this happen? – Simon C. Dec 04 '18 at 07:27
  • @SimonC. Is it possible that you are using an old android version which doesn't support x264 decoding? – Andy Dec 04 '18 at 08:12
  • That may be an issue but I know of other user with newer phone that cannot watch the video. On another hand the telegram app have no problem reading the video made from the phone. I guess the phone is using another format? Another thing is that I am using ffmpeg from FreeBSD. Maybe the problem comes from freeBSD libx264 codec? – Simon C. Dec 04 '18 at 08:51
  • 8
    Adding `-pix_fmt yuv420p` seems to make playback on Android work for me. – Pastafarianist Oct 02 '19 at 18:58
  • `ffmpeg -i "/home/folder/bangkok.avi" -c:v libx264 -crf 26 -vf scale=642:-1 -pix_fmt yuv420p16le out.mp4` This works at desktop and on Android phone – user2455668 Jul 20 '21 at 15:38
0

Try adding -pix_fmt yuv420p, that made it work for me.

Note: taken from a comment from @Pastafarianist in this same question, which should be an answer instead.