brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -vn -c:a copy pulls the audio out of a video as it is

Ffmpeg
~/tips/tip-ffmpeg-vn-extract-audio

ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a

Saves the sound of a video file as a separate audio file without re-encoding it.

A recorded talk or a concert clip often works fine as audio only. I don’t want to re-encode it, because that costs quality and time for nothing.

ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a

-vn leaves the video out and -c:a copy copies the audio stream exactly as it is stored. So you get the original quality and it’s done in seconds.

The extension matters here. With copy, the audio keeps its codec, so the container has to support it. Most MP4 files carry AAC, which fits in .m4a. Opus from a WebM file belongs in .opus or .ogg, and AC-3 from a film can go in .mka. If you’re not sure what’s inside, ask first:

ffprobe -v error -select_streams a -show_entries stream=codec_name -of csv=p=0 talk.mp4

When you really want an MP3, for an old car stereo for example, you have to re-encode, and then copy is out: -vn -c:a libmp3lame -q:a 2 talk.mp3 gives a good variable bitrate. And with several audio tracks, ffmpeg picks one by itself, so add -map 0:a:1 to choose the second one.

Further reading: ffmpeg documentation, ffprobe documentation

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -n -i "$f" -c copy "${f%.mkv}.mp4" All Ffmpeg tips (38) All topics

Link