微信小程序 webview mp4视频 在ios无法播放 安卓和谷歌浏览器正常

记一次微信小程序开发,视频兼容问题
参考链接:https://www.jianshu.com/p/31f0593496ef

问题描述:

微信小程序 内嵌webview 利用video标签播放流媒体视频, 部分视频 报错 error

问题确认:安卓正常, 谷歌正常, mac safari 正常, egretIde报错, iphone 报错

解决过程:

有问题的视频 代码错误提示:TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.

  1. 字面意思是调用错误,首先觉得是代码问题,先搜索上下文 没有相关调用
  2. 然后换了个视频地址 可以播放 . 有可能是兼容问题
  3. 谷歌浏览器打开没问题.mac safari 打开没有问题, egret ide 打开报错
  4. 最后用出问题的手机测试. Safari 直接打开 视频显示异常在这里插入图片描述
  5. 出问题的手机 微信直接打开连接 也显示无法播放
  6. 定位问题: 可能是ios 兼容问题
  7. 然后 上网寻找解决方案

解决方案

h264编码的压缩级别问题导致。

苹果官方文档中对 ios 能支持的压缩级别进行了描述:
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html

我们可以通过 potplayer等软件,查看对应的mp4文件的 压缩级别,如果 压缩级别高于苹果能支持的压缩级别,则会出现ios下无法播放的问题。

如果视频存放在 阿里云或者七牛云,可以使用 他们的 视频转码服务(一般是按量计费),转码为 h264 high 4.1 就基本可以支持
phone4s + 的苹果设备了。 如果 要兼容所有(包括iphone3gs 和 iphone4),那需要转为 baseline 3.1

具体的苹果设备支持的编码格式列表,可以参考这里:
http://www.cnblogs.com/tinywan/p/6404411.html

出问题的编码信息如下(potplayer查看):

可以看到 Format profile : High@L3.1

General
Complete name                  : C:\Users\17838\Documents\WXWork\1688853547747770\Cache\Video\2019-10\light_train_1_test.mp4
Format                         : MPEG-4
Format profile                 : Base Media / Version 2
Codec ID                       : mp42 (mp42/mp41)
File size                      : 5.68 MiB
Duration                       : 27 s 880 ms
Overall bit rate               : 1 708 kb/s
Encoded date                   : UTC 2019-08-17 09:31:40
Tagged date                    : UTC 2019-08-17 09:31:45
TIM                            : 00:00:00:00
TSC                            : 25
TSZ                            : 1

Video
ID                             : 1
Format                         : AVC
Format/Info                    : Advanced Video Codec
Format profile                 : High@L3.1
Format settings                : CABAC / 4 Ref Frames
Format settings, CABAC         : Yes
Format settings, Reference fra : 4 frames
Format settings, GOP           : M=3, N=25
Codec ID                       : avc1
Codec ID/Info                  : Advanced Video Coding
Duration                       : 27 s 880 ms
Bit rate                       : 1 383 kb/s
Width                          : 1 002 pixels
Height                         : 708 pixels
Display aspect ratio           : 3:2
Frame rate mode                : Constant
Frame rate                     : 25.000 FPS
Color space                    : YUV
Chroma subsampling             : 4:2:0
Bit depth                      : 8 bits
Scan type                      : Interlaced
Scan type, store method        : Separated fields
Scan order                     : Bottom Field First
Bits/(Pixel*Frame)             : 0.078
Stream size                    : 4.60 MiB (81%)
Language                       : English
Encoded date                   : UTC 2019-08-17 09:31:40
Tagged date                    : UTC 2019-08-17 09:31:40
Color range                    : Limited
Color primaries                : BT.709
Transfer characteristics       : BT.709
Matrix coefficients            : BT.709
Codec configuration box        : avcC

Audio
ID                             : 2
Format                         : AAC LC
Format/Info                    : Advanced Audio Codec Low Complexity
Codec ID                       : mp4a-40-2
Duration                       : 27 s 880 ms
Source duration                : 27 s 861 ms
Bit rate mode                  : Constant
Nominal bit rate               : 317 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
Source stream size             : 1.05 MiB (19%)
Language                       : English
Encoded date                   : UTC 2019-08-17 09:31:41
Tagged date                    : UTC 2019-08-17 09:31:41

扩展阅读:

2H264编码是什么:

通过某种特定的压缩技术,将某个视频格式的文件转换为另一种视频格式的文件的技术称为视频编码。h264是视频流中其中一种编码标准。H264编码profile & level 控制https://www.cnblogs.com/tinywan/p/6402007.html,这里面说到H264编码的压缩级别,从压缩比例来说,baseline< main < high,对于带宽比较局限的在线视频,可能会优先选择high。但是上文说到,部分mp4视频不能在ios上播放,是由于h264编码的压缩比导致的,那么我们怎么知道ios支持哪些压缩级别呢?

ffmpeg如何控制profile&level:

ffmpeg -i input.mp4 -profile:v baseline -level 3.0 output.mp4

ffmpeg -i input.mp4 -profile:v main -level 4.2 output.mp4

ffmpeg -i input.mp4 -profile:v high -level 5.1 output.mp4

如果ffmpeg编译时加了external的libx264,那就这么写:

ffmpeg -i input.mp4 -c:v libx264 -x264-params "profile=high:level=3.0" output.mp4

苹果的设备对不同profile的支持。
在这里插入图片描述

这里可以看到 是不支持上面出问题的 High@L3.1

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值