Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Audio 如何在覆盖ffmpeg命令中包含音频?_Audio_Video_Ffmpeg - Fatal编程技术网

Audio 如何在覆盖ffmpeg命令中包含音频?

Audio 如何在覆盖ffmpeg命令中包含音频?,audio,video,ffmpeg,Audio,Video,Ffmpeg,使用ffmpeg,我成功地在源视频上添加了视频覆盖(源视频有音频,覆盖没有)。但是,原始视频的音频不会出现在结果视频中 ffmpeg -i source.mp4 -i overlay.mp4 -filter_complex "[0:v]setpts=PTS-STARTPTS, scale=1280x720[top]; [1:v]setpts=PTS-STARTPTS, scale=1280x720, format=yuva420p, colorchannelmixer

使用ffmpeg,我成功地在源视频上添加了视频覆盖(源视频有音频,覆盖没有)。但是,原始视频的音频不会出现在结果视频中

  ffmpeg  -i source.mp4 -i overlay.mp4 -filter_complex "[0:v]setpts=PTS-STARTPTS, scale=1280x720[top]; 
  [1:v]setpts=PTS-STARTPTS, scale=1280x720, format=yuva420p, 
  colorchannelmixer=aa=0.2[bottom]; [top][bottom]overlay=shortest=1" 
  -shortest -acodec copy -vcodec libx264 result1.mp4
  ffmpeg -i result1.mp4 -i audio.mp3 -c:v copy -c:a aac result2.mp4
即使我对上一个命令的结果执行以下单独的命令,新的结果视频中仍然没有音频显示

  ffmpeg  -i source.mp4 -i overlay.mp4 -filter_complex "[0:v]setpts=PTS-STARTPTS, scale=1280x720[top]; 
  [1:v]setpts=PTS-STARTPTS, scale=1280x720, format=yuva420p, 
  colorchannelmixer=aa=0.2[bottom]; [top][bottom]overlay=shortest=1" 
  -shortest -acodec copy -vcodec libx264 result1.mp4
  ffmpeg -i result1.mp4 -i audio.mp3 -c:v copy -c:a aac result2.mp4
以下是日志:

ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.17)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'course/final_video/3008_01_01_01_audio.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:06:01.48, start: 0.000000, bitrate: 215 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 141 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono, fltp, 70 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'images/overlay.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Duration: 00:24:00.38, start: 0.000000, bitrate: 575 kb/s
  Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 442 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/22/2020.
      vendor_id       : [0][0][0][0]
  Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/22/2020.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (h264) -> setpts
  Stream #1:0 (h264) -> setpts
  overlay -> Stream #0:0 (libx264)
  Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[swscaler @ 0x10c590000] No accelerated colorspace conversion found from yuva420p to argb.
[libx264 @ 0x7fc532813200] using SAR=1/1
[libx264 @ 0x7fc532813200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fc532813200] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x7fc532813200] 264 - core 161 r3049 55d517b - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=6 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 'course/final_video/3008_01_01_01_overlay.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 12800 tbn (default)
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/22/2020.
      vendor_id       : [0][0][0][0]

Stream mapping:
  Stream #0:0 (h264) -> setpts
  Stream #1:0 (h264) -> setpts
  overlay -> Stream #0:0 (libx264)
  Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[swscaler @ 0x10c590000] No accelerated colorspace conversion found from yuva420p to argb.
[libx264 @ 0x7fc532813200] using SAR=1/1
[libx264 @ 0x7fc532813200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fc532813200] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x7fc532813200] 264 - core 161 r3049 55d517b - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=6 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 'course/final_video/3008_01_01_01_overlay.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 12800 tbn (default)
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 11/22/2020.
      vendor_id       : [0][0][0][0]
frame= 9037 fps= 32 q=-1.0 Lsize=   20954kB time=00:06:01.62 bitrate= 474.7kbits/s speed=1.26x    
video:15006kB audio:5651kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.439596%
[libx264 @ 0x7fc532813200] frame I:37    Avg QP:14.51  size:123799
[libx264 @ 0x7fc532813200] frame P:2277  Avg QP:16.97  size:  3221
[libx264 @ 0x7fc532813200] frame B:6723  Avg QP:24.31  size:   513
[libx264 @ 0x7fc532813200] consecutive B-frames:  0.8%  0.0%  0.0% 99.2%
[libx264 @ 0x7fc532813200] mb I  I16..4:  8.3% 64.9% 26.9%
[libx264 @ 0x7fc532813200] mb P  I16..4:  0.5%  1.1%  0.2%  P16..4: 16.1%  3.1%  2.3%  0.0%  0.0%    skip:76.7%
[libx264 @ 0x7fc532813200] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 10.5%  0.1%  0.0%  direct: 0.2%  skip:89.2%  L0:45.2% L1:54.7% BI: 0.1%
[libx264 @ 0x7fc532813200] 8x8 transform intra:63.6% inter:83.0%
[libx264 @ 0x7fc532813200] coded y,uvDC,uvAC intra: 56.4% 61.0% 42.7% inter: 1.9% 1.9% 0.0%
[libx264 @ 0x7fc532813200] i16 v,h,dc,p: 29% 18% 18% 35%
[libx264 @ 0x7fc532813200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 19% 31%  4%  4%  4%  4%  5%  5%
[libx264 @ 0x7fc532813200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 22% 15%  4%  5%  6%  5%  5%  5%
[libx264 @ 0x7fc532813200] i8c dc,h,v,p: 51% 29% 14%  6%
[libx264 @ 0x7fc532813200] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fc532813200] ref P L0: 66.0%  6.9% 17.0% 10.1%
[libx264 @ 0x7fc532813200] ref B L0: 77.2% 20.6%  2.2%
[libx264 @ 0x7fc532813200] ref B L1: 90.2%  9.8%
[libx264 @ 0x7fc532813200] kb/s:340.06

-map
告诉它您想要哪种音频:

ffmpeg -i source.mp4 -i overlay.mp4 -filter_complex "[0:v]setpts=PTS-STARTPTS, scale=1280x720[top]; 
  [1:v]setpts=PTS-STARTPTS, scale=1280x720, format=yuva420p, 
  colorchannelmixer=aa=0.2[bottom]; [top][bottom]overlay=shortest=1[v]" 
  -map "[v]" -map 0:a -shortest -acodec copy -vcodec libx264 result1.mp4
  • 原始命令未使用
    -map
    ,因此已启用。这将选择频道最多的流,该流是来自
    overlay.mp4
    (流#1:1)的音频

我添加了日志,非常好。谢谢