Both sides previous revisionPrevious revisionNext revision | Previous revision |
ffmpeg [2022/03/11 13:06] – Images section rjt | ffmpeg [2025/04/14 16:40] (current) – more info on 'copy' ... mb don't need to bang on so much ... rjt |
---|
Most of the time I just use--- | Most of the time I just use--- |
| |
<code>ffmpeg -i input.ext output.ext</code> | <code>ffmpeg -i [input.ext] [output.ext]</code> |
| |
---and it usually works fine leaving it to just use defaults. | ---and it usually works fine leaving it to just use defaults. |
This gives good results (and a smaller file size) converting MP3 to OGG though: | This gives good results (and a smaller file size) converting MP3 to OGG though: |
| |
<code>ffmpeg -i input.mp3 -c:a libvorbis -q:a 4 output.ogg</code> | <code>ffmpeg -i [input].mp3 -c:a libvorbis -q:a 4 [output].ogg</code> |
| |
| Fuck-off those .WEBMs. ''copy'' here copies those streams, so they're no reencoded, it's just changing the container: |
| |
| <code>ffmpeg -i [input].webm -acodec copy -vcodec copy [output].mkv</code> |
| |
| A more compact way is to use ''-c'', which will copy over all streams (there's also ''-c:a'' (audio) ''-c:v'' (video) ''-c:s'' (subtitles)…: |
| |
| <code>ffmpeg -i [input].webm -c copy [output].mkv</code> |
| |
| So if you wanted to copy the video stream and just reencode/change the audio, for example: |
| |
| <code>ffmpeg -i [input].[ext] -acodec aac -vcodec copy [output].[ext]</code> |
| |
=== Multiple === | === Multiple === |
For doing a whole directory I use this one-liner I got from Stack Exchange. | For doing a whole directory I use this one-liner I got from Stack Exchange. |
| |
<code>for i in *.ext; do ffmpeg -i "$i" "${i%.*}.ext"; done</code> | <code>for i in *.[ext]; do ffmpeg -i "$i" "${i%.*}.[ext]"; done</code> |
| |
For converting files for my [[m-u-s-u-c]] blog I also strip out the cover images: ''-map a'' tells it to take only the audio stream. | For converting files for my [[m-u-s-u-c]] blog I also strip out the cover images: ''-map a'' tells it to take only the audio stream. |
<code>for i in *.mp3; do ffmpeg -i "$i" -c:a libvorbis -q:a 4 -map a "${i%.*}.ogg"; done</code> | <code>for i in *.mp3; do ffmpeg -i "$i" -c:a libvorbis -q:a 4 -map a "${i%.*}.ogg"; done</code> |
| |
You can use the wildcard ''*'' in the file extension to, so if you've got a mix of .mkv and .mp4 files from Youtube you can do. say: | You can use the wildcard ''*'' in the file extension too, so if you've got a mix of .mkv and .mp4 files from Youtube you can do. say: |
| |
<code>for i in *.m*; do ffmpeg -i "$i" "${i%.*}.ogv"; done</code> | <code>for i in *.m*; do ffmpeg -i "$i" "${i%.*}.ogv"; done</code> |
If you want to put the new videos into a subdirectory, first create it, then simply add it to the output part: | If you want to put the new videos into a subdirectory, first create it, then simply add it to the output part: |
| |
<code>for i in *.ext; do ffmpeg -i "$i" "directory/${i%.*}.ext"; done</code> | <code>for i in *.[ext]; do ffmpeg -i "$i" "directory/${i%.*}.[ext]"; done</code> |
| |
For converting a directory of .FLAC files to .MP3. ''[-qscale:a 0|-b:a 320k]'' is your choice between VBR with the best quality (0) or a CBR of 320k. VBR is generally just as good, though sometimes you need CBR. | For converting a directory of .FLAC files to .MP3. ''[-q:a 0|-b:a 320k]'' is your choice between VBR with the best quality (0) or a CBR of 320k. VBR is generally just as good, though sometimes you need CBR. |
| |
<code>for a in ./*.flac; do ffmpeg -i "$a" [-qscale:a 0|-b:a 320k] "${a[@]/%flac/mp3}"; done</code> | <code>for i in *.flac; do ffmpeg -i "$i" [-q:a 0|-b:a 320k] "${i%*}.mp3"; done</code> |
| |
==== Editing ==== | ==== Editing ==== |
| |
<code>-filter:v "crop=ih/3*4:ih"</code> | <code>-filter:v "crop=ih/3*4:ih"</code> |
| |
| Full example, with copied audio stream: |
| |
| <code>ffmpeg -i [file] -filter:v "crop=ih/3*4:ih" -c:a copy [file]</code> |
| |
=== Remove Audio === | === Remove Audio === |
<code>cat *.png | ffmpeg -framerate [framerate] -f image2pipe -i - [file]</code> | <code>cat *.png | ffmpeg -framerate [framerate] -f image2pipe -i - [file]</code> |
| |
| == GIF == |
| Default loops. Add ''-loop -1'' to only play once. |
| |
| <code>cat *.png | ffmpeg -framerate [framerate] -f image2pipe -i - [filename].gif</code> |
| |
| == APNG == |
| Default doesn't loop. Add ''-plays 0'' to loop. |
| |
| <code>cat *.png | ffmpeg -framerate [framerate] -f image2pipe -i - -f apng [filename].png</code> |
==== Lowering the file size ==== | ==== Lowering the file size ==== |
Slow, but compresses better: | Slow, but compresses better: |
Just had an .AVI file throwing error messages about a busted index. Copying the file seemed to fix it. | Just had an .AVI file throwing error messages about a busted index. Copying the file seemed to fix it. |
<code>ffmpeg -i "inputfile.avi" -c:v copy -c:a copy "outputfile.avi"</code> | <code>ffmpeg -i "inputfile.avi" -c:v copy -c:a copy "outputfile.avi"</code> |
| |
| ===== Frontends ===== |
| |
| * [[https://ffmpeg.lav.io/|FFmpeg Explorer]] - Browser-based GUI with a node-based interface for changing parameters. |
| |
===== See Also ===== | ===== See Also ===== |