Movie formats

Container formats

Movies are not just simple files, since they have at least some sound tracks. A typical movie has therefore multiple tracks: A video track and two sound tracks to have stereo. To put everything to one single file a container format is required. This container format holds all tracks together. Container formats are:

  1. OGG

  2. AVI

The tracks make use of different codec formats for audio and video. For audio it is mostly mpg3, but for video different codecs are available

Video codecs

  1. DivX

  2. Xvid

  1. MPEG

  2. H264

A good compatibility to have the video running on all kinds of devices is AVI using XVID and a MP3 codec. The selection of codecs are a potential source of incompatibility problems between certain files and applications. So if you get problems with a player try to rip in an other format. Linux uses mostly as default open and license free format, however they do not run well on Windows machines and other devices. To have portable video mpeg seems the way to go.

Video tools

Tools for video files are:

  1. avinfo simple command line tool

  2. kino video editing software. Some terms and concepts must be understood to not get lost. A movie contains different scenes. kino uses a container format not loosing the individual elements of a movie this optimized for editing the movie. However this container format is not that what most users expect from a movie since it is not a simple mp4 or whatever format. The kino container format is to edit the movie and not to just play it. So the container format needs to exported to mp4 or whatever using kino before it is distributed or played. kino supports just dv video format but it is able to convert to it when open a file. In the export a start and stop time can be set so the video can be cut.

  3. openshot gui video editing sw (see overlay eix openshot)

  4. ffmpeg can easily convert videos:

ffmpeg -i<input>.avi <output>.mpg

To see what formats it supports ffmpeg -formats and what codecs: ffmpeg -codecs, or to see the formats ffmpeg -formats

man ffmpeg illustrates that ffmpeg is quite a universal tool.

To rotate 90° clockwise ffmpeg -i <input> -filter:v transpose=clock -c:v libx264 -preset veryfast -crf 22 -c:a copy -metadata:s:v rotate="" <output> it also removes meta data since this could also cause the player to rotate the video.

To copy without modifying the recoding ffmpeg -i<input>.mov -vcodec copy -acodec copy <output>.avi

To change the pixels ffmpeg -i input.avi -s 1360x768 output.avi

To change the video bitrate using the -b:v option ffmpeg -i input.avi -b:v 2048k output.avi

ffmpeg can also handle other things as inputs than files, as from /dev/video0

ffmpeg -f video4linux2 -i /dev/video0 -s 640x480 test.avi

and alsa ffmpeg -f alsa -ac 1 -i hw:1 -f video4linux2 -i /dev/video0 /tmp/out.mpg or grab an x11 screen ffmpeg -f x11grab -video_size cif -framerate 25 -i :0.0 /tmp/out.mpg

The ffmpeg package comes with other tools as ffprobe <filename> to see the details of a movie file. ffplay a simple command line player or the streaming server ffstream.

Compression techniques

A video can highly be compressed to save bandwidth for its transmission and storage size. Video compression must obviously be real-time and requires therefore high processing power. A lot of innovative algorithms and methods have been invented. Currently the H.264 algorithm is the most popular. A video is a sequence of images, typically 24 images a second. Such images are called frames. To make video compression robust sequential frames (12-15) are grouped into Group Of Frames (GOP). The first frame is called I-frame (Intra Coded Frame) and is a regular picture compressed as JPG having macro-blocks of 16*16 pixels that are compressed using a Discrete Cosinus Transformation (DCT). Since the following frames do not differ a lot, they can be highly compressed. Those frames contain just the color and intensity difference of the macro-blocks from the adjacent frames. P-frames (Prediction-Frames) are inserted that are considering differences to the preceding I-frame or P-frame. The H.264 codec goes one step ahead and considers in its B-frames (Bidirectional-Prediction-Frames) the difference to up to 16 preceding and following frames. B-frames are therefore up to 20% smaller than P-frames.

Linurs Servernest startpage