Before we begin the practice, let us ask ourselves some very interesting questions: why the console, why use the Ogg Theora video codec, how and with what parameters is it better to convert the video.
Let's start with the materiel:
Video codec is a program / compression algorithm (that is, reducing the size) of video data (video file, video stream). A codec is a file formula that determines how you can “pack” video content and, accordingly, play the video. Encoding is also possible in addition to video and audio information, adding subtitles, vector effects, etc.
')
Today, the most popular video codecs are the familiar DivX, XviD, H.264, WMV, Apple QuickTime and many others. Ogg Theora was always in the shadow of her colleagues and there seemed to be some reason for that. Maybe because it is a relatively new codec (it appeared only in 2004), maybe because it was initially oriented towards using it on the Internet, and not for encoding video films ... This is not important anymore.
- Theora is an open and free video codec for commercial and non-commercial use.
- Theora uses high quality compression algorithms, making this codec a good choice for encoding any type of video.
- Theoraora is ideal for streaming video on the Internet, the final size / quality leaves far behind all competitors.
- Theora is cross-platform. This means that you can use the format in any modern operating system, both in Linux and in Windows.
- Every modern Linux distribution supports Theora by default. You do not have to use third-party proprietary codecs to view videos in this format.
Here are the main reasons for using Ogg Theora. But the habit is a great power and standard codecs today are DivX and XviD. For high-quality coding, H.264 is usually used. When you download a movie from the Internet, be sure - most likely it is compressed with one of these three codecs.
Who is to blame and what to do? All these codecs are closed, patented and paid. Something tells me that their owners receive good deductions from each sold household player. There are plenty of reasons why Theora is the preferred choice. And you can start to improve the world from the small - translate your video library into the free format OGV - Ogg Vorbis Video.
Using Linux, we have a very powerful tool available - the bash console. With it, you can work wonders and the most complicated operations in a matter of minutes. The same applies to video conversion. To begin, we need only one console utility -
ffmpeg2theora . I will not describe how to install it. If you are using Linux, then you can already install any programs by the regular package manager. So let's get to the point right away.
Example 1. Converting "avishki".
For example, let's convert one series of my favorite series, The Big Bang Theory. So open the console.
Go to the folder with the file:
$ cd ~/Downloads/
Choose the optimal options for non-dynamic video and normal sound:
$ ffmpeg2theora -v 8 --optimize -a 4 -o test.ogv The.Big.Bang.Theory.S03E17.rus.HDTVrip.\[Kuraj-Bambey.Ru\].avi
Let's see what is written here. ffmpeg2theora - of course, this is the program itself. Next are its options-keys:
-v indicates the desired video quality on a scale from one to ten. Level 8 is enough for transcoding an already compressed video. If the film is saturated with dynamic scenes, then it is better to specify to the maximum, that is, 10.
--optimize , as you might guess, optimizes picture quality, to the detriment of the conversion speed. But we have nowhere to hurry, quality is more important.
-a indicates the desired sound quality, also on a ten-point scale. The number 4 actually means 128 kbps, which is enough for the series. You can also specify the -A key with the parameter 128. The same is obtained.
After
-o, we specify the name of the file at the output, for example test.ogv (
ogv is the standard extension for video in ogg format).
And at the very end we specify the file, which, in fact, we want to convert. Hit Enter and watch the result. Or do not follow, since the process lasts a long time, it depends on the power of the computer.
Example 2. Convert DVD.
Here everything is somewhat more complicated, but not by much. Compressing an already compressed video is sometimes fraught with tangible loss of image quality. But the DVDRip in Theora format is better in quality than the usual DivX. For example, let's “rip” the film “The Matrix”.
Go to the folder with the file:
$ cd ~/Downloads/Matrix/VIDEO_TS/
Choose the optimal options in the calculation of the source file of 1.4 gigabytes:
$ cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB VTS_01_5.VOB | ffmpeg2theora --videobitrate 1434 --optimize --first-pass tech.ogv --audiobitrate 256 - && cat VTS_01_1.VOB VTS_01_2.VOB VTS_01_3.VOB VTS_01_4.VOB VTS_01_5.VOB | ffmpeg2theora --videobitrate 1434 --optimize --second-pass tech.ogv --audiobitrate 256 -o matrix.ogv -
Let's expose the magic of this spell. Here we are confronted with a powerful console thing called “thread redirection”. This is beyond the scope of this article, but you can see that before the ffmpeg2theora command, we are building a list of files for conversion. The DVD is always split into VTS_order-number_order-number, so we need to put them together.
cat is doing file adding.
| - this is a redirection symbol, in our case it gives a queue of files for processing by the ffmpeg2theora program.
--videobitrate indicates the desired video quality, like the
-v option , but not on a scale from one to ten, but in
kilo-bits exactly. Synonym for
-V .
- First-pass-pass means the first, technical run of the video and saving the analytical information in the tech.ogv file for the future basis of the second, final run of the video.
--audiobitrate indicates sound quality in kilobits. The key synonym is
-A .
&& is like an addition command. Immediately after the first program to perform the second. Just to automate production :)
- second
-pass - the second run. At this time, algorithms are applied and the video sequence is directly encoded. For this purpose, the tech.ogv technical file prepared during the first “analytical” passage is used.
At the end of the command, a
- is put, this indicates to the converter the incoming file stream for processing.
Click Enter and wait, wait, wait. Will have to wait a long time. While we wait, let's find out where the numbers 1434 and 256 came from.
With 256, everything is simple. This is 256 kbps per sound, which is decent even for a musical :) The video bit rate is calculated using the formula:
BV = (Sx8x1024) / L-BA , where
BV - video bit rate;
S is the desired file size in megabytes;
L is the duration of the film in seconds;
BA - audio bitrate.
It is important to clarify that this is a pure bitrate, without the so-called redundant technical information, which is about one percent of the video bitrate. That is, the real bit rate that the encoder needs to specify is 99% of the BV. Here also those 1434 kilobits turn out.
I wanted the original file to occupy 1.4 gigabytes. The result of simple calculations gave the desired result. If the exact file size does not matter, you can simply specify the -v option with the parameter 8, 9, or 10. This will give a high quality picture without unnecessary problems. In any case, play around with the settings, since for each video the parameters are selected individually, it depends on the dynamics of the image, semitones, etc.
The process, as you can see, is simple and flexible. Of course, the translation of the entire home video library will take a lot of time, but little by little, you can start a little bit.
In the Ogg Theora format, I found only one flaw, for many it will seem significant - the lack of support from manufacturers of household appliances. Yes, your dvd player will most likely not be able to play Ogg. But after all, demand creates supply, right? If the format becomes popular, surely manufacturers will pay attention to it. The quality of the picture will please the eye and world peace will come :) Everything is in our hands.
PS I would be very grateful for any constructive comments and clarifications on this article.