Welcome

I. Introduction What is it? ffmpeg is a free, open source, cross platform application for converting and manipulating audio and video. It allows you to convert audio and video between different formats, stream, record, edit and apply filters. Where can I get it? Downloads can be found here and documentation can be found here. What does it have to do with /r/photoshopbattles, /r/cutouts and /r/battleshops? Still images created with photo manipulation software are the expectation for these subreddits. Furthermore, at this time links submitted (with the exception of comments) must be still images. There are several other subreddits specifically for gifs. There are however, times when a submission in the comment area of a battle may be enhanced with added motion depending on your creative vision for the battle. ffmpeg can be useful to create gifs from still images, get still frames from videos or gifs and apply filters. How do I use it? ffmpeg is an executable command line application, meaning it does not have a graphical user interface, although several projects based on ffmpeg, listed here do have graphical user interfaces (features vary). Instructions for opening command prompt on Windows operating systems can be found here. Instructions for opening command prompt on Apple operating systems can be found here. Basic usage is as follows: <path to ffmpeg application> -i <path to input video, audio or image with file name and extension> [other options] <path to output video, audio or image with file name and extension> We will get into [other options] later, for now we only need the application, input file and output file. Example command for converting video from avi to MPEG-4: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Userskorbendallas\Videos\Fifth Element.avi” “C:\Users_korbendallas\Desktop\Fifth Element.mp4” *nix: /usr/bin/ffmpeg -i /usr/media/video/FifthElement.avi /usr/media/video/FifthElement.mp4 Note: You may or may not need to use quotation marks depending on your operating system. The location you installed ffmpeg will vary. II Getting Still Frames From Videos Or Gifs Format Similar to the example given above, you’ll specify the path for ffmpeg and the input file path, name and extension. For the output, you will specify the path for the series of images that will be output. The still frame images will be named with your selected name followed by a series of numbers. Using image-%3d.png you will see files named image-001.png, image-002.png, image-003.png, etc. You can replace the number 3 with a number of your choosing and the name ‘image’ with a name of your choosing. Using pic-%5d.png you will see pic-00001.png, pic-00002.png, pic-00003.png, etc. Example: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Videos\Fifth Element.avi” “C:\Users_korbendallas\Desktop\stills\FE-%12d.png” *nix: /usr/bin/ffmpeg -i /usr/media/video/FifthElement.avi /usr/media/stills/FE-%12d.png .jpg is also a valid format instead of .png, for a full list, see the official ffmpeg documentation. Trimming Outputting a full length movie this way, will give you an extremely large quantity of images and take up a large amount of disk space. To limit the amount of images, you may want to specify start and stop timestamps. You can achieve this by using -ss option and/or -to option between the input and output file paths/names. -ss sets the starting point in a video and the -to option specifies the end point you wish to use. The time format is HH:MM:SS. HH being hours, MM being minutes and SS being the seconds. The following example will output still frames from a video beginning at 45 minutes and 23 seconds into the movie and ending at 46 minutes and 3 seconds into the movie: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Videos\Fifth Element.avi” -ss 00:45:23 -to 00:46:03 “C:\Users_korbendallas\Desktop\stills\FE-%12d.png” *nix: /usr/bin/ffmpeg -i /usr/media/video/FifthElement.avi -ss 00:45:23 -to 00:46:03 /usr/media/stills/FE-%12d.png Note: For outputting still frames from longer movie segments, you will need to use larger numbers because the frame output may end prematurely. %3d will only allow 999 images, etc. Also, be sure to specify an appropriate path for the images to output to, meaning you probably don’t want 6000 images to appear on your desktop. III Creating Gifs From A Video Or Series Of Images Creating a gif from video As with previous examples, you’ll specify the input and output files. Now you’ll be using .gif as the output file extension. When using a series of still images, make sure they are in the specified numbering format prior to use. Basic example for converting a video to gif: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Videos\Fifth Element.avi” “C:\Users_korbendallas\Desktop\Fifth Element.gif” *nix: /usr/bin/ffmpeg -i /usr/media/video/FifthElement.avi /usr/media/gifs/FifthElement.gif Creating a gif from a series of images Basic example for converting a series of images to gif: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Desktop\stills\FE-%5d.png” “C:\Users_korbendallas\Desktop\Fifth Element.gif” *nix: /usr/bin/ffmpeg -i /usr/media/stills/FE-%5d.png /usr/media/gifs/FifthElement.gif IV Advanced Uses High quality gifs To increase the quality of your gif, you may need to create and use a palette. A palette reduces the colors used in your gif to only those that are needed. This is accomplished in two steps. First, create the palette: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Desktop\stills\FE-%5d.png” -vf "palettegen" -y palette.png nix: /usr/bin/ffmpeg -i /usr/media/stills/FE-%5d.png -vf "palettegen" -y palette.png Next, create the gif using the palette: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Desktop\stills\FE-%5d.png” -i palette.png -lavfi "[0:v][1:v] paletteuse" “C:\Users_korbendallas\Desktop\Fifth Element.gif” *nix: /usr/bin/ffmpeg -i /usr/media/stills/FE-%5d.png -i palette.png -lavfi "[0:v][1:v] paletteuse" /usr/media/gifs/FifthElement.gif In the majority of cases, you will see a significant improvement in quality when using a palette. Transparent overlays Overlaying images with transparency can come in handy when using a cutout or series of cutouts. For this, you’ll specify two inputs (original video and cutout) as well as the x and y coordinates for the second image to be placed. The following example will overlay a transparency onto a video 40 pixels from the left and 20 pixels from the top: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Desktop\my_video.mp4” -i “C:\Users_korbendallas\Desktop\mycutout.png” -filter_complex "[0:v][1:v]overlay=shortest=0:x=40:y=20" “C:\Users_korbendallas\Desktop\output.mp4” *nix: /usr/bin/ffmpeg -i /usr/media/video/my_video.mp4 -i /usr/media/cutouts/my_cutout.png -filter_complex "[0:v][1:v]overlay=shortest=0:x=40:y=20" /usr/media/video/output.mp4 Adding motion In the previous example, the cutout was placed over the video at a specific place. ffmpeg also has the ability to specify motion of the overlay. The following example overlays an image at 40 pixels from the left and 20 pixels from the top and moves the cutout to the right at 200 pixels per second: Windows: “C:\Program Files\ffmpeg\bin\ffmpeg” -i “C:\Users_korbendallas\Desktop\my_video.mp4” -i “C:\Users_korbendallas\Desktop\mycutout.png” -filter_complex "[0:v][1:v]overlay=shortest=1:x=40+t200:y=20" “C:\Users_korbendallas\Desktop\output.mp4” nix: /usr/bin/ffmpeg -i /usr/media/video/my_video.mp4 -i /usr/media/cutouts/my_cutout.png -filter_complex "[0:v][1:v]overlay=shortest=1:x=40+t200:y=20" /usr/media/video/output.mp4 Holy crap! Math came in useful outside of school! Further uses Due to the large numbers of capabilities and combinations, this tutorial won’t be able to cover everything. Understanding how to use advanced filters can be learned by referring to ffmpeg documentation here and/or consulting /r/ffmpeg.

/r/korbendallas Thread