Running ffmpeg on AWS Lambda

Hi all

This is my first post here and I’m amped.

I’ve been building a function on lambda that runs as follows.

An.ts video file is created by Medialive. I have a trigger that is fired when a new .ts file is created.

The lambda function then copies the video.ts file to the /tmp dir. I then use ffmpeg that us accessed via a layer to transcode the file to a h264 mp4 file. Once the transcode is complete the python fuction copies the newly created .mp4 back to s3.

My problem is with the transcode. When I test the files locally in my Mac with a brew installed ffmpeg it works fine without problems. On lambda it’s full of errors. The .mp4 file it copies back to s3 is short and blocky with a few errors.

I’m not sure what the problem is or where to start trying to solve it.

Any help would be most appreciated.

These are some of the ffmpeg errors -

File Size in MegaBytes is 16.275657653808594

built with gcc 8 (Debian 8.3.0-6)

configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --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-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg

libavutil 56. 55.100 / 56. 55.100

libavcodec 58. 92.100 / 58. 92.100

libavformat 58. 46.101 / 58. 46.101

libavdevice 58. 11.100 / 58. 11.100

libavfilter 7. 86.100 / 7. 86.100

libswscale 5. 8.100 / 5. 8.100

libswresample 3. 8.100 / 3. 8.100

libpostproc 55. 8.100 / 55. 8.100

Input #0, mpegts, from ‘/tmp/vw0630_00001.ts’:

Duration: 00:00:23.58, start: 1.441667, bitrate: 5789 kb/s

Program 1

Metadata:

service_name : Service01

service_provider: FFmpeg

Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709/bt709/unknown, progressive), 720x576 [SAR 118:81 DAR 295:162], 24 fps, 24 tbr, 90k tbn, 180k tbc

Stream #0:10x101: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 322 kb/s

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))

Stream #0:1 -> #0:1 (aac (native) -> aac (native))

Press [q] to stop, [?] for help

[libx264 @ 0x7571c40] using SAR=118/81

[libx264 @ 0x7571c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

[libx264 @ 0x7571c40] profile High, level 3.0, 4:2:0, 8-bit

[libx264 @ 0x7571c40] 264 - core 160 r3009 4c9b076 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 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=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=500 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to ‘/tmp/vw0630_00001.mp4’:

Metadata:

encoder : Lavf58.46.101

Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 720x576 [SAR 118:81 DAR 295:162], q=-1–1, 24 fps, 12288 tbn, 24 tbc

Metadata:

encoder : Lavc58.92.100 libx264

Side data:

cpb: bitrate max/min/avg: 500000/0/0 buffer size: 500000 vbv_delay: N/A

Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s

Metadata:

encoder : Lavc58.92.100 aac

[mpegts @ 0x75316c0] Packet corrupt (stream = 0, dts = 227250).

[h264 @ 0x759c400] mb_type 40 in P slice too large at 13 6

[h264 @ 0x759c400] error while decoding MB 13 6

[h264 @ 0x759c400] concealing 1386 DC, 1386 AC, 1386 MV errors in P frame

/tmp/vw0630_00001.ts: corrupt decoded frame in stream 0

debug=1

cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)

[h264 @ 0x793e240] nal_unit_type: 9(AUD), nal_ref_idc: 0

[h264 @ 0x793e240] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1

cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)

[mpegts @ 0x75316c0] Continuity check failed for pid 256 expected 4 got 5

cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)

Last message repeated 2 times

[mpegts @ 0x75316c0] Packet corrupt (stream = 0, dts = 317250).

[h264 @ 0x7967b80] nal_unit_type: 9(AUD), nal_ref_idc: 0

[h264 @ 0x7967b80] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0

[libx264 @ 0x7571c40] frame= 0 QP=24.64 NAL=3 Slice:I Poc:0 I:1620 P:0 SKIP:0 size=25554 bytes

[h264 @ 0x759c400] nal_unit_type: 9(AUD), nal_ref_idc: 0

[h264 @ 0x759c400] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 1

1 Like

Hey there! Where is the Python function being hosted? Are you using a node implementation of ffmpeg?

Hi there, it’s been hosted on s3 and added as a layer to my lambda function. It’s was build for Linux systems, specifically for lambda.

The python itself is part of the lambda function, I’ve set it to use 3.6

https://www.johnvansickle.com/ffmpeg/

How are you using that with 8base?