Using FFmpeg with URL input causes SIGSEGV in AWS Lambda (Python runtime) - python-3.x

I'm trying to implement a video converting solution on AWS Lambda following their article named Processing user-generated content using AWS Lambda and FFmpeg.
However when I run my command with subprocess.Popen() it returns -11 which translates to SIGSEGV (segmentation fault).
I've tried to process the video with the newest (4.3.1) static build from John Van Sickle's site as with the "official" ffmpeg-lambda-layer but it seems like it doesn't matter which one I use, the result is the same.
If I download the video to the Lambda's /tmp directory and add this downloaded file as an input to FFmpeg it works correctly (with the same parameters). However I'm trying to prevent this as the /tmp directory's max. size is only 512 MB which is not quite enough for me.
The relevant code which returns SIGSEGV:
ffmpeg_cmd = '/opt/bin/ffmpeg -stream_loop -1 -i "' + s3_source_signed_url + '" -i /opt/bin/audio.mp3 -i /opt/bin/watermark.png -shortest -y -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset veryfast -r 30 -g 60 -b:v 4500k -c:a copy -map 0:v:0 -map 1:a:0 -filter_complex scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,overlay=(W-w)/2:(H-h)/2,format=yuv420p -loglevel verbose -f flv -'
command1 = shlex.split(ffmpeg_cmd)
p1 = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p1.communicate()
print(p1.returncode) #prints -11
stderr of FFmpeg:
ffmpeg version 4.1.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[tcp # 0x728cc00] Starting connection attempt to 52.219.74.177 port 443
[tcp # 0x728cc00] Successfully connected to 52.219.74.177 port 443
[h264 # 0x729b780] Reinit context to 1280x720, pix_fmt: yuv420p
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://bucket.s3.amazonaws.com --> presigned url with 15 min expiration time':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomavc1
creation_time : 2015-09-02T07:42:42.000000Z
Duration: 00:00:15.64, start: 0.000000, bitrate: 2640 kb/s
Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, left), 1280x720 [SAR 1:1 DAR 16:9], 2475 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
Metadata:
creation_time : 2015-09-02T07:42:42.000000Z
handler_name : L-SMASH Video Handler
encoder : AVC Coding
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
creation_time : 2015-09-02T07:42:42.000000Z
handler_name : L-SMASH Audio Handler
[mp3 # 0x733f340] Skipping 0 bytes of junk at 1344.
Input #1, mp3, from '/opt/bin/audio.mp3':
Metadata:
encoded_by : Logic Pro X
date : 2021-01-03
coding_history :
time_reference : 158760000
umid : 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004500F9E4
encoder : Lavf58.49.100
Duration: 00:04:01.21, start: 0.025057, bitrate: 320 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
Metadata:
encoder : Lavc58.97
Input #2, png_pipe, from '/opt/bin/watermark.png':
Duration: N/A, bitrate: N/A
Stream #2:0: Video: png, 1 reference frame, rgba(pc), 701x190 [SAR 1521:1521 DAR 701:190], 25 tbr, 25 tbn, 25 tbc
[Parsed_scale_0 # 0x7341140] w:1920 h:1080 flags:'bilinear' interl:0
Stream mapping:
Stream #0:0 (h264) -> scale
Stream #2:0 (png) -> overlay:overlay
format -> Stream #0:0 (libx264)
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264 # 0x72d8600] Reinit context to 1280x720, pix_fmt: yuv420p
[Parsed_scale_0 # 0x733c1c0] w:1920 h:1080 flags:'bilinear' interl:0
[graph 0 input from stream 0:0 # 0x7669200] w:1280 h:720 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[graph 0 input from stream 2:0 # 0x766a980] w:701 h:190 pixfmt:rgba tb:1/25 fr:25/1 sar:1521/1521 sws_param:flags=2
[auto_scaler_0 # 0x7670240] w:iw h:ih flags:'bilinear' interl:0
[deinterlace_in_2_0 # 0x766b680] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 2:0' and the filter 'deinterlace_in_2_0'
[Parsed_scale_0 # 0x733c1c0] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1920 h:1080 fmt:yuv420p sar:1/1 flags:0x2
[Parsed_pad_1 # 0x733ce00] w:1920 h:1080 -> w:1920 h:1080 x:0 y:0 color:0x000000FF
[Parsed_setsar_2 # 0x733da00] w:1920 h:1080 sar:1/1 dar:16/9 -> sar:1/1 dar:16/9
[auto_scaler_0 # 0x7670240] w:701 h:190 fmt:rgba sar:1521/1521 -> w:701 h:190 fmt:yuva420p sar:1/1 flags:0x2
[Parsed_overlay_3 # 0x733e440] main w:1920 h:1080 fmt:yuv420p overlay w:701 h:190 fmt:yuva420p
[Parsed_overlay_3 # 0x733e440] [framesync # 0x733e5a8] Selected 1/50 time base
[Parsed_overlay_3 # 0x733e440] [framesync # 0x733e5a8] Sync level 2
[libx264 # 0x72c1c00] using SAR=1/1
[libx264 # 0x72c1c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 # 0x72c1c00] profile Progressive High, level 4.0, 4:2:0, 8-bit
[libx264 # 0x72c1c00] 264 - core 157 r2969 d4099dd - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=9 lookahead_threads=3 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=1 keyint=60 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=abr mbtree=1 bitrate=4500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'pipe:':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomavc1
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 4500 kb/s, 30 fps, 1k tbn, 30 tbc (default)
Metadata:
encoder : Lavc58.35.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/4500000 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: mp3 ([2][0][0][0] / 0x0002), 44100 Hz, stereo, fltp, 320 kb/s
Metadata:
encoder : Lavc58.97
frame= 27 fps=0.0 q=32.0 size= 247kB time=00:00:00.03 bitrate=59500.0kbits/s speed=0.0672x
frame= 77 fps= 77 q=27.0 size= 1115kB time=00:00:02.03 bitrate=4478.0kbits/s speed=2.03x
frame= 126 fps= 83 q=25.0 size= 2302kB time=00:00:04.00 bitrate=4712.4kbits/s speed=2.64x
frame= 177 fps= 87 q=26.0 size= 3576kB time=00:00:06.03 bitrate=4854.4kbits/s speed=2.97x
frame= 225 fps= 88 q=25.0 size= 4910kB time=00:00:07.96 bitrate=5047.8kbits/s speed=3.13x
frame= 272 fps= 89 q=27.0 size= 6189kB time=00:00:09.84 bitrate=5147.9kbits/s speed=3.22x
frame= 320 fps= 90 q=27.0 size= 7058kB time=00:00:11.78 bitrate=4907.5kbits/s speed=3.31x
frame= 372 fps= 91 q=26.0 size= 8098kB time=00:00:13.84 bitrate=4791.0kbits/s speed=3.4x
And that's the end of it. It should continue to do the processing until 00:04:02 as that's my audio's length but it stops here every time (approximately this is my video length).
The relevant code which works correctly:
ffmpeg_cmd = '/opt/bin/ffmpeg -stream_loop -1 -i "' + '/tmp/' + s3_source_key + '" -i /opt/bin/audio.mp3 -i /opt/bin/watermark.png -shortest -y -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset veryfast -r 30 -g 60 -b:v 4500k -c:a copy -map 0:v:0 -map 1:a:0 -filter_complex scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,overlay=(W-w)/2:(H-h)/2,format=yuv420p -loglevel verbose -f flv -'
command1 = shlex.split(ffmpeg_cmd)
p1 = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p1.communicate()
print(p1.returncode) #prints 0
With this code it repeats the video as many times as it has to do to be as long as the audio.
Both versions work correctly on my computer.
This question is almost the same but in my case FFmpeg is able to access the signed URL.

Related

ffmpeg issue after adding background audio

So I have an issue to which I cannot find an answer. I have a video which is 7min 38sec long after concat. When I want to add background audio to this video it cuts off the last 7sec of the original video. I cannot find the reason.
If anyone could help me in any way, it would be amazing because I have been troubleshooting this past 3 days.
My FFmpeg version is ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers.
For concat I use this: FFmpeg -f concat -safe 0 -i txtfile.txt -c copy -ac 2 output.mp4
For adding background audio I use this: ffmpeg -i output.mp4 -i background.mp3 -c:v copy -filter_complex "[0:a]aformat=fltp:44100:stereo,apad[0a];[1]aformat=fltp:44100:stereo,volume=0.2[1a];[0a][1a]amerge[a]" -map 0:v -map "[a]" -ac 2 -shortest output_with_background.mp4
And the console output while doing its stuff is:
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200523
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baee72440] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\videos.txt':
Duration: N/A, start: -0.023220, bitrate: 18916 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 18861 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 54 kb/s
Metadata:
handler_name : SoundHandler
File 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\output.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\output.mp4':
Metadata:
encoder : Lavf58.29.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 18861 kb/s, 30 fps, 30 tbr, 15360 tbn, 15360 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 54 kb/s
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baee72440] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 5 times
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baeeec180] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baee72440] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 14 times
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baee72440] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 20 times
[mov,mp4,m4a,3gp,3g2,mj2 # 0000024baee72440] Auto-inserting h264_mp4toannexb bitstream filter
Last message repeated 7 times
frame= 52 fps= 42 q=-1.0 Lsize= 7838kB time=00:07:38.82 bitrate= 139.9kbits/s speed= 374x
video:4802kB audio:2956kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.044608%
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200523
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:07:38.85, start: 0.000000, bitrate: 139 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 87 kb/s, 0.12 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 52 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mp3, from 'C:\Users\shooey\Desktop\junky\Content\assets\background.mp3':
Metadata:
major_brand : dash
Software : Lavf57.56.101
minor_version : 0
compatible_brands: iso6mp41
Duration: 00:20:03.02, start: 0.025057, bitrate: 167 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 167 kb/s
Metadata:
encoder : LAME3.100
File 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\output_bckg.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 (aac) -> aformat
Stream #1:0 (mp3float) -> aformat
Stream #0:0 -> #0:0 (copy)
amerge -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[Parsed_amerge_4 # 0000017093965c80] No channel layout for input 1
[Parsed_amerge_4 # 0000017093965c80] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, mp4, to 'C:\Users\shooey\Desktop\junky\Content\07-04-2021\output_bckg.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 87 kb/s, 0.12 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.54.100 aac
frame= 52 fps=5.5 q=-1.0 Lsize= 11993kB time=00:07:31.67 bitrate= 217.5kbits/s speed= 48x
video:4802kB audio:7111kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.670061%
[aac # 00000170935b4980] Qavg: 319.394
I think I found the answer by myself. I took the background.mp3 which I wanted to add and made it into a .aac audio file. After that I used the same command for adding audio but instead of -shortest I used -t 00:07:38 because it was the length of the video and I found that FFmpeg has a hard time recognizing the boundaries in videos.

MP4Box / FFMPEG concat loses audio after first clip

So I am certainly no expert when it comes to either of these tools, but I have a web-based project that's executing commands on an Amazon Linux server to concatenate two video files that are uploaded.
Both files are converted to mp4s first using FFMPEG, and those play perfectly in a browser after conversion:
ffmpeg -i file1.mpg -c:v libx264 -crf 22 -c:a aac -strict -2 -movflags faststart file2.mp4
Then, I attempt to combine these two resulting mp4s into a single mp4. I tried using FFMPEG to do this but to no avail. Switching to try MP4Box got me much closer: the videos are concatenated together, but the audio stops playing at the end of the first clip, and the second clip is silent.
MP4Box -force-cat -keepsys -add file.mp4 -cat file2.mp4 out.mp4
I've tried varying versions of the above command with no better results. Any input is greatly appreciated.
EDIT: info on .mp4 files using
ffmpeg -i file1.mp4 -i file2.mp4
ffmpeg -i 1510189259715DogRunsintoGlassDoor_315a03a8e20acfc.mp4 -i
1510189273549NewhouseMoonMoonneverseenstairsbeforefunnydog_285a03a8e6aab25.mp4
ffmpeg version N-61041-g52a2138 Copyright (c) 2000-2014 the FFmpeg
developers
built on Mar 2 2014 05:45:04 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/64bit
--extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from
'1510189259715DogRunsintoGlassDoor_315a03a8e20acfc.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.33.100
Duration: 00:00:04.92, start: 0.023220, bitrate: 634 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
360x360 [SAR 1:1 DAR 1:1], 501 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc
(default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono,
fltp, 132 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from
'1510189273549NewhouseMoonMoonneverseenstairsbeforefunnydog_285a03a8e6aab25.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.33.100
Duration: 00:00:18.79, start: 0.023220, bitrate: 455 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p,
362x360 [SAR 1:1 DAR 181:180], 320 kb/s, 29.94 fps, 29.94 tbr, 11976
tbn, 59.88 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo,
fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
At least one output file must be specified

FFMPEG - Merge mp4 files and audio file

I have an ffmpeg that merges 3 mp4 videos and then another command that adds audio to the output file from the first command. The commands are as follows:
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -filter_complex "[0:v][1:v][2:v]concat=n=3:v=1" -preset ultrafast -crf 1 output.mp4
ffmpeg -i output.mp4 -i audio.mp3 -preset ultrafast -crf 1 final.mp4
vid-1.mp4 (does NOT have audio stream)
vid-2.mp4 (does NOT have audio stream)
Is there anyway to do this in one command? I would like to also add the audio to the video that is getting created in the first command. Is this possible?
Console output of "ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3"
[jstevens#jr testing]$ ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.1.1 (GCC) 20160510 (Red Hat 6.1.1-2)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
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
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 1085 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1081 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 1018 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1014 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 823 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 819 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
[mp3 # 0x1ca30c0] Skipping 0 bytes of junk at 0.
[mp3 # 0x1ca30c0] Estimating duration from bitrate, this may be inaccurate
Input #3, mp3, from 'audio.mp3':
Duration: 00:00:19.57, start: 0.000000, bitrate: 64 kb/s
Stream #3:0: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
At least one output file must be specified
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3 \
-filter_complex "[0:v][1:v][2:v]concat=n=3:v=1:a=0[v]" \
-map "[v]" -map 3:a -shortest output.mp4
I recommend to manually define mappings with -map instead of relying on the default stream selection behavior.
The -shortest option is added because the concatenated video duration is shorter than the audio duration.

ffmpeg : Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

I'm experiencing troubles running ffmpeg on my synology. I'm trying to convert .avi video to mp4.
Here is the command :
ffmpeg -i vid20160623.avi -acodec libfaac -b:a 128k -vcodec mpeg4 -b:v 1200k -flags +aic+mv4 -f mp4 vid20160623.mp4
And the logs :
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.3 (crosstool-NG 1.20.0) 20150311 (prerelease)
configuration: --prefix=/usr --incdir='${prefix}/include/ffmpeg' --arch=arm --target-os=linux --cross-prefix=/usr/local/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- --enable-cross-compile --enable-optimizations --enable-pic --enable-gpl --enable-shared --disable-static --enable-version3 --enable-nonfree --enable-libfaac --enable-encoders --enable-pthreads --disable-bzlib --disable-protocol=rtp --disable-muxer=image2 --disable-muxer=image2pipe --disable-swscale-alpha --disable-ffserver --disable-ffplay --disable-devices --disable-bzlib --disable-altivec --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --disable-vaapi --disable-decoder=amrnb --disable-encoder=zmbv --disable-encoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=eac3 --disable-decoder=dca --disable-decoder=eac3 --disable-decoder=truehd --cc=/usr/local/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ccache-gcc
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, avi, from 'vid20160623.avi':
Metadata:
encoder : MEncoder git-ab94fc6-4.4.3
Duration: 00:20:18.07, start: 0.000000, bitrate: 1197 kb/s
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 624x352 [SAR 1:1 DAR 39:22], 1056 kb/s, 25 fps, 23.98 tbr, 25 tbn, 23.98 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 128 kb/s
Output #0, mp4, to vid20160623.mp4':
Metadata:
encoder : MEncoder git-ab94fc6-4.4.3
Stream #0:0: Video: mpeg4, none, q=2-31, 128 kb/s, SAR 351:352 DAR 0:0, 23.98 fps
Metadata:
encoder : Lavc56.41.100 mpeg4
Stream #0:1: Audio: aac, 0 channels, 128 kb/s
Metadata:
encoder : Lavc56.41.100 libfaac
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (mp3 (native) -> aac (libfaac))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I tried to reduce b:a and b:v but it did not work.
Any help will be welcome.
Looks like the encoder is not recognizing the resolution of the output stream. Also, the codec frame rate is different than the actual frame rate. Try,
ffmpeg -i vid20160623.avi -acodec libfaac -b:a 128k -vf "scale=624:352,setsar=1" -vcodec mpeg4 -r 25 -b:v 1200k -flags +aic+mv4 -f mp4 vid20160623.mp4
Maybe a late answer but as I looked for a while for the same reason...
The issue is not in your command line but in FFmpeg version itself!
You asked for 1200k bit rate but we can see in output->Stream 0:0, it would try 128kb/s!
I have just used same command line with FFMpeg 2.8.11 and it works like a charm!

ffmpeg 1 image (JPG) + 1 audio file (MP3) = 1 video (WEBM) using real encode (-re)

I'd like to make video streaming to distribute it in a streaming.
The mp3 file is being extracted from a video file (which is being recorded live) and, while audio being extracted (MP3), I want to take this audio file and a image it and spread it in a real time streaming. But -re is not working for this.
To extract audio file i use:
ffmpeg.exe -re -i file(LIVE).AVI -vn -ar 22050 -ab 16k -r 1 -ac 1 -f mp3 C:\Users\" & wshNetwork.Username & "\Documents\audio.mp3"
This work very well to make the MP3 file. Using -re.
After that, I'm using this command to marge the auvio file with the jpg image:
ffmpeg.exe -loop 1 -f image2 -i c:\picture.jpg -re -i c:\Users\" & wshNetwork.Username & "\Documents\audio.mp3 -vb 10k -ar 22050 -ab 16k -ac 1 -r 1 -bufsize 300k -f webm www.adress.com
This second command is not working because the -re is not working, and produce a video with the picture and a choppy audio.
the output is:
ffmpeg version N-63113-g72dcd48 Copyright (c) 2000-2014 the FFmpeg developers
built on May 12 2014 22:10:08 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable
-decklink --enable-zlib
libavutil 52. 83.100 / 52. 83.100
libavcodec 55. 61.100 / 55. 61.100
libavformat 55. 37.102 / 55. 37.102
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 5.100 / 4. 5.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, image2, from 'c:\imagens\radiobb.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc), 553x342 [SAR 96:96 DAR 553:342], 25
fps, 25 tbr, 25 tbn, 25 tbc
[mp3 # 0000000002b8f660] Estimating duration from bitrate, this may be inaccurat
e
Input #1, mp3, from 'C:\Users\f3548956\Documents\audio.mp3':
Metadata:
encoder : Lavf55.37.102
Duration: 00:00:09.34, start: 0.050113, bitrate: 16 kb/s
Stream #1:0: Audio: mp3, 22050 Hz, mono, s16p, 16 kb/s
[swscaler # 0000000002ae1640] deprecated pixel format used, make sure you did se
t range correctly
[libvpx # 0000000002a8da40] v1.3.0
Output #0, webm, to 'http://172.17.146.***:8080/publish/tvbb100?password=****'
:
Metadata:
encoder : Lavf55.37.102
Stream #0:0: Video: vp8 (libvpx), yuv420p, 553x342 [SAR 1:1 DAR 553:342], q=
-1--1, 10 kb/s, 1k tbn, 25 tbc
Stream #0:1: Audio: vorbis (libvorbis), 22050 Hz, mono, fltp, 16 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> libvpx)
Stream #1:0 -> #0:1 (mp3 -> libvorbis)
Press [q] to stop, [?] for help
frame= 33 fps=0.0 q=0.0 size= 4kB time=00:00:01.32 bitrate= 23.3kbits/s
frame= 67 fps= 66 q=0.0 size= 4kB time=00:00:02.68 bitrate= 11.5kbits/s
frame= 101 fps= 66 q=0.0 size= 11kB time=00:00:04.04 bitrate= 22.4kbits/s
frame= 133 fps= 66 q=0.0 size= 11kB time=00:00:05.32 bitrate= 17.0kbits/s
Can anybody help me?

Resources