This configuration creates a minimal, optimized FFmpeg binary specifically tailored for audio processing in AWS Lambda environments. The build is focused on producing a small binary size (around 3.6MB) while maintaining essential audio processing capabilities.
-
Build the Binary
- Go to the "Actions" tab in your repository
- Select "ffmpeg-arm64" workflow
- Click "Run workflow"
- Download the artifacts from the completed run
-
Use the Binary
- Extract the downloaded artifacts
- Include the FFmpeg binary in your project
- Follow the configuration-specific instructions below
- Base Image: Built on Amazon Linux 2023 for deploying to AWS Lambda (
al2023-arm64andal2023-x86_64) - Minimal Size: Optimized to be as small as possible while maintaining essential functionality
- Audio-Focused: Configured primarily for audio processing tasks
- Lambda-Optimized: Built specifically for AWS Lambda's environment and constraints
- libfdk_aac: High-quality AAC audio encoder/decoder
- libmp3lame: MP3 audio encoder/decoder
- libopus: Opus audio codec for excellent compression
aresample: Audio resamplingatempo: Audio tempo/speed adjustmentformat: Format conversionsilencedetect: Silence detection in audio streamsvolume: Volume adjustment
- MP3
- AAC
- WAV
- libmp3lame (MP3)
- libfdk_aac (AAC)
- aac (native AAC)
- file (local file access only)
- AAC
- MP3
- MOV
- MP4
- Matroska
- WAV
- AAC
- MP3
- Opus
- FLAC
- PCM formats
- Vorbis
- WavPack
- aac_adtstoasc: AAC ADTS to ASC conversion
- extract_extradata: Extract extradata from stream
To minimize binary size, the following components are disabled:
- Debug information
- Documentation
- FFplay
- Network protocols
- Hardware acceleration
- Most filters
- Most muxers/demuxers
- Most encoders/decoders
- Input/output devices
This FFmpeg build is ideal for AWS Lambda functions that need to:
- Convert between audio formats (MP3, AAC, WAV)
- Adjust audio volume or speed
- Detect silence in audio files
- Extract audio from video files
- Process basic audio transformations
Here's an example of how to use the FFmpeg binary in a Python Lambda function to extract and convert audio:
import subprocess
import logging
import os
def extract_audio_segment(input_file: str, output_file: str, start_time: float, end_time: float) -> bool:
"""
Extract an audio segment from a media file and convert it to MP3.
Args:
input_file: Path to the input media file
output_file: Path where the output MP3 will be saved
start_time: Start time in seconds (e.g., 10.5)
end_time: End time in seconds (e.g., 30.0)
Returns:
bool: True if successful, False otherwise
"""
ffmpeg_path = '/opt/ffmpeg' # Path in AWS Lambda
try:
cmd = [
ffmpeg_path,
'-i', input_file,
'-ss', f'{start_time:.3f}',
'-to', f'{end_time:.3f}',
'-map', '0:a', # Only select audio streams
'-vn', # No video processing
'-c:a', 'libmp3lame',
'-b:a', '192k',
'-y', # Overwrite output file if exists
output_file
]
logging.info(f"Executing FFmpeg command: {' '.join(cmd)}")
subprocess.run(cmd, check=True, capture_output=True, text=True)
return True
except subprocess.CalledProcessError as e:
logging.error(f"FFmpeg error: {e.stderr}")
return False
except Exception as e:
logging.error(f"Unexpected error: {str(e)}")
return False
# Example usage in a Lambda handler
def lambda_handler(event, context):
try:
# Example: Extract 20 seconds of audio starting at 10 seconds
success = extract_audio_segment(
input_file='/tmp/input.mp4',
output_file='/tmp/output.mp3',
start_time=10.0,
end_time=30.0
)
if success:
return {
'statusCode': 200,
'body': 'Audio extraction successful'
}
else:
return {
'statusCode': 500,
'body': 'Audio extraction failed'
}
except Exception as e:
return {
'statusCode': 500,
'body': f'Error: {str(e)}'
}This example demonstrates:
- Extracting a specific time segment from a media file
- Converting to MP3 format with high-quality settings
- Proper error handling and logging
- Integration with AWS Lambda
- Using the binary from the correct Lambda path
This build includes components under GPL and other licenses. The FDK-AAC codec is covered by a non-free license. Please review the FFmpeg License for details about licensing requirements if you distribute this binary.