8 ms·
Perhaps it's time to start a collection of ffmpeg commands for every situation, similar to bro pages [1]. I feel like I have to look at my old projects every ti
by nicbou 6y ago
Perhaps it's time to start a collection of ffmpeg commands for every situation, similar to bro pages [1]. I feel like I have to look at my old projects every time I need to use it. It took me a lot of trial and error to write an all-purpose ffmpeg command.
This is how I convert videos to 720p web-playable videos (if it's not already web-playable):
https://github.com/nicbou/homeserver/blob/22c0a160f9df5f4c34cc7a0dc322d5461a73a28b/videoprocessing/src/jobs.py#L97 https://github.com/nicbou/homeserver/blob/22c0a160f9df5f4c34...
This is how I create hover previews like on modern streaming sites:
https://github.com/nicbou/timeline/blob/9d9340930ed0213dffdd884bef17f65c73e86ffc/backend/source/timeline/file_utils.py#L31 https://github.com/nicbou/timeline/blob/9d9340930ed0213dffdd...
[1] http://bropages.org/tar http://bropages.org/tar
- panabee 6y agothis is a wonderful idea. we launched a repo here to do exactly this; we'll update the repo over time as we collect commands. https://github.com/HotpotDesign/FFMpeg-Online https://github.com/HotpotDesign/FFMpeg-Online could we list and credit your commands?
- nicbou 6y agoSure, they're open source for a reason! The videoprocessing one is more mature. It's been converting various torrents movies to playable mp4s for a few years. The 10x1s preview looks magical once you see it in production. It's also a great introduction to ffmpeg filter syntax, which really isn't that complex.
- panabee 6y agothanks! i just wanted to confirm your permission before posting on the repo. :) on a related note, do you have a command for converting HTML5 animations into webp or mp4 videos?
- fireattack 6y agoI just noticed you have one for "Create single-image video with audio". This seemingly easy task is actually pretty hard to get right with FFMPEG. Just leave a few notes here if anyone want to use that. Video part Chroma sampling Without any `pix_fmt` argument, FFMPEG defaults to 4:4:4 instead of typical 4:2:0. Which has very limited support (for example, Firefox doesn't support it.) To fix: add `pix_fmt yuv420p`, or chain a `format=yuv420p` vf at the end to your other vf(s). Color space FFMPEG by default uses BT.601 when converting your RGB images into YUV. This is an issue if your image / output video is in HD resolution. Almost all video players (including browsers) would assume BT.709 for anything >=720P. This causes color to shift in playback(255,0,0 would become 255,24,0). To fix: add `-vf zscale=matrix=709`. Note: there are some other video filters can do the same. The most famous being good ol' `scale` (based on libswscale). However, it has a notorious bug that would cause the color to shift on its own (becomes yellow) if the input is in BGR (all the `.bmp`s). See: https://trac.ffmpeg.org/ticket/979 https://trac.ffmpeg.org/ticket/979 So stick with better `zscale`. Framerate etc. You can set framerate with `-r` to a small number for both input (reading the same image X times per second) and output (since it's a still image, you can get away with very low framerate. `-tune stillimage` should also be used for (default) x264 encoder. In summary: ffmpeg -loop 1 -r 1 -i image.png -i audio.wav -r 1 -shortest -vf zscale=matrix=709,format=yuv420p -c:v libx264 -tune stillimage output_video.mp4 Audio part - length mismatch bug Even if we ignore all the image/video troubles above, `ffmpeg -loop 1 -i image.png -i sound.mp3 -shortest video.mp4` still doesn't work well. "-shortest" argument has a long-standing bug (https://trac.ffmpeg.org/ticket/5456 https://trac.ffmpeg.org/ticket/5456) that is the output video would be longer than your input audio (by quite a few seconds, worse if using -r 1). There are some workarounds (listed in the ticket) but they don't eliminate the issue entirely. Your best bet (if the length match is crucial) is to just convert the output video again and use -t to cut to the proper length.
- dddw 6y agoI have one that is pretty usefull to me, which I use to convert MTS files from my Sony camera to mp4. # batch convert MTS files into mp4 files for f in .MTS; do avconv -i "$f" -deinterlace -vcodec libx264 -pass 1 "${f%.MTS}.mp4";done
- devadvance 6y agoThe hover previews is an awesome example. Thanks for sharing! I like collections of commands. However, the challenges that seem unsolved are (1) keeping the example in sync with the CLI options, and (2) making it easy to dig into parts of examples. The former is a classic documentation problem, of course.
- gitgud 6y agoThanks for sharing! I use a collection of commands in a dotfiles [1] repo I share around a few machines. This [2] command, compresses any video into a small web-playable file with relatively high quality so you can quickly share HD footage. ffcompress INPUT.mp4 # creates INPUT.compressed.mp4 [1] https://github.com/benwinding/dotfiles https://github.com/benwinding/dotfiles [2] https://github.com/benwinding/dotfiles/blob/master/bin/ffcompress https://github.com/benwinding/dotfiles/blob/master/bin/ffcom...
- neolog 6y agohttps://github.com/tldr-pages/tldr https://github.com/tldr-pages/tldr is a large collection
- _joel 6y agoThere's always commandlinefu.com - https://www.commandlinefu.com/commands/matching/ffmpeg/ZmZtcGVn/sort-by-votes https://www.commandlinefu.com/commands/matching/ffmpeg/ZmZtc...
- lozf 6y agoSomething like FFmprovisr: https://amiaopensource.github.io/ffmprovisr/ https://amiaopensource.github.io/ffmprovisr/ https://github.com/amiaopensource/ffmprovisr https://github.com/amiaopensource/ffmprovisr (CC Licensed, they accept pull requests.) --- The ffmpeg subreddit also has some helpful contributors: https://old.reddit.com/r/ffmpeg/ https://old.reddit.com/r/ffmpeg/
- aq3cn 6y agothere are many such syntax generator websites for simple video conversion like tasks. see: https://www.mrfdev.com/ffmpeg-command-generator https://www.mrfdev.com/ffmpeg-command-generator http://www.mackinger.at/ffmpeg/ http://www.mackinger.at/ffmpeg/ https://marceauka.github.io/ffmpeg-generator/# https://marceauka.github.io/ffmpeg-generator/#