FFmpeg includes command-line utilities for analyzing multimedia files and retrieving details about their streams. Finding the audio codec used by a media file can help with compatibility checks, media analysis, or preparing a file for further processing. This tutorial explains how to get audio codec of file using FFmpeg.
The ffprobe utility makes it possible to inspect a media file and display the codec assigned to its audio stream without decoding or re-encoding the content.
Download a sample file for testing:
curl -sSo test.mp4 https://raw.githubusercontent.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4
The audio codec can be obtained using the following command:
ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 test.mp4
The command returns:
aac
Command breakdown:
ffprobe- inspects multimedia files and provides information about their streams.-v error- limits the log output to errors, hiding informational messages. This keeps the command output clean and ensures that only relevant error messages are shown.-select_streams a:0- selects the first audio stream found in the input file.-show_entries stream=codec_name- tells to report the codec name associated with the selected stream.-of default=noprint_wrappers=1:nokey=1- formats the output without wrappers or the field name, leaving only the codec value.test.mp4- specifies the media file to analyze.
Leave a Comment
Cancel reply