TelegramMessenger / Telegram-iOS

Telegram-iOS
6.36k stars 1.67k forks source link

Video appears green when played on iOS, plays ok on desktop #1125

Closed levicki closed 1 year ago

levicki commented 1 year ago

Checklist

Description

A video I compiled using ffmpeg looks green when played in Telegram on iOS.

Expected Behavior

Video shouldn't be green.

Actual Behavior

Video is green.

Steps to Reproduce

  1. Download the video
  2. Share it to yourself
  3. Play it

Screenshots and Videos

image

Download video here (mega.nz).

Environment

Device: iPhone 13 Pro Max

iOS version: 16.5

App version: 9.6.3

ali-fareed commented 1 year ago

Does the same video work OK when saved to Photos?

levicki commented 1 year ago

@ali-fareed

Does the same video work OK when saved to Photos?

That's the thing,

Save to Photos also doesn't seem to work for me -- it says video saved to Photos when you tap it, but the video doesn't appear in the Gallery. Telegram has full permissions.

ali-fareed commented 1 year ago

Then it is likely encoded in a way that is not compatible with iOS. QuickTime on MacOS also can't play it.

levicki commented 1 year ago

@ali-fareed

Then it is likely encoded in a way that is not compatible with iOS. QuickTime on MacOS also can't play it.

Even if true, that's not the reason to close the ticket and refuse to fix the playback in the Telegram app which can obviosly play it, just with wrong colors. The desktop app can also play it just fine.

Here is the media info for the video:

General
Complete name                            : D:\Downloads\GoldHighlightReel.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 146 MiB
Duration                                 : 1 min 59 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 10.2 Mb/s
Writing application                      : Lavf60.4.100

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Format Range@L4.1@Main
Codec ID                                 : hev1
Codec ID/Info                            : High Efficiency Video Coding
Duration                                 : 1 min 59 s
Bit rate                                 : 9 991 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 60.000 FPS
Color space                              : RGB
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.080
Stream size                              : 143 MiB (98%)
Writing library                          : x265 3.5+96-9c9ab68fc:[Windows][GCC 12.2.0][64 bit] 8bit+10bit+12bit
Encoding settings                        : cpuid=1111039 / frame-threads=4 / numa-pools=16 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=3 / input-res=1920x1080 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=3 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-eob / no-eos / no-hrd / info / hash=0 / temporal-layers=0 / open-gop / min-keyint=6 / keyint=60 / gop-lookahead=0 / bframes=4 / b-adapt=0 / b-pyramid / bframe-bias=0 / rc-lookahead=15 / lookahead-slices=6 / scenecut=40 / no-hist-scenecut / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=2 / limit-refs=3 / no-limit-modes / me=1 / subme=2 / merange=57 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / deblock=0:0 / sao / no-sao-non-deblock / rd=2 / selective-sao=4 / no-early-skip / rskip / fast-intra / no-tskip-fast / no-cu-lossless / no-b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=2.00 / psy-rdoq=0.00 / no-rd-refine / no-lossless / cbqpoffs=6 / crqpoffs=6 / rc=crf / crf=26.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.30 / aq-mode=2 / aq-strength=1.00 / cutree / zone-count=0 / no-strict-cbr / qg-size=32 / no-rc-grain / qpmax=69 / qpmin=0 / no-const-vbv / sar=0 / overscan=0 / videoformat=5 / range=1 / colorprim=2 / transfer=2 / colormatrix=0 / chromaloc=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=255 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / scenecut-aware-qp=0conformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass / no-mcstf / no-sbrc
Color range                              : Full
Matrix coefficients                      : Identity
Codec configuration box                  : hvcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 1 min 59 s
Source duration                          : 1 min 59 s
Bit rate mode                            : Variable
Bit rate                                 : 241 kb/s
Maximum bit rate                         : 256 kb/s / 256 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 3.44 MiB (2%)
Source stream size                       : 3.44 MiB (2%)
Default                                  : Yes
Alternate group                          : 1

I don't see what could be the problem here for Apple to play it, HEVC and AAC are supported and so is the MP4 container. Can you at least check what error the iOS returns when you try saving it to gallery so I can try to report the problem to Apple?

EDIT: It would also be nice if Telegram didn't lie about video being saved and showed the actual error to the user.

levicki commented 1 year ago

@ali-fareed

I have figured out why the video cannot be saved — maybe it will be useful for other people too.

Codec ID for Apple devices must be hvc1, not hev1.

This is how you can re-tag already encoded video so it can be saved to photos:

ffmpeg -i input.mp4 -c:v copy -c:a copy -tag:v hvc1 output.mp4

After doing that I can save the video from Telegram app and play it from Photos app.

However, it is still green, indicating that there is some problem with Apple HEVC decoder.