如何从图像和音频文件创建视频?

如何从图像和音频文件创建视频?

简而言之,我只想用 X 张图片和一个 mp3 文件创建一个视频,获得相同的音频质量。

我已经检查过 ffmpeg 网站,但是......我得到的结果是:

ffmpeg.exe -y -i img%01d.jpg -i "03 eminem - when I'm Gone.mp3" -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest shortt.mp4

在哪里: 在同一个文件夹中,我有 img0.jpg img1.jpg 等等...

mp3 文件是音频文件。

输出应存储在 shortt.mp4 中

我运行此命令后,大约需要 2 秒钟才能完成,结果如下:

C:\Users\icebox\Desktop>ffmpeg.exe -y -i img%01d.jpg -i "03 eminem - when I'm Go
ne.mp3" -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest shortt.mp
4
ffmpeg version N-57821-g1fb3b49 Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov  2 2013 18:01:35 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 49.100 / 52. 49.100
  libavcodec     55. 40.101 / 55. 40.101
  libavformat    55. 21.100 / 55. 21.100
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, image2, from 'img%01d.jpg':
  Duration: 00:00:00.16, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj444p(pc), 126x126 [SAR 29:22 DAR 29:22], 25 f
ps, 25 tbr, 25 tbn, 25 tbc
[mp3 @ 028dca60] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from '03 eminem - when I'm Gone.mp3':
  Metadata:
    title           : When I'm Gone
    artist          : Eminem
    genre           : Other
  Duration: 00:04:40.54, start: 0.000000, bitrate: 128 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
No pixel format specified, yuvj444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 02531860] using SAR=29/22
[libx264 @ 02531860] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 02531860] profile High 4:4:4 Predictive, level 1.1, 4:4:4 8-bit
[libx264 @ 02531860] 264 - core 140 r2377 1ca7bb9 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=4 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 in
terlaced=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 scenecu
t=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 'shortt.mp4':
  Metadata:
    encoder         : Lavf55.21.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj444p, 126x1
26 [SAR 29:22 DAR 29:22], q=-1--1, 12800 tbn, 25 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 19
2 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)
  Stream #1:0 -> #0:1 (mp3 -> aac)
Press [q] to stop, [?] for help
Input stream #0:0 frame changed from size:126x126 fmt:yuvj444p to size:1024x768
fmt:yuvj444p
[swscaler @ 06562000] deprecated pixel format used, make sure you did set range
correctly
Input stream #0:0 frame changed from size:1024x768 fmt:yuvj444p to size:96x96 fm
t:yuvj420p
[swscaler @ 0257f640] deprecated pixel format used, make sure you did set range
correctly
Input stream #0:0 frame changed from size:96x96 fmt:yuvj420p to size:1920x1200 f
mt:yuvj420p
[swscaler @ 06562000] deprecated pixel format used, make sure you did set range
correctly
frame=    4 fps=0.0 q=-1.0 Lsize=       9kB time=00:00:00.16 bitrate= 456.7kbits
/s
video:8kB audio:0kB subtitle:0 global headers:0kB muxing overhead 17.815873%
[libx264 @ 02531860] frame I:1     Avg QP:32.77  size:  2030
[libx264 @ 02531860] frame P:3     Avg QP:31.02  size:  1673
[libx264 @ 02531860] mb I  I16..4:  1.6% 98.4%  0.0%
[libx264 @ 02531860] mb P  I16..4:  9.4% 40.1% 50.5%  P16..4:  0.0%  0.0%  0.0%
 0.0%  0.0%    skip: 0.0%
[libx264 @ 02531860] 8x8 transform intra:54.7%
[libx264 @ 02531860] coded y,u,v intra: 77.0% 31.8% 35.5%
[libx264 @ 02531860] i16 v,h,dc,p:  0% 26% 11% 63%
[libx264 @ 02531860] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 22% 18%  9%  5%  6%  7%
 7%  8%
[libx264 @ 02531860] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 12% 14%  6%  6% 10%  6%
10%  5%
[libx264 @ 02531860] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 02531860] kb/s:352.45

文件在那里,但如果我在 VLC 中打开它,什么也不会发生。

我试过不用-最短争论。我已经等了 5 分钟了,但仍然没有完成,所以我停止了它。

这是我得到的:

[swscaler @ 0653e000] 使用了弃用的像素格式,请确保正确设置了范围 有什么建议 ?

附言:我还设法创建了包含图像和音频文件的视频,但它并没有循环播放所有图像。

回应第一个答案:

输出

  built on Nov  2 2013 18:01:35 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 49.100 / 52. 49.100
  libavcodec     55. 40.101 / 55. 40.101
  libavformat    55. 21.100 / 55. 21.100
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, image2, from 'img%01d.jpg':
  Duration: 00:00:00.16, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj444p(pc), 126x126 [SAR 29:22 DAR 29:22], 25 f
ps, 25 tbr, 25 tbn, 25 tbc
[mp3 @ 0259cac0] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from '03 eminem - when I'm Gone.mp3':
  Metadata:
    album_artist    : Lil Wayne
    genre           : Other
    title           : Prom Queen
    album           : Rebirth
    artist          : Lil Wayne
  Duration: 00:03:41.94, start: 0.000000, bitrate: 320 kb/s
    Stream #1:0: Audio: mp3, 48000 Hz, stereo, s16p, 320 kb/s
File 'o.mp4' already exists. Overwrite ? [y/N] y
[swscaler @ 02596ce0] deprecated pixel format used, make sure you did set range
correctly
[libx264 @ 03fd18c0] using SAR=29/22
[libx264 @ 03fd18c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 03fd18c0] profile High, level 1.1
[libx264 @ 03fd18c0] 264 - core 140 r2377 1ca7bb9 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 i
nterlaced=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 scenec
ut=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 'o.mp4':
  Metadata:
    encoder         : Lavf55.21.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 126x12
6 [SAR 29:22 DAR 29:22], q=-1--1, 12800 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (i[0][0][0] / 0x0069), 48000 Hz, stereo, 320 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
Input stream #0:0 frame changed from size:126x126 fmt:yuvj444p to size:1024x768
fmt:yuvj444p
[swscaler @ 051b7b20] deprecated pixel format used, make sure you did set range
correctly
Input stream #0:0 frame changed from size:1024x768 fmt:yuvj444p to size:96x96 fm
t:yuvj420p
[swscaler @ 051b7b20] deprecated pixel format used, make sure you did set range
correctly
Input stream #0:0 frame changed from size:96x96 fmt:yuvj420p to size:1920x1200 f
mt:yuvj420p
[swscaler @ 05173fa0] deprecated pixel format used, make sure you did set range
correctly
frame=    4 fps=0.0 q=-1.0 Lsize=      15kB time=00:00:00.16 bitrate= 718.6kbits
/s
video:7kB audio:7kB subtitle:0 global headers:0kB muxing overhead 9.792652%
[libx264 @ 03fd18c0] frame I:1     Avg QP:31.89  size:  1831
[libx264 @ 03fd18c0] frame P:3     Avg QP:30.50  size:  1487
[libx264 @ 03fd18c0] mb I  I16..4:  3.1% 90.6%  6.3%
[libx264 @ 03fd18c0] mb P  I16..4:  7.8% 41.1% 51.0%  P16..4:  0.0%  0.0%  0.0%
 0.0%  0.0%    skip: 0.0%
[libx264 @ 03fd18c0] 8x8 transform intra:53.5%
[libx264 @ 03fd18c0] coded y,uvDC,uvAC intra: 76.2% 66.0% 37.5%
[libx264 @ 03fd18c0] i16 v,h,dc,p: 18% 12%  6% 65%
[libx264 @ 03fd18c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 21% 22%  9%  6%  8%  6%
 7%  9%
[libx264 @ 03fd18c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 11% 15%  7%  6% 11%  6%
10%  5%
[libx264 @ 03fd18c0] i8c dc,h,v,p: 64% 16% 17%  3%
[libx264 @ 03fd18c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 03fd18c0] kb/s:314.65

输出视频只有 12 KB,当我用 VLC 打开它时什么也没有发生,没有声音,没有视频。

答案1

色度子采样

从控制台输出:

No pixel format specified, yuvj444p for H.264 encoding chosen.  
Use -pix_fmt yuv420p for compatibility with outdated media players.

这意味着你需要添加-pix_fmt yuv420p输出选项。否则 ffmpeg 可能会(取决于你的输入、ffmpeg 版本和所使用的编码器)尝试避免色度二次采样。从技术上来说这很好,但是大多数(所有?)非基于 FFmpeg 的播放器(例如 QuickTime)都无法正确解码它。

更改框架尺寸

从控制台输出:

Input stream #0:0 frame changed from size:126x126 fmt:yuvj444p to
size:1024x768 fmt:yuvj444p

这告诉您,您的输入帧并非都是相同的大小,并且可能会导致意外行为。

[swscaler @ 0257f640] 使用了弃用的像素格式,请确保正确设置了范围

这是一个警告(更多针对开发人员而非用户),您可以忽略。

声音的

您正在重新编码音频。您可以流复制音频,因为您的输出容器 (mp4) 应该支持 MP3 音频。这样可以避免重新编码,从而保持质量,并且运行速度更快。

例子

ffmpeg -i img%01d.jpg -i "03 eminem - when I'm Gone.mp3" -c:v libx264 \
-pix_fmt yuv420p -c:a copy -shortest output.mp4

相关内容