我正在使用 ffmpeg 将尺寸为 200x100 的 png 和 m4a 音频文件合并到视频中,使用以下命令
ffmpeg -i audio.m4a -i image.png -pix_fmt yuv420p output.mp4
这样制作的视频尺寸为 200x100,但视频中的图像被缩放为 100x100,而不是图像实际的 200x100。
我怎样才能使图像占据整个视频,并具有原始图像的尺寸(200x100)?
编辑:
完整日志
built with gcc 9.3.1 (GCC) 20200621
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 55.100 / 56. 55.100
libavcodec 58. 93.100 / 58. 93.100
libavformat 58. 47.100 / 58. 47.100
libavdevice 58. 11.100 / 58. 11.100
libavfilter 7. 86.100 / 7. 86.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'audio.m4a':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
creation_time : 2020-06-13T10:03:52.000000Z
Duration: 00:02:41.89, start: 0.000000, bitrate: 129 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 7 kb/s (default)
Metadata:
creation_time : 2020-06-13T10:03:52.000000Z
handler_name : ISO Media file produced by Google Inc.
Input #1, png_pipe, from 'image.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 200x100 [SAR 1:2 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #1:0 -> #0:0 (png (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0000029d49352980] using SAR=1/2
[libx264 @ 0000029d49352980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX BMI1 SlowPshufb
[libx264 @ 0000029d49352980] profile High, level 1.1, 4:2:0, 8-bit
[libx264 @ 0000029d49352980] 264 - core 160 - 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=3 lookahead_threads=1 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 'output.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6mp41
encoder : Lavf58.47.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 200x100 [SAR 1:2 DAR 1:1], q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc58.93.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2020-06-13T10:03:52.000000Z
handler_name : ISO Media file produced by Google Inc.
encoder : Lavc58.93.100 aac
frame= 1 fps=0.1 q=28.0 Lsize= 2590kB time=00:02:41.88 bitrate= 131.1kbits/s speed=20.9x
video:2kB audio:2559kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.118362%
[libx264 @ 0000029d49352980] frame I:1 Avg QP:29.89 size: 1599
[libx264 @ 0000029d49352980] mb I I16..4: 18.7% 44.0% 37.4%
[libx264 @ 0000029d49352980] 8x8 transform intra:44.0%
[libx264 @ 0000029d49352980] coded y,uvDC,uvAC intra: 78.0% 91.2% 62.6%
[libx264 @ 0000029d49352980] i16 v,h,dc,p: 29% 41% 0% 29%
[libx264 @ 0000029d49352980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 24% 11% 10% 8% 4% 6% 5% 12%
[libx264 @ 0000029d49352980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 27% 7% 4% 6% 3% 7% 4% 4%
[libx264 @ 0000029d49352980] i8c dc,h,v,p: 37% 36% 5% 21%
[libx264 @ 0000029d49352980] kb/s:319.80
[aac @ 0000029d49342000] Qavg: 223.851```
答案1
您的图片有样本纵横比为 1/2,因此任何优秀的玩家都会修正宽度以符合 SAR。
Stream #1:0: Video: png, rgba(pc), 200x100 [SAR 1:2 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
使用 setsar 过滤器将 SAR 设置为 1 并避免调整大小。
ffmpeg -i audio.m4a -i image.png -vf setsar=1 -pix_fmt yuv420p output.mp4