乐闻世界logo
搜索文章和话题

How can I extract audio from video with ffmpeg?

1个答案

1

When using ffmpeg to extract audio from video files, first ensure that ffmpeg is installed. Installation instructions can be found on the official website FFmpeg. After installation, you can use command-line tools to perform the extraction.

Step 1: Open the Command-Line Tool

Open your command-line tool, such as CMD or PowerShell on Windows, or Terminal on Mac or Linux.

Use the cd command to navigate to the directory containing the video file. For example:

bash
cd C:\Users\YourUsername\Videos

Step 3: Execute the FFmpeg Command to Extract Audio

Use the following command format to extract audio:

bash
ffmpeg -i input_video.mp4 -vn -acodec copy output_audio.aac

Here is the parameter explanation:

  • -i input_video.mp4: Specifies the input file, e.g., input_video.mp4.
  • -vn: This option instructs FFmpeg to ignore video data.
  • -acodec copy: Indicates that audio encoding uses copy mode, directly copying the original audio without transcoding.

Example

Suppose you have a video file named example.mp4 and you want to extract the audio and save it as example.aac. The command is:

bash
ffmpeg -i example.mp4 -vn -acodec copy example.aac

Result

This command generates an audio file named example.aac in the same directory, containing the original audio data from example.mp4.

Notes

  • Ensure the output file format supports the audio encoding. For instance, if the original video uses AAC-encoded audio, choose a format like .aac or another container format compatible with AAC.
  • If you need to convert the audio encoding (e.g., from MP3 to AAC), adjust the -acodec parameter to specify a different encoder.

This method is straightforward and highly useful for quickly extracting audio from videos when required.

2024年8月9日 01:43 回复

你的答案