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 ?
First, the -i flag specifies the input video file name. Second, using -map 0:a selects all audio streams we found before. Next, -acodec copy copies the stream without re-encoding. Finally, audio.
-map 0 tells ffmpeg to all streams from input 0 (the first input) in the output file. -c:a copy -c:s copy will copy over any audio and subtitle streams present.
You can of course select any ffmpeg parameters for audio encoding that you like, to set things like bitrate and so on. Use -acodec libmp3lame and change the extension from . ogg to . mp3 for mp3 encoding.
You can use FFmpeg to concatenate mp4 files very easily! There are many ways to do this including variations such as (1) concatenating only the audio (2) concatenating only video (3) concatenating all the files in a directory (4) concatenating files that do not have the same height, width, etc.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With