我有一个 webm 文件,想将其转换为 mp4 文件。结果得到的 mp4 文件的时长与 webm 不同(长得多)。
- Webm 文件(通过 WeTransfer,example.webm,421kb)
关于 webm 文件
我正在使用浏览器的媒体记录器 API。播放时,它会显示一个 4 秒的剪辑(应该如此)。
ffprobe -v error -show_format -show_streams example.webm
输出:
[STREAM]
index=0
codec_name=vp8
codec_long_name=On2 VP8
profile=0
codec_type=video
codec_time_base=0/1
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=960
height=540
coded_width=960
coded_height=540
closed_captions=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=-99
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=unspecified
field_order=progressive
timecode=N/A
refs=1
id=N/A
r_frame_rate=1000/1
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
TAG:alpha_mode=1
[/STREAM]
[FORMAT]
filename=example.webm
nb_streams=1
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=N/A <------------ Noticed it
size=431167
bit_rate=N/A <------------ Noticed it
probe_score=100
TAG:encoder=Chrome
[/FORMAT]
注意到持续时间是 N/A,所以在浏览超级用户社区后,我看到了一个关于该 api 中与持续时间相关的错误的帖子但还在答案中找到了一个解决方案,即简单地在文件上运行 ffmpeg。
因此我运行了以下命令:
ffmpeg -i example.webm example-n.webm
输出:
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'example.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Video: vp8, yuv420p(progressive), 960x540, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x7fb3a501dc00] v1.8.2-217-gbf3fe26f7
[libvpx-vp9 @ 0x7fb3a501dc00] Neither bitrate nor constrained quality specified, using default CRF of 32
Output #0, webm, to 'example-n.webm':
Metadata:
encoder : Lavf58.45.100
Stream #0:0(eng): Video: vp9 (libvpx-vp9), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 1k fps, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
encoder : Lavc58.91.100 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 34 fps=0.0 q=0.0 size= 1kB time=00:00:00.31 bitrate= 13.2kbits/s
frame= 45 fps= 43 q=0.0 size= 1kB time=00:00:00.70 bitrate= 5.9kbits/s
frame= 56 fps= 36 q=0.0 size= 1kB time=00:00:01.09 bitrate= 3.8kbits/s
frame= 67 fps= 32 q=0.0 size= 1kB time=00:00:01.47 bitrate= 2.8kbits/s
frame= 78 fps= 30 q=0.0 size= 1kB time=00:00:01.88 bitrate= 2.2kbits/s
frame= 89 fps= 29 q=0.0 size= 1kB time=00:00:02.29 bitrate= 1.8kbits/s
frame= 100 fps= 28 q=0.0 size= 1kB time=00:00:02.67 bitrate= 1.6kbits/s
frame= 111 fps= 27 q=0.0 size= 1kB time=00:00:03.05 bitrate= 1.4kbits/s
frame= 113 fps= 21 q=0.0 Lsize= 58kB time=00:00:03.97 bitrate= 119.8kbits/s speed=0.727x
video:57kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.312099%
对新的 webm 文件运行相同的 ffprobe 命令:
[FORMAT]
filename=example-n.webm
nb_streams=1
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=3.972000 <--- NOT N/A. 4 seconds - looks better.
size=59473
bit_rate=119784
probe_score=100
TAG:ENCODER=Lavf58.45.100
[/FORMAT]
编辑:但在[STREAM]上仍然:
duration_ts=N/A
duration=N/A
bit_rate=N/A
转换为 mp4
运行命令:
ffmpeg -i example.webm example-1.mp4
输出:
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, matroska,webm, from 'example.webm':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Video: vp8, yuv420p(progressive), 960x540, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x7fbb0f80b600] using SAR=1/1
[libx264 @ 0x7fbb0f80b600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fbb0f80b600] profile High, level 5.2, 4:2:0, 8-bit
[libx264 @ 0x7fbb0f80b600] 264 - core 161 r3015 4c2aafd - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'example-1.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 1k fps, 16k tbn, 1k tbc (default)
Metadata:
alpha_mode : 1
encoder : Lavc58.91.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 316 fps=0.0 q=33.0 size= 0kB time=00:00:00.25 bitrate= 1.5kbits/
frame= 672 fps=658 q=33.0 size= 0kB time=00:00:00.61 bitrate= 0.6kbits/
More than 1000 frames duplicated
frame= 1060 fps=679 q=33.0 size= 0kB time=00:00:01.00 bitrate= 0.4kbits/
frame= 1442 fps=687 q=33.0 size= 0kB time=00:00:01.38 bitrate= 0.3kbits/
frame= 1816 fps=695 q=33.0 size= 0kB time=00:00:01.75 bitrate= 0.2kbits/
frame= 2195 fps=698 q=33.0 size= 256kB time=00:00:02.13 bitrate= 982.0kbits/
frame= 2572 fps=703 q=33.0 size= 256kB time=00:00:02.51 bitrate= 834.7kbits/
frame= 2948 fps=705 q=33.0 size= 256kB time=00:00:02.88 bitrate= 726.0kbits/
frame= 3332 fps=705 q=33.0 size= 256kB time=00:00:03.27 bitrate= 640.8kbits/
frame= 3692 fps=703 q=33.0 size= 256kB time=00:00:03.63 bitrate= 577.3kbits/
frame= 4006 fps=692 q=-1.0 Lsize= 545kB time=00:00:04.00 bitrate=1116.0kbits/s dup=3893 drop=0 speed=0.692x
video:498kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 9.589657%
[libx264 @ 0x7fbb0f80b600] frame I:17 Avg QP:19.61 size: 13978
[libx264 @ 0x7fbb0f80b600] frame P:1010 Avg QP:18.45 size: 156
[libx264 @ 0x7fbb0f80b600] frame B:2979 Avg QP:22.92 size: 38
[libx264 @ 0x7fbb0f80b600] consecutive B-frames: 0.8% 0.0% 0.0% 99.2%
[libx264 @ 0x7fbb0f80b600] mb I I16..4: 18.6% 64.7% 16.7%
[libx264 @ 0x7fbb0f80b600] mb P I16..4: 0.2% 0.3% 0.0% P16..4: 1.6% 0.2% 0.1% 0.0% 0.0% skip:97.5%
[libx264 @ 0x7fbb0f80b600] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.7% 0.0% 0.0% direct: 0.0% skip:99.3% L0:52.4% L1:47.5% BI: 0.0%
[libx264 @ 0x7fbb0f80b600] 8x8 transform intra:62.0% inter:74.2%
[libx264 @ 0x7fbb0f80b600] coded y,uvDC,uvAC intra: 10.8% 18.8% 13.6% inter: 0.0% 0.1% 0.0%
[libx264 @ 0x7fbb0f80b600] i16 v,h,dc,p: 34% 54% 11% 2%
[libx264 @ 0x7fbb0f80b600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 63% 11% 24% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x7fbb0f80b600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 44% 22% 14% 4% 4% 3% 4% 3% 3%
[libx264 @ 0x7fbb0f80b600] i8c dc,h,v,p: 70% 19% 9% 1%
[libx264 @ 0x7fbb0f80b600] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fbb0f80b600] ref P L0: 91.8% 2.4% 5.0% 0.8%
[libx264 @ 0x7fbb0f80b600] ref B L0: 69.0% 30.4% 0.6%
[libx264 @ 0x7fbb0f80b600] ref B L1: 97.2% 2.8%
[libx264 @ 0x7fbb0f80b600] kb/s:1016.19
问题:输出的mp4文件,播放时播放器显示其时长为21秒。虽然应该是4秒。第一秒,片段看起来很棒,但之后的 20 秒,片段似乎以“慢动作”移动。