Add music to your content creations: youtube-dl

Today, I present a series of tools to create videos and add music to them. Our operating system is GNU/LINUX, a distribution that does not comply with the ethics of free software by using proprietary drivers.I hope to have time soon to be able to change the distribution. For better or for worse, we learn as we go.

As a tool to record videos we have used Vokoscreen, it is licensed under the GNU General Public License v2.0. In its Github repository you can check it. It allows us to create videos, with or without sound. Although, in this case we are going to create a video without sound and add it with another tool.

The default installation allows us to create videos in mp4, mkv and gif formats. I suposse that there are ‘plugins’ to extend it to more formats, but we have not looked for them to show you some tool that acts by command line and transforms video formats.

With VokoScreen we have created a video called stringReveralSolutionOne.mkv

We locate on YouTube a song by a group that we like and note the URL that refers to it:

As we are learning about free software, we have located information about the sound formats considered as such. Ogg Vorbis is listed in the FSF’s free software directory.

On the other hand, we have youtube-dl tool which is a command line program to download videos or extract audio from streaming sites such as YouTube, Dailymotion or Vimeo. It is written in Python and in the public domain under the Unlicense license.

This is its repository on GihHub which was closed a while ago and has been reopened.

At the time it performs the YouTube sound extraction, it allows us to apply the format we want to apply to it, in this case Vorbis. So go ahead, from the command line we execute:

youtube-dl -x –audio-format vorbis https://www.youtube.com/watch?v=9UklTj3Cqw8

Once the process is finished, the song is available on our computer: rockAndRoll.ogg

As the video created with VokoScreen is in MKV format, we use another command line tool to convert it to OGV format. This tool is called ffmpeg and is licensed under the license Creative Commons Attribution-ShareAlike 3.0 License.

In the beginning… was the command line

We execute the following command to replace the video sound  (created with VokoScreen) with the song that we have extracted from YouTube:

ffmpeg -i stringReveralSolutionOne.mkv -i rockAndRoll.ogg -c:v copy -map 0:v:0 -map 1:a:0 stringReveralSolutionOneA.mkv

Now we transform the video format with the same tool:

ffmpeg -i stringReveralSolutionOneA.mkv -codec:v libtheora -qscale:v 3 -codec:a libvorbis -qscale:a 3 -f ogv stringReversalSolutionOneB.ogv

Specifically, these videos correspond to the resolution of the problems of a course by Stephen Griden. The published code is licensed under the GNU General Public License v3.0

The solutions are being published in a Github repository and of course, under the same license.

String Reversal. Solution 1

String Reversal. Solution 2 and 3.