12

I know that we can install many applications to support many new video formats. My question is:

  1. Does Telegram have an internal video player? (Does the software itself come with a player?)
  2. If yes, which formats can be played with that player (audio and video)?

Note: I've seen that sometimes mp4 files can be played in Telegram but sometimes they can't. What's the difference? Is it related to bitrate?

2
  • Would someone explain in a comment as to why this was flagged as off-topic?
    – jonsca
    Jun 12, 2018 at 22:07
  • Because it's question about mobile application not web application. From OP's post: (Does the software itself come with a player?)
    – user159892
    Jun 14, 2018 at 15:29

5 Answers 5

9

The data provided in this answer is relevant to Telegram web and Android application Telegram X as of 10/06/2018.

Tl;DR - Video: Baseline 3.0 640x360 ~800 kbps VBR single pass Audio aac 128 VBR

While there is an official statement, it is outdated.

As the answer above stated: Telegram indeed uses H.264 and MPEG-4 is a must as a container.
If you upload a video file from computer, in the case the file exceeds 10 MB it will be marked as a file and will not be playable by Web app or Android app. It still will be playable on iPhone however. Bitrate and resolution don't make any difference in that specific case.

When uploading a video file from the phone, unless you specifically choose to upload as uncompressed file, which will disable playback, the Android application will encode your video for you (even if you used better encoding) to the following format:
Video: Baseline 3.0 640x360 ~800 VBR single pass
Audio aac 128 VBR
What can you do?
You can create a file on the pc, send it to yourself as a file, and upload it to telegram using your phone. As an example I can provide a video that was uploaded to Telegram using this method: Original video:
1:04:02, Main 3.1, 1280x720, 700 kbps VBR double pass, AAC 128 VBR total file size - 379 MB
After uploading to Telegram:
1:04:02, Baseline 3.0 640x360 798 kbps VBR (pressumably single pass), AAC 125 VBR, total file size - 424.2 MB

As a result, the video lost some quality and gained 11.87% to its size but is playable using the build in player which is neat, since it supports picture in picture.

4

I have found an article on telegram website about the media requirements. The article is for Blackberry but worked for me for Web browser and Android as well.

Video dimensions must be set to 480x320 (320x480 for vertical videos).
H.264 and MPEG-4 should be used as the codec and container.

After converting my video to 480x270 resolution (.mp4 format) telegram started to show it as a playable video rather than just a file to download (both on web and android).

telegram playable video screenshot

With this resolution my video file size also dropped to 8mb, not sure if telegram takes the file size into account.

I used resolution 480x270 instead of 480x320 to preserve the original 16:9 aspect ratio.

2

Recommendations on ffmpeg commands to optimize a video to run in the Telegram player

Essential
Video codec: x264 (avc) or x265 (hevc)
audio codec: aac
audio channels: up to 2

Recommended
max_muxing_queue_size 9999 - prevents memory allocation error during encoding for high-resolution videos. (Too many packets buffered for output stream)

c:v libx264 - x264 codec, requires less CPU, avoiding crashes on old smartphones

maxrate 4.5M - Establishes maximum peak bitrate in complex scenes, to avoid crashes on a modest internet connection.

crf 23 - Establishes a constant quality factor. Can be overridden by bitrate setting

preset faster - image optimization filter presets in the encode, which impacts the final size in a negative correlation with processing time. "Faster" delivers the best cost-benefit tradeoff according to the trainer and author Jan Ozer

flags +global_header - Adds global metadata to the file, useful to the player

pix_fmt yuv420p - Greater compatibility with older smartphones

profile:v baseline - Greater compatibility with older smartphones

movflags +faststart - Rearranges the output file so that essential metadata is placed at the beginning of the file

c:a aac - Audio codec required by Telegram

ac 2 - Limits up to 2 audio channels (stereo). Above that, Telegram does not execute the file.

Final command example:

ffmpeg -i "input.mkv" -max_muxing_queue_size 9999 -c:v libx264 -crf 23 -maxrate 4.5M -preset faster -flags +global_header -pix_fmt yuv420p -profile:v baseline -movflags +faststart -c:a aac -ac 2 "output.mp4"

For batch video optimization
VIDQA - Python library that performs batch video optimizations, compatible with Telegram

1

For generating a video that can be understood by the internal player of Telegram (thus letting you play it in-place), you can use the media-processing tool FFMPEG to convert the video as follows:

ffmpeg -i INPUT_FILE.mkv  \
   -c:v libx264 -profile:v baseline -c:a aac -ar 44100 -ac 2 -b:a 128k \
   -vf format=yuv420p \
   OUTPUT_TELEGRAM_VIDEO.mp4
1
  • 2
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 21, 2022 at 15:23
0

H.264 and MPEG-4 should be used as the codec and container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.