TelegramMessenger / Telegram-iOS

Telegram-iOS
6.37k stars 1.67k forks source link

Black screen instead of video uploaded via Telegram API (only in iOS app) #301

Open kv-y opened 4 years ago

kv-y commented 4 years ago

Checklist

Description

I use MTProto Telegram API and Telegram Bot API to upload small videos to Telegram. Format of video: h264+mp4 (audio stream doesn't matter) Resolution: 720p or 1080p Size of video file: > 10 MB (but less than 20MB) Source of video: doesn't matter (you can use any valid h264 video). Method: sendVideo if Telegram Bot API or messages.sendMedia if MTProto API.

I upload my video to the Telegram server using mentioned API and don't provide explicit info about width and height of this video. According to the documenation of sendVideo I don't need to provide info about width and height. They are both marked as optional. In this case Telegram server is reported that video was uploaded successfully (with width=0 and height=0). After that I try to watch video in different Telegram clients. Video is played correctly in Desktop client and Android app. But in iOS app I see a black screen instead of video (see attached screenshot).

If I explicitly set width and height of video or use video is less than 10 MB than video is played correctly iOS app. As I understand, if video is less than 10 MB then telegram server is calculated its width and height.

Expected Behavior

I can watch the video uploaded via Telegram Bot API or MTProto API in the Telegram-iOS app (even if I don't provide info about width and height in API method)

Actual Behavior

Black screen instead of the video in iOS app. But I can hear sound and can see video thumbnails.

Steps to Reproduce

  1. Upload h264+mp4 video (size of file between 10MB and 20MB) from your PC using MTProto Telegram API or Telegram Bot API. Don't provide explicit info about video's width and height (these are optional parameters according to the documentation).
  2. Check that video was uploaded successfully (use any other platform except iOS to watch it).
  3. Try to watch the video using iPhone. You can see a black screen instead of video.
  4. Upload the same video using MTProto Telegram API or Telegram Bot API, but provide info about width and height at this time (e.g. width=1920, height=1080).
  5. Congrats! Now you can watch this video in your Telegram-iOS app.

Screenshots and Videos

black_screen

Environment

Device: iPhone X

iOS version: 13.4, 13.5

App version: 6.1.2

tombeynon commented 4 years ago

I glossed over it initially but @hisirbr has mentioned a fix in his comment - setting the width and height causes the video to playback correctly.

vkrzt commented 4 years ago

@hisirbr thanks, your solution works. Just added proper width and height as parameters and video started to display correctly not only on iOS but also on official MacOS client.

if you are looking for easy solution how to grab locally stored video dimensions, this works for me (using ffmpeg-python): https://github.com/kkroening/ffmpeg-python/blob/master/examples/video_info.py#L15

probe = ffmpeg.probe(path_to_file) video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) width = int(video_stream['width']) height = int(video_stream['height'])