ajuste de audio ffmpeg mp4

1

Mi mp4 es h264 + aac Quiero usar ffmpeg.exe para agregarle una música de fondo, esta musci es más corta que la mp4, por lo tanto, la música debería repetirse

Yo he tratado ffmpeg -i test.mp4 -i background.m4a -filter_complex "amovie=background.m4a:loop=0" output.mp4

pero obtengo un mal resultado, reemplaza la pista de audio de mi test.mp4 por background.m4a no se mezcla ¿Podría alguien dar alguna ayuda?

actualizar

G:\bin>ffmpeg -i test.mp4 -filter_complex "amovie=music.m4a:loop=0[loop],volume=0.5;[0:a][loop]amerge=inputs=2[a]"  -map 0:v -map "[a]
" -c:v copy -ac 2 -shortest -movflags +faststart output.mp4
ffmpeg version N-66931-gbbd8c85 Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct 17 2014 01:09:43 with gcc 4.9.1 (GCC)
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontco
nfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable
-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libope
njpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-li
bvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enab
le-libx265 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      54. 10.100 / 54. 10.100
  libavcodec     56.  8.100 / 56.  8.100
  libavformat    56.  9.100 / 56.  9.100
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.106 /  5.  1.106
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.15.102
  Duration: 00:02:00.04, start: 0.000000, bitrate: 2947 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 2846 kb/s, 15.97 fps, 25000000.00 tbr, 25000000.00 tb
n, 50000000.00 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
File 'output.mp4' already exists. Overwrite ? [y/N] y
[Parsed_amerge_2 @ 0000000000302880] No channel layout for input 1
[Parsed_amerge_2 @ 0000000000302880] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.9.100
    Stream #0:0: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s
    Metadata:
      encoder         : Lavc56.8.100 libvo_aacenc
    Stream #0:1(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 2846 kb/s, 15.97 fps, 25000000.00 tbn, 25000000.00 tbc (default
)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:2: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s
    Metadata:
      encoder         : Lavc56.8.100 libvo_aacenc
Stream mapping:
  Stream #0:1 (aac) -> volume
  Stream #0:1 (aac) -> amerge:in0
  volume -> Stream #0:0 (libvo_aacenc)
  Stream #0:0 -> #0:1 (copy)
  amerge -> Stream #0:2 (libvo_aacenc)
Press [q] to stop, [?] for help
[mp4 @ 00000000003044c0] Starting second pass: moving the moov atom to the beginning of the file
frame= 1917 fps=382 q=-1.0 Lsize=   45571kB time=00:02:00.00 bitrate=3110.9kbits/s
video:41707kB audio:3751kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.248006%

Actualización2:

➜  misc  ffmpeg -i test.mp4 -filter_complex "amovie=music.m4a:loop=1[loop];[0:a][loop]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2  -movflags +faststart -strict -2 output.mp4
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.15.102
  Duration: 00:02:52.52, start: 0.000000, bitrate: 2867 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 2765 kb/s, 17.11 fps, 25000k tbr, 25000k tbn, 50000k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
File 'output.mp4' already exists. Overwrite ? [y/N] y
[Parsed_amerge_1 @ 0x7f804bd0f880] No channel layout for input 1
[Parsed_amerge_1 @ 0x7f804bd0f880] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 2765 kb/s, 17.11 fps, 25000k tbr, 25000k tbn, 25000k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc56.26.100 aac
Stream mapping:
  Stream #0:1 (aac) -> amerge:in0
  Stream #0:0 -> #0:0 (copy)
  amerge -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
Error while decoding stream #0:1: Cannot allocate memory
    Last message repeated 6517 times
frame= 2663 fps=0.0 q=-1.0 size=   49484kB time=00:02:35.84 bitrate=2601.2kbits/Error while decoding stream #0:1: Cannot allocate memory
    Last message repeated 715 times
[mp4 @ 0x7f804c05b000] Starting second pass: moving the moov atom to the beginning of the file
frame= 2952 fps=0.0 q=-1.0 Lsize=   58332kB time=00:02:52.47 bitrate=2770.5kbits/s    
video:58245kB audio:49kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.065551%
➜  misc 
Jason
fuente

Respuestas:

1

Debe fusionar ambas entradas en una sola secuencia con amerge. Esto creará una transmisión de audio de 4 canales (suponiendo que ambas entradas sean estéreo) que luego se volverá a mezclar en estéreo -ac 2.

ffmpeg -i video.mp4 -filter_complex \
"amovie=music.m4a:loop=0[loop]; \
 [0:a][loop]amerge=inputs=2[a]" \
-map 0:v -map "[a]" -c:v copy -ac 2 -shortest -movflags +faststart output.mp4
  • -shortestse usa aquí para evitar que se codifique para siempre, ya que se amovierepetirá infinitamente.

  • Si desea reducir el volumen de la música, use el volumefiltro.

  • No proporcionó información sobre sus entradas, por lo que asumí que ambas entradas contienen audio estéreo.

  • El video se copia en secuencia para evitar una nueva codificación innecesaria.

lema
fuente
Vídeo. mp4 puede ser estéreo o mono
Jason
el comando funciona bien, espere que cuando baje el volumen con volumen = 0.5, music.m4a parece no mezclarse con test.mp4 cmd es ffmpeg -i test.mp4 -filter_complex "amovie = music.m4a: loop = 0 [loop], volume = 0.2; [0: a] [loop] amerge = input = 2 [a] "-map 0: v -map" [a] "-c: v copy -ac 2 -shortest -movflags + faststart output.mp4
Jason
He actualizado la salida de la consola por comando anterior, agradezco su ayuda
Jason
lo siento, lo siento, omita alguna información publicada de ffmpeg, he procesado toda la salida de la consola
Jason
@ Jason Prueba "amovie=music.m4a:loop=0,volume=0.5[loop];[0:a][loop]amerge=inputs=2[a]". No lo probé; Puede no funcionar y volumepuede ser exigente a veces.
llogan