2 source videos in FFMPEG… how to map audio?

2019-08-09 03:26发布

问题:

i am currently placing 2 videos side by side in FFMPEG. Here is the command:

ffmpeg -i input.mov -vf "[in] scale=1280:720, pad=2*1280:720 [left]; movie=right.mov, scale=1280:720 [right]; [left][right]  overlay=1280:0 [out]" -b:v 1000k -vcodec libx264 -an sidebyside.mp4

I now need to manage the audio. I keep trying to specify:

-acodec libfaac -ac 2 -map 0:1 -map 0:2

to take the 2 audio channels from the first input and use them. I keep getting the error:

[aformat @ 0x7febf2e01fc0] auto-inserting filter 'auto-inserted resampler 0' between the filter 'src' and the filter 'aformat'
    [aresample @ 0x7febf2e02180] [SWR @ 0x7febf40dd000] Input channel layout isnt supported
Error opening filters!

I'm looking for the best way to specify which video provides the audio! Thanks for any advice!

Here's the complete output:

ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jun  9 2012 21:40:17 with clang 3.0 (tags/Apple/clang-211.10.1)
  configuration: --prefix= --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libxvid --enable-postproc --enable-swscale --enable-avfilter --enable-pthreads --enable-yasm --enable-libfaac --enable-libmp3lame --cc=clang --enable-libvorbis
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'left.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-06-19 21:13:20
  Duration: 00:02:28.81, start: 0.000000, bitrate: 36378 kb/s
    Stream #0:0(eng): Video: mpeg2video (Main) (xdvf / 0x66766478), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 35000 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 59.94 tbc
    Metadata:
      creation_time   : 2012-06-19 21:13:20
      handler_name    : Apple Alias Data Handler
    Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 1 channels (FL), s16, 768 kb/s
    Metadata:
      creation_time   : 2012-06-19 21:13:20
      handler_name    : Apple Alias Data Handler
    Stream #0:2(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, 1 channels (FR), s16, 768 kb/s
    Metadata:
      creation_time   : 2012-06-19 21:13:20
      handler_name    : Apple Alias Data Handler
    Stream #0:3(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      creation_time   : 2012-06-19 21:13:20
      handler_name    : Apple Alias Data Handler
      timecode        : 02:20:28;08
File 'output.mp4' already exists. Overwrite ? [y/N] y
w:1920 h:1080 pixfmt:yuv420p tb:1/2997 sar:1/1 sws_param:flags=2
[buffersink @ 0x7febf2c18c80] No opaque field provided
[movie @ 0x7febf2c191c0] seek_point:0 format_name:(null) file_name:/Users/danielpcoffey/Desktop/tommy.mov stream_index:0
[scale @ 0x7febf2c19320] w:1920 h:1080 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuv420p sar:1/1 flags:0x4
[pad @ 0x7febf2c19800] w:1280 h:720 -> w:2560 h:720 x:0 y:0 color:0x000000FF
[scale @ 0x7febf2c1ca40] w:1920 h:1080 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuva420p sar:1/1 flags:0x4
[overlay @ 0x7febf2c1ce20] main w:2560 h:720 fmt:yuv420p overlay x:1280 y:0 w:1280 h:720 fmt:yuva420p
[overlay @ 0x7febf2c1ce20] main_tb:1/2997 overlay_tb:1/2997 -> tb:1/2997 exact:1
[aformat @ 0x7febf2e01fc0] auto-inserting filter 'auto-inserted resampler 0' between the filter 'src' and the filter 'aformat'
[aresample @ 0x7febf2e02180] [SWR @ 0x7febf40dd000] Input channel layout isnt supported
Error opening filters!

回答1:

The movie video filter just takes the video stream, not audio, so you might not have to map the audio at all.

If you do want to keep finer control over the audio, with newer versions of FFmpeg you can select output streams by type instead of only by number, i.e., -map 0:a -map 1:v which is worlds simpler and less error prone.

So for your situation I'd recommend either (grabbing all audio from input):

ffmpeg -i input.mov -vf "...movie=right.mov..." -c:a libfaac -ac 2 out.mp4

or (grabbing first and second audio streams from input)

ffmpeg -i input.mov -vf "...movie=right.mov..." -c:a libfaac -ac 2 -map 0:v -map 0:a:0 -map 0:a:1 out.mp4