FFMPEG is an [[LGPLv2.1]] licensed media transcoder and manipulation tool written in [[3. Reference/Software/Programming Languages/C|C]]. - [Website](https://ffmpeg.org/) - [Source](https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/README.md) - [Documentation](https://ffmpeg.org/documentation.html) - [AlternativeTo](https://alternativeto.net/software/ffmpeg/about/) > FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata. # Notability One of the most important media tools available today. # Philosophy # Platform Support # Features # Tips ## OCR & TTS - https://dev.to/video/exploring-ocr-and-text-to-speech-in-ffmpeg-2o61 ## Losslessly Change Container Use `copy` with the audio `-c:a` and `-c:v` codec options.[^3][^4][^6] ```sh ffmpeg -i video.mkv -c:v copy -c:a copy -map 0 -sn output.mp4 ``` ## Remove Audio Use the `-an` flag.[^2] ```sh ffmpeg -i video.mkv -c:v copy -an output.mp4 ``` ## Extract Audio to File AKA remove video by `copy`ing the audio `-acodec` and removing the video `-vn`.[^5] ```sh ffmpeg -i video.mkv -vn -acodec copy -map a output.aac ``` The `-map a` is needed to tell `ffmpeg` not to worry about subtitles or any other video streams that won't fit into the target container. ## Extract DTS Audio to File [[Solus]]'s build of `ffmpeg` doesn't include the DTS/ADTS muxer. To build it in: ```sh git clone https://git.ffmpeg.org/ffmpeg.git cd ffmpeg ./configure --enable-muxer=adts make ``` ## Extract Text Subtitles ```sh ffmpeg -i video.mkv -map 0:s:0 subs.srt ``` ## Extract Bitmap Subtitles ```sh ffmpeg -i video.mkv -map 0:s:0 -c:s:0 copy subs.sup ``` Then you should download [[SubtitleEdit]] and use it to OCR the bitmaps and save it as an [[Subtitles|SRT]] file which is a plain text file. ## Convert to WebM To preserve quality, do a two-pass conversion.[^1] The first pass we discard the video because we just need the metadata (`ffmpeg2pass-0.log`) and the second one uses that info to do the conversion. >[!WARNING] > This may take a *while* even for short videos! > > It very much depends on the input video codec and framerate but a 2:34 60fps screen recording from OBS Studio took 8:51 to complete! ```sh #!/bin/sh -xe ffmpeg -i "$1" -b:v 0 -crf 30 -pass 1 -an -f webm -y /dev/null ffmpeg -i "$1" -b:v 0 -crf 30 -pass 2 "${1%.mp4}.webm" ``` ## FFPLAY `ffplay` is a tool that comes with `ffmpeg` that provides the ability to play and process files, including filters, and generate different effects such as video color vectorscope and audio stereo vectorscopes, spectrograms, and more.[^7] ### Audio Vectorscope ```sh ffplay -f lavfi 'amovie=input.flac,asplit=2[out1][a],[a]avectorscope=m=polar:s=800x400[out0]' ``` # Resources ## GUIs - https://sites.google.com/site/dmsimpleapps ## Forks A group of `ffmpeg` developers split off in 2012 and formed `avconv` which shipped its own versions of `ffmpeg` with error messages and libraries that confused a lot of people. The `avconv` fork was discontinued in 2019 and is now defunct. # References ## LibAV - https://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv - http://blog.pkh.me/p/13-the-ffmpeg-libav-situation.html ## Footnotes [^1]: https://video.stackexchange.com/questions/19590/convert-mp4-to-webm-without-quality-loss-with-ffmpeg [^2]: https://superuser.com/questions/268985/remove-audio-from-video-file-with-ffmpeg [^3]: https://superuser.com/questions/472420/handbrake-settings-to-convert-mkv-to-mp4-while-retaining-the-original-quality [^4]: https://askubuntu.com/questions/50433/how-to-convert-mkv-file-into-mp4-file-losslessly [^5]: https://stackoverflow.com/questions/42542906/ffmpeg-what-muxer-do-i-need-to-save-an-aac-audio-stream [^6]: https://github.com/jspw/Little-Fun-Stuffs/tree/main/mkv%20to%20mp4%20converter [^7]: https://trac.ffmpeg.org/wiki/FancyFilteringExamples