Ffmpeg is a gigantic library with customizations that makes people like me happy. I'm a man of 'give me life customization' kind, so it's a treat for me.
I do the same when I build my own software and apps - most people don't even realize what I keep hidden in my apps, because layman don't need them or don't want to go into complexities of learning them. But for power users it's a blessing.
Ffmpeg is backbone of every video/audio/downloader tool out there. Every app that you see for YouTube download, Audio or Video manipulation online, be it web app, android app, iOS app or desktop app, it's all based on ffmpeg more or less.
Anyway, over the years I have accumulated quite a lot of ffmpeg commands that I use, and when I make something work/tweak perfectly according to my liking, it goes into number of note taking apps that I have (scattered everywhere).
This blog post is to keep a track of all those commands so that I can come back here and pick those instead of going through my stuff looking for 'that perfect command' again.
Mp4 to Mp3 (or any other format)
Simple and useful, one format to another.
ffmpeg -i input.mp4 -vn output.wav
The vn flag is optional - it's to say `video no` meaning drop the video. Of course you can convert video to another video format, or audio to another audio format or any permutation that you like.
Slow down the video/audio
I have experimented quite a lot of things, stretching the time and the pitch shift etc. What gives us exact speed control is knowing your source, which is usually 41 or 48 kHz.
Here's the command for an audio file that goes kaboom.
ffmpeg -i input.mp4 -vn -af "asetrate=24000,aresample=48000" output_slow.wav
Remove silences from audio
Adjust the 0.5 threshold if you want, but this is the standard that everyone uses.
ffmpeg -i master_audio.flac -af silenceremove=stop_periods=-1:stop_duration=0.5:stop_threshold=-40dB output_no_silence.flac
Less than this and people will feel suffocated.
Flac is considered a lossless quality format by the way. So if you want exact copy of audio from a video, use video to audio conversion and choose flac as the output format.
Remove Silences from Video with Audio
Run the following command:
auto-editor.exe "input.mp4" --edit audio:threshold=-35dB
This roughly means:
- Audio below -35 dB is considered silence
- The corresponding video frames are removed
- The corresponding audio is removed as well
- The remaining video and audio stay synchronized
-35dB may be too aggressive or too lenient depending on your
recording. You may need to adjust the threshold depending on how much
background noise is present and how quiet the speech gets.
YouTube video
You can get the whole video or a part of it. Example:
yt-dlp -f "(bestvideo+bestaudio/best)[protocol!*=dash]" --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss 815 -to 903" "https://youtu.be/gwjFSonRzno"
// or in general with ffmpeg, for a stream/localserver/downloadable video:
ffmpeg -ss 00:42:10 -i "http://127.0.0.1:<port>/<id>/0" -t 10 -c:v libx264 -crf 18 -c:a aac clip.mp4
meaning -ss 00:42:10 = seek to 42 minutes 10 seconds before reading the input; -i "http://127.0.0.1:<port>/.../0" = specifies the local streaming URL as the input; -t 10 = process only 10 seconds of video from the selected starting point; -c:v libx264 = encode the video using the H.264 codec; -crf 18 = set H.264 quality (lower = higher quality/larger file; 18 is very good visually); -c:a aac = encode the audio using AAC; clip.mp4 = output filename.
Will keep adding commands here. Until then, thanks for the visit.
Rab raakha.
No comments:
Post a Comment