What video format should be used for `sendVideo` in Telegram Bot API

What video format is compatible with the Telegram Bot API’s sendVideo method? The documentation only mentions “H.264/MPEG-4 AVC.” When I use the command

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

I get a positive response (ok:true) but the video preview shows a blurred image in the Telegram client. Any suggestions?

I’ve encountered similar issues before when working with video formats for the Telegram Bot API. One thing that often helps is ensuring that the video encoding settings are optimal. Try using an FFmpeg command with settings fine-tuned for compatibility. For example, when I use the command below, the videos usually display correctly:

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:a aac -b:a 128k -movflags +faststart output.mp4

In your case, the blurring issue might be due to the CRF value. Lowering it from 26 to a value around 23 can significantly improve quality without a huge increase in file size. Also, ensure the video scales to even dimensions (multiples of 2) to avoid any issues with encoding and display.

In my expierence, changing the file extension from .m4v to .mp4 might do the trick. Also, tinker the CRF value to around 23, and make sure to include -movflags +faststart. These tweaks should help display the video correctly in Telegram.

I’ve also navigated through similar issues with video uploads on the Telegram Bot API. From my experience, minor adjustments in your FFmpeg command can significantly enhance the outcome. Ensure you’re targeting compatibility by utilizing libx264 and a CRF value between 18 and 24. Additionally, you might want to adjust the dimensions to be even, which can be crucial. Try using a command like:

ffmpeg -i input-video -c:v libx264 -crf 22 -vf "scale=ceil(iw/2)*2:ceil(ih/2)*2" -c:a aac -movflags +faststart output.mp4

This should help in producing a smoother video output that Telegram handles well.