Contents
Introduction
This wiki-page tries to cover the basics for editing videos. You will learn how to download a video with youtube-dl, how to cut it with ffmpeg and how to add subtitles. For further instructions please go to the documentation page from ffmpeg. Any contribution to this wiki page is highly appreciated and please also keep in mind that I only tested this with my Linux System and it might not work well on other systems.
Download a Video
For this you can use youtube-dl. Youtube-dl is available in the most package-managers like: apt, dnf or pacman. To install youtube-dl, first search for the package and then install it in your package manager:
apt
$ apt-cache search youtube-dl $ apt install somethingWithYoutube-dl
After you have installed youtube-dl it is ready for use. You can download any video with the video link. For example: $ youtbe-dl -F linkToVideo #shows you the available formats.
A possible output could look like this:
[youtube] Wf9bvwPlzgs: Downloading webpage [youtube] Wf9bvwPlzgs: Downloading video info webpage [info] Available formats for Wf9bvwPlzgs: format code extension resolution note 249 webm audio only tiny 54k , opus @ 50k (48000Hz), 13.39MiB 250 webm audio only tiny 66k , opus @ 70k (48000Hz), 16.56MiB ... 22 mp4 1280x720 720p 820k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)
For choosing the best quality you can type: $ youtube-dl -f 22 linkToVideo
Now the download will start and the video will be saved to the current folder you are in. If you are unsure of which one this is type: $ pwd #This will tell you your current working directory
Editing videos
There are many programs for editing videos. You could for example use ffmpeg - ffmpeg video converter. It is packed with features, and in fact a lot of video editors actually use FFmpeg to do the actual video rendering. FFmpeg is a commandline utility, which lends itself for scripting, so you can automate the work and get consistent results. You can download this package following the same procedure as described with youtube-dl. ffmpeg is a very useful and mighty tool. To get a manpage with an overview of the functionality you can type:
$ man ffmpeg
or for a more simple help you can type the following command.
$ ffmpeg --help
For easier reading in a paginated fashion, pipe it to less:
$ ffmpeg --help | less
The displayed information can give you a short overview on what ffmpeg is able to do.
Also you can read the Online FFmpeg documentation which is covered with useful examples.
Note: It should be possible to combine the provided commands into a single command so you FFmpeg can do the process in a single conversion. Combing the conversions in a single command helps to retain quality and reduce conversion time. It might be harder to understand these long chained commands, so take the time to properly understand and document them.
Get video information
By simply calling FFmpeg with only an input file, it will provide you with more information on the video like duration, framerate, bitrate, codecs and individual streams. This information can be helpful to validate or debug conversions.
$ ffmpeg -i input.avi
Format a video
A typical conversion is to produce a different file type. On the website mostly the .mp4 and .webm formats are used, as most users will have at least support for one of those formats.
For a simple conversion just provide ffmpeg with the input file and output location and it will make some assumptions on codecs and quality and render the output:
$ ffmpeg -i input.avi output.mp4
Downscale to a lower resolution
You might have a video of full-HD (1080x1920) resolution that also needs to be offered in a lower resolution format. The FFmpeg scale filter allows you to do that. In the below example the video is downscaled to a height of 720 pixels (HD-ready resolution) and the width is automatically determined by providing -1 as the width value:
$ ffmpeg -i input.mp4 -vf scale=-1:720p output.mp4
Convert to a lower bitrate
Besides the lower resolution, it might be worthwile to reduce the bitrate which will save bandwidth at the cost of lower quality. Typically the lower bitrate is combined with a lower resolution to target mobile devices. A simple way to set the quality is using the 'Constant Rate Factor (crf)' property. A lower 'crf' will result in higher quality. As discussed on a StackExchange answer the value range depends on the codec. For MP4 a crf of 20 is a good starting point, and for Webm a value of 10. In order to use it you need to explicitly remove the existing bitrate configuration by setting it to 0 using '-b:v 0'
$ ffmpeg -i input.mp4 -b:v 0 -crf 20 output.mp4
Note: there are many ways and default settings to downscale video's in resolution and quality. When only trying to downscale, a GUI tool like Handbrake can help you with a convenient interface and a long list of presets for different targets.
Cut a video
If you only need an excerpt of a video, you can use FFmpeg to cut it out:
$ ffmpeg -i input.mp4 -ss 00:00:00.0 -c copy -t 01:00:17.0 output.mp4
The first timestamp is the starting point and the second one is the duration of the sequence you want to cut. So in the case above our video would end after 1 hour and 17 seconds.
Add an overlay or watermark
An overlay, also called watermark, can be added to a video for a more professional look. A logical candidate will be the FSFE logo, or for the FSFE20 videos the 'FSFE Since 2001' logo. For this to work we need the FFmpeg overlay filter. To define and 'route' both the video and watermark stream, we need the Filtergraph description syntax.
Simple overlay
In the simple case of an overlay the image can be loaded using the movie multimedia source. Here the movie command is output to the 'watermark' link. Then the input video file and the watermark link are provided to the overlay filter to render the final video. In this case the transparent png logo image is overlayed so the top-left corner of the image is 20 pixels from the left border and 20px from the top border.
ffmpeg -i input.mp4 -vf "movie=transparent_fsfe_logo.png [watermark]; [in][watermark] overlay=20:20 [out]" output.mp4
Overlay with fade-in and fade-out
For the FSFE20 videos we had an intro and outro in the video. It would ruin the look of the graphic intro and outtro if the overlay was shown during these parts. By using a fade-in and fade-out effect the logo could neatly appear after the intro and dissappear right before the outro.
From experience the previous movie multimedia source wouldn't work for this use-case, and a different style of command is needed. The image is now provided as an additional input to the FFmpeg command, which requires a 'complex-filter' to handle both input commands.
The image has to be called with the '-loop 1' option to keep it available. Also the 'format=yuva470p' should be called on this input number 1 to ensure it is in the correct format. The fade filter is used to provide a fade-in and fade-out to the watermark chain. For this video the fade-in starts (st) at 4 seconds, has a transition duration (d) of 1 second, and fades from transparency instead of black (alpha=1). Similarly the fade-out starts (st) at 137 seconds, has a transition duration (d) of 1 second, and also fades from transparency instead of black (alpha=1). As the looping watermark input will produce an endless video (albeit fully transparent at the end due to the alpha=1 fade-out), the 'shortest=1' property needs to be set on the overlay filter so that it stops once the first link ends, which is the main video.
ffmpeg -i input.mp4 -loop 1 -i transparent_fsfe_logo.png -filter_complex "[1]format=yuva420p, fade=in:st=4:d=1:alpha=1, fade=out:st=137:d=1:alpha=1 [watermark]; [0][watermark] overlay=20:20:shortest=1" outputvideo-total.mp4
Add subtitles
For this you first need to create a subtitles file.
- Open your Editor (like vim, gedit or atom)
Go to the Menu -> Save as -> choose the folder you have the video in -> Name.srt
A subtitles file looks like this:
0 00:00:04,00 --> 00:00:09,99 Hmhm, tock tock, hmhm 1 00:00:10,00 --> 00:00:15,44 Hello and welcome! 2 00:00:15,48 --> 00:00:21,99 more text .... 3 00:00:38,05 --> 00:00:43,79 Thank you for listening and good bye.
Now to add the subtitles file to the video there are different options.
For an avi Video:
$ ffmpeg -i input.avi -vf subtitles=subtitle.srt output.avi
For mp4 you can do it like this:
$ ffmpeg -i input.mp4 -i xyz.srt -c copy -c:s mov_text output.mp4
If your subtitles file was correct you now have an output.mp4 with subtitles.
Youtube
If you want to add subtitles to one of the youtube videos you can follow those steps:
- 1) Login to the fsfe-youtube channel.
2) Go to the Video -> click on "Settings" -> Subtitles/CC -> Add subtitles/cc -> Add new subtitles or cc -> choose language -> upload a file -> choose srt file
3) To enforce the subtitles: Go to "YouTube Studio" -> Videos (on the right side) -> mark the video where you want to enforce the subtitles -> Edit -> Tags -> type: yt:cc=on -> update video
FSFE website upload
To upload the video for use on the FSFE website, it needs to be uploaded to the Download server.