home   articles   archive   forum   masthead  
Published at 5.8.2000
Author: Ronny Ziegler
Translator: Andy Ziegler
Languages: de nl
Printer printer-version
Support Us!

Linux a VCR

Linux, the VCR If you own a TV card but not a VCR (video cassette recorder), or if you want your favorite movies on a CD, you should read this article.


Linux & Multimedia

Almost everyone who wants to edit videos professionally typically uses any other platform than Linux with GPL programs.
Until now, the Linux-supported MPEG cards have been few and the only Linux software that exists is MainActor.

Who has enough money to buy a MPEG card that costs about $500? Not us!
As usual, Linux offers a much cheaper solution that comes with with some constraints and more work.

A TV card, a quite fast and medium sized hard disk (it does not have to be SCSI), a few GPL programs and a lot of time are necessary.
As more Linux systems are placed on the desktop, the interest in multimedia programs becomes greater. In the beginning, the main Linux tools were word processors and network tools, but with increasing PC power and the rising number of X programs you find multimedia programs as well.

Whoever tried to produce MPEG videos with Linux two years ago had to use the Berkeley tools. With these programs you had to split your video into single frames, then encode every frame and finally merge them to an MPEG stream.
The sound had to be converted into MPEG and both streams had to be merged.
The synchronization of picture and sound worked randomly; after so much effort, this could be quite annoying.

The Software

Meanwhile, there is a quite comfortable alternative that also produces MPEG videos. We use the program Broadcast2000, mpeg2_movie and XMovie which all were created by Adam Williams.

The video is recorded with Bcast2000 and saved in the Quicktime format. The encoding of Quicktime to MPEG2 is done by mpeg2_movie. The MPEG2 player is XMovie (the players that are usually included into the distributions only support MPEG1).

The combination of the three programs is a little more complicated than expected at first ...


Broadcast can record pictures and sound coming from a TV card as many other programs, too.
Other programs like kWinTV save the video signal in the AVI format, but Broadcast uses the Quicktime format.
This can be done because the Quicktime libraries are under the GPL license.

Depending on the power of your PC (in particular the speed of your hard disk), an upper limit exists for the data flow. Too bad that this maximum data flow can be reached very fast.

Usually there is a maximum resolution supported by your PC. With higher resolutions, your recording is not free of errors. These errors are usually missing frames in the stream. The upper limit is different for every PC and everyone should try to find it individually.

Before you try your first record, you have to set the channels in Broadcast2000.

Therefore you have to push the record button:

Record button

In the appearing window you enter a dummy filename where the video file will be saved (e.g. /tmp/tmp.mov).

Activate the button "Render audio tracks" and "Render video tracks" and click on OK.
Now, one or two windows appear depending on the activation of the button "Monitor Video". If you have just one window, click on this button and the second window will open. There you see the signal on your TV card. As long as no channels are set, you just see noise. The top left button in this window guides you to another window where you can set the programs. The menu "Add" has to be selected and one more window is opened where you specify the source:

Broadcast settings

The fine tuning is done by hand and an automatic channel search does not exist. It can take quite a long time until you have set all the channels.
Remember the names of the channels (case sensitive) you set because you'll need them later.

If you set all the channels, you would be able to start recording videos. Select the desired channel and deactivate the "Monitor Video" button. Then click on the red record button.
Have a look at the number of frames that are lost (at "Frames behind"):


Here you should see a count of 1 to 2 frames.
If this number increases continuously, you PC would not be able to handle the data flow and you would have to choose a lower resolution or frame rate. This can be done in the main window at
Video -> Frame rate and
Video -> Resize

Default resolutions are:


The frame rate should be between 15 and 24 frames per second. The recorded video is saved after stopping the record and clicking on the save button. Then push the play button and you would see the recorded file if the menu Window -> Show Video is activated.
Now you should find the settings which you prefer: A higher resolution with a few missing frames of more frames per second and a smaller resolution.
If you found the maximum data flow that could be handled by your PC you should write down the setting (frame rate and resolution) and exit Broadcast.

Our PC (K6-400 and IBM harddisk) manages a resolution of 320x240 and a frame rate of 15 Fps. This is not splendid, but acceptable to us.

A video can be recorded by hand as we did before, but a record steered by a script would be much more efficient; Bcast2000 supports this option.
A script should look like:

  (new_project)                 # start a new project
  (set_atracks 1)               # number of audio tracks
  (set_vtracks 1)               # number of video tracks
  (set_channels 1)              # 
  (set_samplerate 48000)        # Rate of the sound record
  (set_framerate 15)            # Frame rate
  (set_trackw 320)              # Resolution width      perfectly
  (set_trackh 240)              # Resolution height
  (set_outputw 320)             # Width of the output video
  (set_outputh 240)             # Height of the output video
  (set_aspectw 4)               # Ration of Width to 
  (set_aspecth 3)               #           Height
  (ok)                          # 
  (record)                      # start Record
  (set_channel Pro7)            # name of the channel (case sensitive)
  (set_path /tmp/record.mov)    # Filename of the record
  (set_audio 1)                 # record audio
  (set_video 1)                 # record video
  (set_format Quicktime)        # file format
  (set_audio_compression IMA4)  # Audio compression
  (set_audio_dither 0)          #
  (set_audio_signed 1)          #
  (set_audio_channels 1)        # 
  (set_video_compression JPEG)  # Video compression
  (set_video_quality 80)        # quality of the compression
  (ok)                          #
  (set_mode timed)              # record defined time length
  (set_duration 1200)           # record time in seconds
  (set_monitor_audio 0)         # do not display audio
  (set_monitor_video 0)         # do not display video
  (start_recording)             #
  (ok)      		      #

download script

Now an automatic record can be started via

  >> /path/to/bcast2000.sh -b /path/to/record_script
Bcast2000 works through the script, opens the record window with the chosen settings and starts recording.
If the set duration is over Broadcast would not stop the program automatically, just the recording. The file can only be saved by hand and also you have to exit the program by hand (this is not the perfect solution for an automatic recording of more than one file ...)

Linux is not a real-time OS, but a multitasking OS and it can happen that other programs start during recording (e.g. by a cron job) and lower the frame rate which can be handled by the PC.
The only solution would be to stop all other programs that are not necessary.
An other problem would occur if you try to record a very long time. The created MOV file reaches the maximum allowed file size of the ext2 file system quickly.
A solution might be a change to another file system (e.g. ext3 or better, ReiserFS) but this is not recommended for Linux newbies.
A simple solution would be to record the movie in small parts. Best places for interrupts are the commercials which you can cut completely while you wait for the continuation of the movie. But don't forget that you have to choose a different file name for the next part!


If you recorded the video parts, proceed to the next step. The encoding of Quicktime to MPEG2 takes a very very long time. Video and audio stream are encoded separately. In the subdirectory of video of mpeg2_movie you start the program encode:

  >> encode -b 1900000 /tmp/record.mov /tmp/record.m2v
This program produces the MPEG2 video (suffix .m2v).
The encoding can take very long depending on the file size (15-20 hours for a 20 minutes video on our PC).
If you split the video in parts you have to encode every single file on its own:
  >> encode -b 1900000 /tmp/record1.mov /tmp/record1.m2v
  >> encode -b 1900000 /tmp/record2.mov /tmp/record2.m2v
  >> encode -b 1900000 /tmp/record3.mov /tmp/record3.m2v
If all m2v files are created, we change to the sound encoding. Therefore you start the program encode from the audio subdirectory (for a split movie):
  >> ./encode -b 192000 /tmp/record1.mov /tmp/record1.mp2
  >> ./encode -b 192000 /tmp/record2.mov /tmp/record2.mp2
  >> ./encode -b 192000 /tmp/record3.mov /tmp/record3.mp2
This runs much faster than the video encoding.

Now the three video files (.m2v) and the three audio files (.mp2) have to be merged in one file. The program mpeg2cat in the subdirectory libmpeg2 does this job:

  >> ./mpeg2cat /tmp/record1.m2v /tmp/record2.m2v /tmp/record3.m2v > /tmp/record_all.m2v
  >> ./mpeg2cat /tmp/record1.mp2 /tmp/record2.mp2 /tmp/record3.mp2 > /tmp/record_all.mp2

In the final step, you have to merge the video and the audio stream. The tool mplex is used and can be found in the subdirectory mplex of mpeg2_movie:
  >> mplex /tmp/record_all.m2v /tmp/record_all.mp2 /tmp/record_all.mpg   
Now we have reached our goal after a lot of time and have the final MPEG2 file we wanted.


xmovie Screenshot Now, how do we see the MPEG movie? In contrast to MPEG1, MPEG2 is not well supported with Linux (even MPEG2 M$Win tools cannot be found that easy).
With Linux, you can use the program XMovie to play the file. But this is not so easy as you might think because the program needs the xv extension to compile correctly and this extension is only included in the newest X servers.
If you used an older X server, you should not be too disappointed. It could help if you comment out the corresponding lines in the source code.
These are quite more lines than we can list here and that is why we made our "adjusted" version of XMovie available here. You can download the source code or a binary version (RedHat 6.2) (download XMovie and say "Thank you" to the GPL).
If the pre-compiled version does not run, you have to download the source code and do a "make clean; make".

This adjusted version can not support all functions of the original but as long as you can play MPEG2 files, it should be enough.
The call to XMovie looks like:

  >> xmovie /tmp/record_all.mpg

Wishes for the future

An automatic recording is not yet possible because Broadcast does not exit automatically and locks the video device as long as it runs. You cannot start recordings in a defined timetable without closing the window every time by hand.
We hope that the Broadcast`s programmers add this option and make it possible to use the PC as a VCR via the at command.
We dream about a small Web frontend so that you can program your VCR via the internet (And if you think about how much money you would save compared to a commercial AV-server, you'll get a big smile!!)
As soon as Broadcast`s authors release a new version, we will write the next article.

http://members.xoom.com/NicholasF/ Trinity Logo Trinity is an other video record program. It is developed as well as Broadcast, but it seems that the development effort has stopped.
http://heroine.linuxave.net Homepage of Broadcast, Xmovie and mpeg2_movie. You will find a big collection of other tools and information about MPEG and Linux.
http://www.ma inconcept.com/products/
Here you will find the commercial tool to edit frames that can be used with Linux, too.
The sources of all MPEGs: the Berkeley MPEG tools.
http://moes.pmnet.uni-oldenburg.de/bttvgrab/ Bttvgrab is an other program to create MPEG videos but with difficult video-audio synchronization. The program can be steered completely via options and can be used for an automatic record.

Talkback Area

Enter Own Comment