0

I am trying to merge the audio of my video with a music track, whilst keeping the picture part the same. To do this I am trying to use the amix filter, but FFmpeg seems to hang when I run the command. Am I doing something wrong?

$ ffmpeg -y -i aae635a604ff16c9a320376398ac121b_0.000_5.015.mp4 -i
full_dillon_in_pro_audio.mp3 -filter_complex
"[1:a][0:a]amix=inputs=2[m]" -map 0:v -map [m] -c:v libx264 -preset
ultrafast -c:a aac 4615491572977860225_PLzGS5hkLTwTfxlgkk0.mp4

ffmpeg version N-86394-g66cf78e Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/usr/local
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
--bindir=/usr/local/bin --disable-doc --disable-static --enable-shared
--disable-ffplay --extra-libs=-ldl --enable-version3
--enable-libfreetype --enable-libx264 --enable-gpl --enable-openssl
--enable-nonfree --disable-debug
  libavutil      55. 63.100 / 55. 63.100
  libavcodec     57. 96.101 / 57. 96.101
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 91.100 /  6. 91.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'aae635a604ff16c9a320376398ac121b_0.000_5.015.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:00:05.04, start: 0.000000, bitrate: 656 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
1280x720 [SAR 1:1 DAR 16:9], 522 kb/s, 30 fps, 30 tbr, 15360 tbn, 60
tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[mp3 @ 0xf20a60] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from 'full_dillon_in_pro_audio.mp3':
  Metadata:
    title           : Dillon in Pro Audio
    artist          : Jingle Punks
    album           : YouTube Audio Library
    genre           : Dance & Electronic
    encoder         : Google
  Duration: 00:01:18.84, start: 0.000000, bitrate: 320 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s
Stream mapping:
  Stream #0:1 (aac) -> amix:input1 (graph 0)
  Stream #1:0 (mp3) -> amix:input0 (graph 0)
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  amix (graph 0) -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0xf338e0] using SAR=1/1
[libx264 @ 0xf338e0] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xf338e0] profile Constrained Baseline, level 3.1
[libx264 @ 0xf338e0] 264 - core 148 - H.264/MPEG-4 AVC codec -
Copyleft 2003-2016 - http://www.videolan.org/x264.html - options:
cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1
psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0
8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0
threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1
interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0
keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0
crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to '4615491572977860225_PLzGS5hkLTwTfxlgkk0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.72.101
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021),
yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps,
15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.96.101 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, 128 kb/s (default)
    Metadata:
      encoder         : Lavc57.96.101 aac
<hang for more than 10 minutes>

Other significantly more complex commands run in seconds or at most minutes.

12
  • Is it possible that one of the files is very short? When I try it myself, it works perfectly well until when FFmpeg hits the end of the shorter file. I used ffmpeg -i vid_input.mkv -f lavfi -i color=color=black -i aud_input.flac' -filter_complex "[0:v][1:v]overlay=eof_action=endall[v];[2:a][0:a]amix=inputs=2:duration=longest[a]" -map [v] -map [a] -c:v libx264 -crf 30 -preset ultrafast -c:a aac -b:a 128k test.mkvand could get it to work with this code; however, of course now you have a box in your video and also, VLC won't know where to set the time-slieder after the end of the video...
    – flolilo
    Jun 28, 2017 at 17:17
  • @flolilolilo In that example the two durations are: 00:00:05.04 and 00:01:18.84, so different... That causes it to hang? If I trim them both to the same length it will work?
    – Jon G
    Jun 28, 2017 at 17:23
  • I tried using -to and that worked for me - however, I would think that there's a work-around for this problem, but my mind is stuck at the overlay-thing...
    – flolilo
    Jun 28, 2017 at 17:27
  • I wondered if amix=input‌​s=2:duration=shortest might solve it, but it didn't in my test. Similarly if I use [1:a]atrim=0:5[a1];[a1][0:a]amix[m] it still hangs.
    – Jon G
    Jun 29, 2017 at 8:42
  • What does work for me is trimming both inputs (even though [0] is already 5s long) [0:v]trim=0:5[v0];[0:a]atrim=0:5[a0];[1:a]atrim=0:5[a1];[a0][a1]amix[m]. Does this count as an FFmpeg bug? Or just something I need to plan for?
    – Jon G
    Jun 29, 2017 at 8:44

1 Answer 1

0

This is fixed in the latest FFmpeg master branch, see discussion of the bug here:

http://www.ffmpeg-archive.org/amix-filter-hanging-td4680251.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .