为什么mp4视频在iphone上无法播放? 但android上可以正常播放?

2,173 阅读5分钟

因为视频格式(1080i)在iphone上不兼容, iphone上可以播放1080p的视频, 但是无法播放1080i的视频

1. 什么是1080i? 和1080p有什么区别?

1080i 是一种高清晰度电视信号格式。其中,"1080" 表示垂直方向有 1080 条水平扫描线,"i" 表示采用交错式扫描视频显示方式(interlaced scan)。在播放时,它先扫描单数的垂直画面,再扫描双数的垂直画面,故只需要 1080p 一半的带宽。它的出现对电视产业的发展具有重要的影响。

1080p 是一种视频显示格式,外语字母 P 意为逐行扫描(Progressive scanning)。1080p 是一种视频显示格式,外语字母 P 意为逐行扫描(Progressive scan),有别于 1080i 的隔行扫描 ( interlaced scan ) 。数字 1080 则表示水平方向有 1080 条水平扫描线。通常 1080p 的画面分辨率为 1920×1080。

2. 如何知道视频是1080i还是1080P?

使用ffmpeg 的 showinfo 命令获取视频前5帧m, 然后分析详细的帧信息

ffmpeg -y -i video.mp4 -vf showinfo -frames:v 5 -f flv /dev/null

// 以下是命令输出信息

[Parsed_showinfo_0 @ 0x7fd9d2304080] n:   1 pts:   1000 pts_time:0.04    pos:   421397 fmt:yuv420p sar:0/1 s:1920x1080 i:B iskey:0 type:B checksum:C7CACCBA plane_checksum:[738450B5 F656CF71 0B50AC85] mean:[133 126 133] stdev:[45.9 14.7 16.7]
[Parsed_showinfo_0 @ 0x7fd9d2304080] color_range:tv color_space:bt709 color_primaries:bt709 color_trc:bt709
[Parsed_showinfo_0 @ 0x7fd9d2304080] n:   2 pts:   2000 pts_time:0.08    pos:   433996 fmt:yuv420p sar:0/1 s:1920x1080 i:B iskey:0 type:B checksum:08D08C34 plane_checksum:[5FDA5DE2 8C91A027 EE8E8E1C] mean:[133 126 133] stdev:[46.3 14.6 16.6]
[Parsed_showinfo_0 @ 0x7fd9d2304080] color_range:tv color_space:bt709 color_primaries:bt709 color_trc:bt709
[Parsed_showinfo_0 @ 0x7fd9d2304080] n:   3 pts:   3000 pts_time:0.12    pos:   369831 fmt:yuv420p sar:0/1 s:1920x1080 i:B iskey:0 type:P checksum:6B05610C plane_checksum:[255E6DAD 4AFB26FD 0806CC53] mean:[133 126 133] stdev:[46.7 14.7 16.6]
[Parsed_showinfo_0 @ 0x7fd9d2304080] color_range:tv color_space:bt709 color_primaries:bt709 color_trc:bt709
[Parsed_showinfo_0 @ 0x7fd9d2304080] n:   4 pts:   4000 pts_time:0.16    pos:   523784 fmt:yuv420p sar:0/1 s:1920x1080 i:B iskey:0 type:B checksum:E2DCB096 plane_checksum:[0E049EB6 16BBCDC8 DC9E4409] mean:[133 126 133] stdev:[46.8 14.6 16.6]
[Parsed_showinfo_0 @ 0x7fd9d2304080] color_range:tv color_space:bt709 color_primaries:bt709 color_trc:bt709
[Parsed_showinfo_0 @ 0x7fd9d2304080] n:   5 pts:   5000 pts_time:0.2     pos:   552948 fmt:yuv420p sar:0/1 s:1920x1080 i:B iskey:0 type:B checksum:AD717237 plane_checksum:[28D98B7A 73D7F12F 142FF570] mean:[133 126 133] stdev:[46.6 14.7 16.6]
[Parsed_showinfo_0 @ 0x7fcc3d006c80] color_range:unknown color_space:unknown color_primaries:unknown color_trc:unknown

showinfo 命令指南

Show a line containing various information for each input video frame. The input video is not modified.
This filter supports the following options:

checksum
Calculate checksums of each plane. By default enabled.

The shown line contains a sequence of key/value pairs of the form key:value.
The following values are shown in the output:

n
The (sequential) number of the input frame, starting from 0

pts
The Presentation TimeStamp of the input frame, expressed as a number of time base units. The time base unit depends on the filter input pad.

pts_time
The Presentation TimeStamp of the input frame, expressed as a number of seconds.

pos
The position of the frame in the input stream, or -1 if this information is unavailable and/or meaningless (for example in case of synthetic video).

fmt
The pixel format name.

sar
The sample aspect ratio of the input frame, expressed in the form num/den.

s
The size of the input frame. For the syntax of this option, check the (ffmpeg-utils)"Video size" section in the ffmpeg-utils manual.

i
The type of interlaced mode ("P" for "progressive", "T" for top field first, "B" for bottom field first).  隔行扫描模式("P"代表逐行,“T”代表上场优先,“B”代表下场优先)

iskey
This is 1 if the frame is a key frame, 0 otherwise.

type
The picture type of the input frame ("I" for an I-frame, "P" for a P-frame, "B" for a B-frame, or "?" for an unknown type). Also refer to the documentation of the AVPictureType enum and of the av_get_picture_type_char function defined in libavutil/avutil.h.

checksum
The Adler-32 checksum (printed in hexadecimal) of all the planes of the input frame.

plane_checksum
The Adler-32 checksum (printed in hexadecimal) of each plane of the input frame, expressed in the form "[c0 c1 c2 c3]".

mean
The mean value of pixels in each plane of the input frame, expressed in the form "[mean0 mean1 mean2 mean3]".

stdev
The standard deviation of pixel values in each plane of the input frame, expressed in the form "[stdev0 stdev1 stdev2 stdev3]".

通过文档我们可以知道, 通过查看i参数, 即可区分出来视频是隔行还是逐行的。

3. 如何把1080i视频转换为1080p视频?

  • 使用剪映工具可以非常简单的转换视频为1080p格式

lADPBFRyd5pI-vLNBgLNCjA_2608_1538.jpg_720x720g.jpg

lADPBFRyd5pJKbvNBpjNCdA_2512_1688.jpg_720x720g.jpg

lADPBFRyd5pJ1WvNBebNCho_2586_1510.jpg_720x720g.jpg

  • 也可以使用ffmpeg命令进行转换
// 转换视频为1080p中等质量视频
ffmpeg -i input.mp4 -b 1500K -minrate 1500K -maxrate 1500K -bufsize 2000K -vcodec libx264 -pix_fmt yuv420p -profile:v main -level 3.1 -crf 23 -x264-params ref=4 -acodec copy -movflags +faststart output1080p.mp4

// 转换视频为1808i中等质量视频
ffmpeg -i input.mp4 -b 1500K -minrate 1500K -maxrate 1500K -bufsize 2000K -vcodec libx264 -pix_fmt yuv420p -profile:v main -level 3.1 -crf 23 -x264-params ref=4 -flags +ilme+ildct -acodec copy -movflags +faststart output1080i.mp4

// 获取视频第一帧
ffmpeg -i input.mp4 -vf "select=eq(n\,0)" -q:v 3 output.jpg