简体   繁体   中英

How to extract an audio part from a mp4 using ffmpeg?

I tried to use the following command :

ffmpeg -i video.mp4 -acodec copy -ss 00:30:00 -to 00:60:00 extract.mp3

but it fails and says

[mp3 @ 0x3bfade0] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

I believe it's because I need to extract the mp3 data first and provide it to the command, but is not there a way to do this in one command and avoid creating the full mp3 file that I don't need ?

Your audio track is likely AAC, not MP3.

So either

ffmpeg -i video.mp4 -acodec copy -ss 00:30:00 -to 00:60:00 extract.aac

or

ffmpeg -i video.mp4 -vn -ss 00:30:00 -to 00:60:00 extract.mp3

Save it to a generic MP4 if you need a failsafe command.

ffmpeg -i video.mp4 -map 0:a:0 -acodec copy -ss 00:30:00 -to 00:60:00 extract.mp4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM