Demuxing
I am demuxing TS segments into audio and video as follows.
ffmpeg -y -i input.ts -vcodec copy -an output_video.ts
ffmpeg -y -i input.ts -acodec copy -vn output_audio.aac
Inspecting Input
The start_pts and start_time on input.ts are as shown below. I was able to inspect these values using ffprobe -show_streams -print_format json input.ts
"start_pts": 8306558438,
"start_time": "92295.093756",
Inspecting output video
The output .ts has some default start_pts and start_time values as shown below. These were also obtained using the same ffprobe command as indicated above.
"start_pts": 126000,
"start_time": "1.400000",
Inspecting output audio
The same ffprobe command on output_audio.aac shows that the output aac has invalid codec_tag and codec_tag_string as shown below. The start_pts and start_time are not present in the output_audio.aac.
"codec_tag_string": "[0][0][0][0]", (should have been [15][0][0][0])
"codec_tag": "0x0000", (should have been 0xf000)
Questions
Wondering if this difference in the start_pts, start_time, codec_tag is expected?
If it is expected, what can I do to ensure that the all of these parameters get retained on the output?
If it is not expected, is there some more information I can share to track this down?
Note
There were other outputs that I found inconsistent in the ffprobe command for the output_audio.aac like duration etc.. I shared what I thought are most valuable at this point. If required I can share complete outputs from all of the above executions.
[EDIT 07/30/2018 - 08:00 MST]
logs for ffmpeg -y -i input.ts -vcodec copy -an output_video.ts -acodec copy -vn output_audio.aacare as shown below.
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.3.0/include/openjpeg-2.3 --enable-nonfree
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
[mpegts # 0x7f88ed803000] start time for stream 0 is not set in estimate_timings_from_pts
Input #0, mpegts, from 'i7h9456s_media_46185.ts':
Duration: 00:00:06.05, start: 86216.852667, bitrate: 2898 kb/s
Program 1
Stream #0:0[0x102]: Data: timed_id3 (ID3 / 0x20334449)
Stream #0:1[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
Output #0, mpegts, to '../output_video.ts':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(tv, smpte170m, progressive), 640x360 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
Output #1, adts, to '../output_audio.aac':
Metadata:
encoder : Lavf58.12.100
Stream #1:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 190 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:2 -> #1:0 (copy)
Press [q] to stop, [?] for help
frame= 180 fps=0.0 q=-1.0 Lsize= 2088kB time=00:00:06.03 bitrate=2833.8kbits/s speed= 904x
video:1918kB audio:142kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.349750%
All the differences are expected. FFmpeg removes input timestamp offset unless set otherwise. The MPEG-TS muxer also adds a timestamp offset.
You can preserve source timestamps when remuxing TS, and also avoid the muxer's offset, like this,
ffmpeg -y -copyts -i input.ts -vcodec copy -an -muxdelay 0 -muxpreload 0 output_video.ts
As .aac is a raw ADTS stream, there is no codec tag string present. This is expected. Mux to .m4a or .mka or a similar container if tags are needed.
Related
I have a problem with some mp3 files. When transcoding the file with FFMPEG I get the following error:
[mp3float # 0x7fd42f813200] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
Is this a problem of the file itself, and how it is produced?
Or is it a problem of FFMPEG?
Here full decoding message:
ffmpeg version git-2020-07-28-dfd12ee Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.16)
configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD-dfd12ee_2 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --disable-libjack --disable-indev=jack --enable-opencl --enable-videotoolbox --disable-htmlpages --enable-libfdk-aac --enable-nonfree
libavutil 56. 57.100 / 56. 57.100
libavcodec 58. 97.102 / 58. 97.102
libavformat 58. 49.100 / 58. 49.100
libavdevice 58. 11.101 / 58. 11.101
libavfilter 7. 87.100 / 7. 87.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
[mp3 # 0x7fd42f808200] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'Ice Mc - Think About The Way.mp3':
Metadata:
title : Think About The Way
TBPM : 133
artist : Ice MC
date : 1994
track : 4/15
disc : 0
album_artist : ICE MC
Duration: 00:04:16.39, start: 0.000000, bitrate: 323 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 600x592 [SAR 72:72 DAR 75:74], 90k tbr, 90k tbn, 90k tbc (attached pic)
Metadata:
comment : Other
Stream mapping:
Stream #0:1 -> #0:0 (mjpeg (native) -> wrapped_avframe (native))
Stream #0:0 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
Metadata:
title : Think About The Way
TBPM : 133
artist : Ice MC
date : 1994
track : 4/15
disc : 0
album_artist : ICE MC
encoder : Lavf58.49.100
Stream #0:0: Video: wrapped_avframe, yuvj420p(progressive), 600x592 [SAR 72:72 DAR 75:74], q=2-31, 200 kb/s, 90k fps, 90k tbn, 90k tbc (attached pic)
Metadata:
comment : Other
encoder : Lavc58.97.102 wrapped_avframe
Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc58.97.102 pcm_s16le
[mp3float # 0x7fd42f813200] Header missing
Error while decoding stream #0:0: Invalid data found when processing input
frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:04:16.60 bitrate=N/A speed= 725x
video:1kB audio:44204kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
What is also noticed is that this mp3 has the cover embedded as a video stream. And there is also this weird cross mapping. Not sure if that is normal?
Are you sure, that you use only the stream you need? If no, you can check it by printing all the stream number of packets, returned by av_read_frame.
To select a specific stream, you should discard others. Check this thread to find out how: How to change stream index in libavformat
From
-t duration (input/output)
When used as an input option (before -i), limit the duration of data read from the input file.
When used as an output option (before an output url), stop writing the output after its duration reaches duration.
So this should yield a 1-minute file with timestamps starting at 1:49, right?
ffmpeg -y -copyts -ss 1:49 -i ~/Videos/input.mkv -c copy -t 1:00 timing-1m49s.mkv
ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7 (SUSE Linux)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -g' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -g' --disable-htmlpages --enable-pic --disable-stripping --enable-shared --disable-static --enable-gpl --disable-openssl --enable-avresample --enable-libcdio --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcelt --enable-libcdio --enable-libdc1394 --enable-libfreetype --enable-libgsm --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-netcdf --enable-vaapi --enable-vdpau --enable-libfdk_aac --enable-nonfree --enable-libmp3lame --enable-libtwolame --enable-libx264 --enable-libx265 --enable-libxvid
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, matroska,webm, from '/home/ariel/Videos/input.mkv':
Metadata:
encoder : libebml v0.7.7 + libmatroska v0.8.0
creation_time : 2006-07-20T03:07:03.000000Z
Duration: 00:23:57.06, start: 0.000000, bitrate: 1983 kb/s
Stream #0:0: Video: h264 (High), yuv420p(progressive), 720x480, SAR 37:30 DAR 37:20, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
Stream #0:1(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
Stream #0:2(jpn): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:3(eng): Subtitle: dvd_subtitle, 720x480 (default)
Metadata:
title : English Audio
Stream #0:4(eng): Subtitle: dvd_subtitle, 720x480
Metadata:
title : Japanese Audio
Output #0, matroska, to 'timing-1m49s.mkv':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 720x480 [SAR 37:30 DAR 37:20], q=2-31, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc (default)
Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s (default)
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=-1.0 Lsize= 1kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Wrong. It outputs a file with no frames:
-rwxrwx--- 1 root users 805 Jul 30 01:36 timing-1m49s.mkv
I have to specify -t 1:49 or more, and e.g. -t 1:55 produces a 6-second file that starts at 0:00 and according to the metadata should last 1:55.
I arrived at this point trying to extract a clip and add subtitles in the same command, but this minimal case looks to me contrary to the documentation.
Yes, the -t used as output option looks at the timestamps, which usually start at zero. Except for cases like these when -copyts is used. Use -t as input option:
ffmpeg -y -copyts -ss 1:49 -t 1:00 -i ~/Videos/input.mkv -c copy timing-1m49s.mkv
I have a .ts file (Download files here: http://dropcanvas.com/2gmsg/1).
I want to split this video while I expect ALL other properties remain same including pts time.
Here is what I try to achieve this:
ffmpeg -ss 0.000 -i sample.ts -y -c copy -t 3 splitted.ts
Expected start time: 94678.950389
New start time: 1.402367
I expect the above command should only take first 3 seconds of the .ts file and all other stuff to stay same. I've seen copyts and copytb options from the documentation but I wasn't able to use them.
So how do I do this?
Thank you
Here are the logs for copyts. It creates a 0 byte splitted.ts file:
ffmpeg -ss 0:00:00 -i sample.ts -to 00:00:03 -y -c copy -copyts splitted.ts
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.0 (clang-700.0.72)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libx265 --enable-nonfree --enable-vda
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
[NULL # 0x7fafac02fc00] start time for stream 2 is not set in estimate_timings_from_pts
Input #0, mpegts, from 'sample.ts':
Duration: 00:00:10.07, start: 94678.950389, bitrate: 934 kb/s
Program 1
Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 854x480 [SAR 1280:1281 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 140 kb/s
Stream #0:2[0x102]: Data: timed_id3 (ID3 / 0x20334449)
Output #0, mpegts, to 'splitted.ts':
Metadata:
encoder : Lavf57.25.100
Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 854x480 [SAR 1280:1281 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, 140 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=-1.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
This works for me
ffmpeg -seek_timestamp 1 -ss 94678.950389 -i sample.ts -y -c copy -copyts -to 94681.950389 -muxdelay 0 splitted.ts
Your original command can work if you use the frames flag.
ffmpeg -ss 0.000 -i sample.ts -y -c copy -copyts -muxdelay 0 -vframes 90 splitted.ts
Where 90 represents amount of frames in t seconds.
I have multiple streaming sources that need to combined and re-streamed as a single source.
My sources are:
A local low rate RTP audio stream
A camera
I need to redistribute the combined stream (via UDP multicast) across the local network.
The problem I am seeing is that periodically ffmpeg appears to lock up and stop processing the combination after an indeterminate amount of time (sometimes as little as 15 min sometimes almost an hour). However if I redirect the streams independently (audio or video only) there appears to be no problem and the run indefinitely.
Command
ffmpeg -f rtp -i rtp://127.0.0.1:6666 -f video4linux2 -standard NTSC -s 704x480 -i /dev/video1 -strict experimental -vcodec libx264 -acodec ac3 -preset ultrafast -r 3 -g 3 -keyint_min 6 -x264opts "keyint=6:min-keyint=6:no-scenecut" -b:v 200k -ac 1 -b:a 64k -f mpegts udp://225.1.1.15:30000
Output
ffmpeg version 2.5.1- http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2014 the FFmpeg developers
built on Dec 18 2014 09:06:26 with gcc 4.8 (Debian 4.8.3-19)
configuration: --enable-gpl --enable-version3 --disable-shared --disable- debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable- libx265 --enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx -- enable-libfreetype --enable-fontconfig --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus -- disable-ffserver --enable-libass --enable-gnutls --cc=gcc-4.8
libavutil 54. 15.100 / 54. 15.100
libavcodec 56. 13.100 / 56. 13.100
libavformat 56. 15.102 / 56. 15.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
[rtp # 0xb61abe0] Guessing on RTP content - if not received properly you need an SDP file describing it
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, rtp, from 'rtp://127.0.0.1:6666':
Duration: N/A, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s
Input #1, video4linux2,v4l2, from '/dev/video1':
Duration: N/A, start: 1424887596.039777, bitrate: 162039 kb/s
Stream #1:0: Video: rawvideo (YUY2 / 0x32595559`enter code here`), yuyv422, 704x480, 162039 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 # 0xb61f900] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 # 0xb61f900] profile High 4:2:2, level 2.2, 4:2:2 8-bit
Output #0, mpegts, to 'udp://225.1.1.15:30000':
Metadata:
encoder : Lavf56.15.102
Stream #0:0: Video: h264 (libx264), yuv422p, 704x480, q=-1--1, 200 kb/s, 3 fps, 90k tbn, 3 tbc
Metadata:
encoder : Lavc56.13.100 libx264
Stream #0:1: Audio: ac3, 8000 Hz, mono, fltp, 64 kb/s
Metadata:
encoder : Lavc56.13.100 ac3
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (pcm_mulaw (native) -> ac3 (native))
Press [q] to stop, [?] for help
frame= 5 fps=0.0 q=12.0 size= 0kB time=00:00:00.33 bitrate= 0.0kbits/s dup=0 drop=12
Turns out the only way I was able to get the streams to run for an extended period was to split them into two independent streams.
I am currently having issues with ffmpeg and one of its filters.
I am trying to merge 2 audio streams of a video into one. for this purpose I tried this command:
ffmpeg -i /home/maniaplanet/Videos/ManiaPlanet\ 2014-08-21\ 20-09-13-082.avi.output.mkv -filter_complex "[0:1][0:2] amerge=inputs=2"-c:v copy -c:a libvo_aacenc -b:a 256k /var/www/files/output.mp4
But I get this output:
ffmpeg version 1.0.10 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 25 2014 07:50:40 with gcc 4.7 (Debian 4.7.2-5)
configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libfdk-aac --enable-libdc1394 --disable-altivec --dis libavutil 51. 73.101 / 51. 73.101
libavcodec 54. 59.100 / 54. 59.100
libavformat 54. 29.104 / 54. 29.104
libavdevice 54. 2.101 / 54. 2.101
libavfilter 3. 17.100 / 3. 17.100
libswscale 2. 1.101 / 2. 1.101
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, matroska,webm, from '/home/maniaplanet/Videos/ManiaPlanet 2014-08-21 20-09-13-082.avi.output.mkv':
Metadata:
ISRC : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
ENCODER : Lavf55.37.100
Duration: 01:49:48.47, start: 0.000000, bitrate: 3867 kb/s
Stream #0:0: Video: h264 (High), yuv420p, 1280x1024, SAR 1:1 DAR 5:4, 30 fps, 30 tbr, 1k tbn, 60 tbc (default)
Stream #0:1: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
Stream #0:2: Audio: mp3, 48000 Hz, stereo, s16, 320 kb/s (default)
File '/var/www/files/output.mp4' already exists. Overwrite ? [y/N] y
Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[libvo_aacenc # 0x7ae800] Unable to set encoding parameters
Output #0, mp4, to '/var/www/files/output.mp4':
Metadata:
ISRC : Video:RGB24 Audio0:Headset (2- Plantronics .Audio 655 DSP) Audio1:Headset (2- Plantronics .Audio 655 DSP)
ENCODER : Lavf55.37.100
Stream #0:0: Audio: aac, 48000 Hz, 4.0, s16, 256 kb/s
Stream #0:1: Video: h264, yuv420p, 1280x1024 [SAR 1:1 DAR 5:4], q=2-31, 30 fps, 90k tbn, 1k tbc (default)
Stream mapping:
Stream #0:1 (mp3) -> amerge:in0
Stream #0:2 (mp3) -> amerge:in1
amerge -> Stream #0:0 (libvo_aacenc)
Stream #0:0 -> #0:1 (copy)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I think the important part is at the bottom:
Stream mapping:
Stream #0:1 (mp3) -> amerge:in0
Stream #0:2 (mp3) -> amerge:in1
amerge -> Stream #0:0 (libvo_aacenc)
Stream #0:0 -> #0:1 (copy)
It maps the video stream as the second stream and the audio gets first. How do i resolve this? -map did not help. (Maybe I just used it wrong)
Example
ffmpeg -i input -filter_complex "[0:a:0][0:a:1] amerge=inputs=2 [a]" \
-map [0:v] -map "[a]" -c:v copy -c:a libfdk_aac -ac 2 -b:a 128k output.mp4
Notes
Your output in your question contained 4 channels of audio, but I'll assume you actually wanted to downmix it to stereo. You can do that with the pan audio filter or with -ac 2 as shown above. See FFmpeg Audio Channel Manipulation: 2 × stereo → stereo for an example using pan.
As you guessed, you can control mapping with -map. The order of the mapping can determine the output of the output mapping.
libfdk_aac is the best AAC encoder supported by ffmpeg, and libvo_aacenc is the worst. I switched to libfdk_aac since your build supports it, and it will allow a lower bitrate and still sound fairly good. See the FFmpeg AAC Encoding Guide.
I changed the filtering input from [0:1] to [0:a:0] which means "first input:audio stream type:first (audio) stream". In this case it maps to the same stream but this allows you to be slightly lazier.
You can add -movflags +faststart if your viewers are going to watch this via progressive download in a browser. It will relocate the moov atom from the end of the file to the beginning to allow playback to begin with less of a wait by the viewer.