我有两张图片image1.png
和image2.png
,它们都有相同的尺寸。我还有两个音频文件audio1.wav
和audio2.wav
,每个音频文件都有不同的长度。我想制作一个在image1.png
期间显示audio1.wav
,然后在image2.png
上显示audio2.wav
的视频。
我尝试了两种方法,但它们不起作用。图像显示正确,但持续时间未与音频同步。
ffmpeg -loop 1 \
-y \
-i "image1.png" \
-i "audio1.wav" \
-c:v libx264 -tune stillimage -pix_fmt yuv420p \
-c:a aac -b:a 192k \
-shortest \
"video1.mp4"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, png_pipe, from 'image1.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, rgba(pc), 800x800, 25 fps, 25 tbr, 25 tbn, 25 tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from 'audio1.wav':
Metadata:
title : untitled
track : 1
Duration: 00:00:03.70, bitrate: 1411 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fead980bc00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fead980bc00] profile High, level 3.1
[libx264 @ 0x7fead980bc00] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:-3:-3 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=2.00:0.70 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-4 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.20
Output #0, mp4, to 'video1.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 192 kb/s
Metadata:
encoder : Lavc57.89.100 aac
frame= 151 fps=0.0 q=-1.0 Lsize= 106kB time=00:00:05.92 bitrate= 146.6kbits/s speed=6.73x
video:13kB audio:87kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 5.016360%
[libx264 @ 0x7fead980bc00] frame I:1 Avg QP:14.87 size: 5746
[libx264 @ 0x7fead980bc00] frame P:38 Avg QP:12.15 size: 51
[libx264 @ 0x7fead980bc00] frame B:112 Avg QP:16.81 size: 48
[libx264 @ 0x7fead980bc00] consecutive B-frames: 0.7% 1.3% 0.0% 98.0%
[libx264 @ 0x7fead980bc00] mb I I16..4: 46.9% 44.7% 8.4%
[libx264 @ 0x7fead980bc00] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:99.9%
[libx264 @ 0x7fead980bc00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.7% L0:63.5% L1:36.5% BI: 0.0%
[libx264 @ 0x7fead980bc00] 8x8 transform intra:40.7% inter:20.0%
[libx264 @ 0x7fead980bc00] coded y,uvDC,uvAC intra: 4.9% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x7fead980bc00] i16 v,h,dc,p: 82% 13% 4% 0%
[libx264 @ 0x7fead980bc00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 74% 2% 24% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x7fead980bc00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 24% 32% 2% 2% 2% 2% 1% 2%
[libx264 @ 0x7fead980bc00] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 0x7fead980bc00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fead980bc00] ref B L0: 48.0% 52.0%
[libx264 @ 0x7fead980bc00] ref B L1: 99.5% 0.5%
[libx264 @ 0x7fead980bc00] kb/s:17.36
[aac @ 0x7fead981b400] Qavg: 535.938
ffmpeg -loop 1 \
-y \
-i "image2.png" \
-i "audio2.wav" \
-c:v libx264 -tune stillimage -pix_fmt yuv420p \
-c:a aac -b:a 192k \
-shortest \
"video2.mp4"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, png_pipe, from 'image2.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, rgba(pc), 800x800, 25 fps, 25 tbr, 25 tbn, 25 tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from 'audio2.wav':
Metadata:
title : untitled
track : 2
Duration: 00:00:05.49, bitrate: 1411 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fa0e201ce00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fa0e201ce00] profile High, level 3.1
[libx264 @ 0x7fa0e201ce00] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:-3:-3 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=2.00:0.70 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-4 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.20
Output #0, mp4, to 'video2.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 192 kb/s
Metadata:
encoder : Lavc57.89.100 aac
frame= 195 fps=177 q=-1.0 Lsize= 150kB time=00:00:07.68 bitrate= 160.2kbits/s speed=6.96x
video:14kB audio:129kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.516541%
[libx264 @ 0x7fa0e201ce00] frame I:1 Avg QP: 9.03 size: 6402
[libx264 @ 0x7fa0e201ce00] frame P:49 Avg QP: 6.59 size: 41
[libx264 @ 0x7fa0e201ce00] frame B:145 Avg QP: 9.67 size: 39
[libx264 @ 0x7fa0e201ce00] consecutive B-frames: 0.5% 1.0% 0.0% 98.5%
[libx264 @ 0x7fa0e201ce00] mb I I16..4: 54.7% 36.0% 9.3%
[libx264 @ 0x7fa0e201ce00] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:100.0%
[libx264 @ 0x7fa0e201ce00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.2% 0.0% 0.0% direct: 0.0% skip:99.8% L0:70.1% L1:29.9% BI: 0.0%
[libx264 @ 0x7fa0e201ce00] 8x8 transform intra:36.0% inter:14.3%
[libx264 @ 0x7fa0e201ce00] coded y,uvDC,uvAC intra: 4.3% 0.0% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x7fa0e201ce00] i16 v,h,dc,p: 91% 5% 4% 0%
[libx264 @ 0x7fa0e201ce00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 72% 8% 20% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x7fa0e201ce00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 23% 25% 4% 3% 3% 3% 2% 2%
[libx264 @ 0x7fa0e201ce00] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 0x7fa0e201ce00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fa0e201ce00] ref P L0: 83.3% 8.3% 8.3%
[libx264 @ 0x7fa0e201ce00] ref B L0: 40.1% 59.9%
[libx264 @ 0x7fa0e201ce00] kb/s:14.38
[aac @ 0x7fa0e201e600] Qavg: 595.040
当我将这些视频导入Final Cut时,我可以看到两个视频都在2:30左右增加了静音(音频中没有):
ffmpeg -i "video1.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i "video2.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc "video_combined.mp4"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Duration: 00:00:06.04, start: 0.000000, bitrate: 143 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, 18 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, mpegts, to 'intermediate1.ts':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, q=2-31, 18 kb/s, 25 fps, 25 tbr, 90k tbn, 12800 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 151 fps=0.0 q=-1.0 Lsize= 135kB time=00:00:05.92 bitrate= 187.5kbits/s speed=2.43e+03x
video:14kB audio:87kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 34.259724%
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Duration: 00:00:07.80, start: 0.000000, bitrate: 157 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, 15 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, mpegts, to 'intermediate2.ts':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.71.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 800x800, q=2-31, 15 kb/s, 25 fps, 25 tbr, 90k tbn, 12800 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 195 fps=0.0 q=-1.0 Lsize= 192kB time=00:00:07.68 bitrate= 204.8kbits/s speed=2.6e+03x
video:14kB audio:129kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 33.605099%
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.38)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.2.0/include/openjpeg-2.2 --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, mpegts, from 'concat:intermediate1.ts|intermediate2.ts':
Duration: 00:00:07.82, start: 1.456778, bitrate: 342 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 800x800, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 169 kb/s
Output #0, mp4, to 'video_combined.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (High) ([33][0][0][0] / 0x0021), yuv420p(progressive), 800x800, q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 169 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 346 fps=0.0 q=-1.0 Lsize= 257kB time=00:00:13.74 bitrate= 153.3kbits/s speed=1.54e+03x
video:30kB audio:217kB subtitle:0kB other streams:0kB global headers:1kB muxing overhead: 4.243830%
组合视频的输出包含额外的静音,但第二个音频没有正确组合:
ffmpeg -f concat -i input.txt -map 0 \
-vcodec libx264 \
-aprofile aac_low -acodec aac -strict experimental -cutoff 15000 -b:a 32k
"video_combined.mp4"
有什么想法吗?