Obtaining footage
For those who prefer the added flexibility of the command line
(with LiVES you only can load the footage from a
DVD or a VCD one chapter/title at a time),
ripping can also be done using MPlayer from the command line. For
example, if the movie resides in the first title the following
command will retrieve all the chapters and store them in
dvd.vob:
mplayer -softsleep -dumpstream dvd://1 -dumpfile dvd.vob
|
Similarly, the following code rips track 4 from a CD into a wav file:
cdparanoia -w 4 track.wav
|
Edit using PNG frames
|
In order to use PNG files instead of the default JPG the following line smogrify:
$img_ext=".jpg"; # can be .jpg or .png
must be changed to:
$img_ext=".png"; # can be .jpg or .png
This will be automatic in future versions of LiVES.
|
Instead of JPG files LiVES can use PNG-encoded frames.
These files are much larger than their JPG counterparts
and operating on them takes longer, but they have the
advantage of better quality through lossless compression.
Editing PNG files requires you have MPlayer 1.0pre7 or greater
installed.
Here is a simple size comparison (in bytes) between the
two formats for a typical movie frame:
| Compression |
JPG filesize |
PNG filesize |
|
100%
|
3425
|
370675
|
|
0%
|
175647
|
433138
|
|
25%
|
37795
|
426806
|
Note that opening movies in LiVES using a high PNG compression level can
take a very long time during which the GUI is active. It may be convenient
to open the video file at low PNG compression (if space allows) and then
compress the PNG files after saving the file set (that is, doing
VJ -> Save Set and Exit). The just cd into
the temporary directory and run
pngcrush as follows (under zsh in the example below):
for i in *.png
pngcrush -e .tmp $i
mv -vf $i:r.tmp $i
|
Next time you re-open LiVES and reload the set it will use the highly
compressed PNG frames (no need to make any changes under Preferences).
A few SoX tips
You might have to trim and/or fade-out the music to suit the video
(although LiVES itself is also capable of trimming audio). The
first command below resamples a 48KHz DVD sound file to 44.1KHz.
Of the next two commands below, the first trims the track at the 4 minute
mark, while the second fades the last ten seconds of the track
until reaching zero-volume at the 4m00s mark using a half a sinewave
envelope:
sox -t wav dvd.wav -r 44100 cd.wav resample -ql
sox -t wav track.wav trimmed.wav trim 0 00:04:00.0
sox -t wav trimmed.wav faded.wav fade h 0 00:04:00.0 10
sox -t wav faded.wav boosted.wav vol 1.3
|
The last command increases the sound's volume. See the sox
man page for details. Another good sound editor is
Audacity.
Working directly on the images
While editing, LiVES keeps all video frames in a directory which is located
under the temporary directory path which you specify in
Tools &mdash> Preferences... &mdash> Directories/Temp directory.
Each clip will contain a file called set.name where name
is the name of the saved set (an within that file is the name of the actual
clip, e.g. try strings set.name).
When you save the set the images remain there, and can be edited in any way
you see fit. You can thus apply various effects which LiVES may not be capable
of performing (using the ImageMagick tools, for example). When you reload the
set LiVES will show the modified images. For example:
Deinterlacing
The smogrify command is what LiVES runs when it makes
any changes to the video you are working on. You might sometimes need
to modify this command in order to perform certain operations which LiVES has
no way (yet) of controlling. For example, in one case a I had a file which
had no audio when I opened it with LiVES
(loading audio is rather important, as sometimes LiVES fails to
load the entire clip if no audio is present). Furthermore, I wanted to deinterlace
the video for my AMV (LiVES now has this capability, although it's not very good).
In order to achieve this I had to directly
edit the smogrify command, changing the lines (these are both one-liners):
$syscom=$mplay_command . " -quiet -slave $band -osdlevel 0
-vo jpeg:quality=$quality $ss -noframedrop $frames -ao pcm
-mc 0 \"$file\" $extra_params > $curtmpfile 2>/dev/null";
.
.
$syscom=$mplay_command . " -quiet -slave $band -osdlevel 0
-vo png -z $compression $ss -noframedrop $frames -ao pcm
-mc 0 \"$file\" $extra_params > $curtmpfile 2>/dev/null";
|
to:
$syscom=$mplay_command . " -vf pullup,scale -aid 128 -quiet
-slave $band -osdlevel 0 -vo jpeg:quality=$quality
$ss -noframedrop $frames -ao pcm
-mc 0 \"$file\" $extra_params > $curtmpfile 2>/dev/null";
.
.
$syscom=$mplay_command . " -vf pullup,scale -aid 128 -quiet
-slave $band -osdlevel 0 -vo png -z $compression
$ss -noframedrop $frames -ao pcm
-mc 0 \"$file\" $extra_params > $curtmpfile 2>/dev/null";
|
Please refer to the
mplayer documentation for further details.
desub.py command line usage
To eliminate the subtitles on frames 1 to 1000 and create
ds_00000001.png to ds_00001000.png use:
desub.py 00000001.png 00001000.png
Suppose your frames are 352x240, and that the subtitles
occupy the bottom 47 pixels. The following command eliminates
the subtitles and slightly pans the images to the right
by 43 pixels. The resulting images will overwrite the
originals:
desub.py -c -s 47 -p 43 -x 00235.png 00987.png
If it's which surtitles occupy the top 20% pixels then, explicitly
using keyframe 00234.png:
desub.py -r -s '20%' -t -x -k 00234.png 00235.png 00987.png
|
Post-processing and encoding
It might be the case that pre-processing requires more sophisticated tools
than those provided by LiVES. Furthermore,
LiVES currently offers very little control over how movies are encoded.
If this is the case it is possible to directly
manipulate the image files as described in the
section above and encode the resulting images. For example, going into the
movie's temporary directory and running:
for i in *.png
do
echo $i
convert -crop '688x448+17+11' -enhance -sharpen '0.0x0.5' -gamma 1.2 -contrast $i img_$i
convert -resize '368x224!' img_$i simg_$i
done
|
Would create two more sets of image files named img_00000001.png ... and
simg_00000001.png ... . In the former set the images have been cropped,
enhanced, and further modified to improve their appearance:

Before
|

After
|
The second set is simply
a smaller version of the first. Note that all dimensions are multiples of 16: failing
to use such sizes might result in a green bar (or other artifacts) appearing around the
movie after encoding.
These changes will not been seen by LiVES (indeed, one
could quit LiVES before running the above commands, as long Save Set and Exit
has been done), but we can now proceed to encode them via the command line:
To generate the appropriate WAV/MP2 file:
sox -t raw -r 44100 -w -c 2 -s audio audio.wav
mp2enc -b 256 -o audio.mp2 -r 44100 < audio.wav
To create an MPEG-1 file from PNG images:
png2yuv -b 1 -f 29.97 -I p -L 0 -j img_%08d.png | \
yuvdenoise -t 2 | \
mpeg2enc -f 0 -F 4 -H -r 24 -4 1 -2 1 -P -g 6 -G 18 -a 3 -b 6500 -q 4 -B 350 -V 1000 -o amv.mpv
Combining video and audio streams:
mplex -f 0 -b 1100 -V -r 7000 audio.mp2 amv.mpv -o amv.mpg
|
As a result of the above an MPEG-1 file will be created from a series of PNG images,
tuned according to some of the myriad of options detailed in the
mjpegtools documentation. A similar procedure could be used for JPG files, making sure to use
jpeg2yuv instead of png2yuv. However, manipulating JPG
files can easily lead to quality loss, and it is recommended that they be converted
into PNG (even at the temporary expense of space) for processing (by, say, changing
the filename extension when running
the convert command).
Note that removing *img*, movie* and audio*.*
would suffice in order
for the temporary directory to return to its purely LiVES-generated state.
Many of the above operations can be carried out by using the various encoders,
all of which work basically the same way. Here is a more thorough example of
how mpeg_encoder.py works:
First, check that all dependencies are satisfied:
mpeg_encoder.py -C
/usr/local/bin/convert: found
/usr/local/bin/mpeg2enc: found
/usr/local/bin/mp2enc: found
/usr/local/bin/sox: found
/usr/local/bin/png2yuv: found
/usr/local/bin/jpeg2yuv: found
/usr/local/bin/yuvdenoise: found
/usr/local/bin/yuvscaler: found
/usr/local/bin/mplex: found
Suppose you have restored a LiVES' .lv1 file (in either JPG or PNG format),
and that the images are stored in the directory "/tmp/livestmp/991319584/".
In this example the movie is assumed to be 16:9. NOTE THAT THE VIDEO MUST
BE PROGRESSIVE (NON-INTERLACED) FOR THIS TO WORK. Then, in order to
create an MPEG-1 file you can simply do the following:
mpeg_encoder.py -d /tmp/livestmp/991319584 -o /movies/default.mpg -a 3
and the clip "default.mpg" will be created in "/movies/" with the correct
aspect ratio.
Suppose we want to make a downloadable version of the clip, small in size
but of good quality. The following command activates the generic enhancement
filter and resizes the images to "352x240". Note that these operations
are performed after cropping the originals a bit (using "704x464+5+6").
This is done because we are assuming that there is a black border around
the original pictures which we want to get rid of (this might distort the
images somewhat, so be careful about cropping/resizing, and remember to
use dimensions which are multiples of 16):
mpeg_encoder.py -v -d /tmp/livestmp/991319584 -w /tmp/tmpmpg \
-o /movies/download.mpg -a 3 -k -e -c "704x464+5+6" -r "352x240"
Here is how you can create a DVD-compatible MPEG-2:
mpeg_encoder.py -v -d /tmp/tmpmpg -t dvd -o /movies/dvd.mpg \
-s /tmp/livestmp/991319584/audio -a 3 -k -p eimg
If you notice that the video and audio become out of sync so that
near the end of the movie the video trails the audio by, say, 0.2s,
you can use the "-D" option as follows:
mpeg_encoder.py -d /tmp/livestmp/991319584 -o test.mpg -D 200
Note that negative time values are also allowed.
Suppose that you have "movie1.lv1", "movie2.lv1" and "movie3.lv1".
Batch-encoding can be done as follows (zsh-syntax):
for i in movie?.lv1
do
mkdir /tmp/$i:r
mpeg_encoder.py -d /tmp/$i:r -o /tmp/$i:r.mpg -L $i
rm -rf /tmp/$i:r
done
This will generate the files "movie1.mpg", "movie2.mpg" and
"movie3.mpg" in "/tmp". Note that is is not necessary to
specify whether the files are stored in JPG or PNG format,
and that potentially time-consuming options (e.g. "-e") may
be enabled. It is not necessary to have a working LiVES
installation to encode .lv1 files.
|
x264 support
A great new video format is H264/AVC which can be encoded using the
x264 (h.264) libraries.
These libraries are still extremely new and in constant development, so
they are not recommended to encode clips for distribution. However, they
have great potential and offer an opportunity to test the "up-and-coming"
codec. Below is a quick and dirty guide on how to install the libraries
so as to allow encoding and playback using MPlayer:
First read:
http://www.videolan.org/x264.html
then do:
svn co svn://svn.videolan.org/x264/trunk x264
Then in the directory (say $X264) do "make". Once
that's done re-compile MPlayer adding the following:
--enable-x264
--with-x264libdir=$X264
--with-x264incdir=$X264
(of course, "$X264" is actually something like /usr/local/x264).
|
Creating an (S)VCD
If you have a CD-burner you can make a disc which will be playable on certain
(most?) hardware DVD players. This of course allows to watch an AMV on a
TV screen. The procedure consists in encoding the appropriate MPEG file and
then creating an image which can be burned unto the disc. In general SVCDs
look better than VCDs, but the latter seem to be more widely supported by
DVD players. I've also noticed that que image quality (for a given VCD, say),
can vary quite a bit from player to player. YMMV. The following
instructions create NTSC-playable CDs, but may also work on PAL (untested).
Note that the LiVES mjpegtool_encoder should be able to
create
MPEG movies, including those compatible with the VCD/SVCD formats. However,
this plugin is still very new and hasn't been thoroughly tested. The
multi_encoder is better tested, but can only encode non-interlaced
video (however, it is quite good at it). The following
procedures are known to work, and learning them provides a lot of insight of
how things work. However, you may skip most of the gory details and use the
mpeg_encoder.py script provided. Still, this section
also has some tips about burning the media, so it's probably a worthwhile
read anyways.
Within the LiVES temp directory which contains the JPG/PNG frame files run
the following:
sox -t raw -r 44100 -w -c 2 -s audio audio.wav
To create VCD MPEG-1 files:
mp2enc -V -o audio.mp2 < audio.wav
png2yuv -b 1 -f 29.97 -I p -L 0 -j %08d.png | \
yuvdenoise -t 2 | \
yuvscaler -M WIDE2STD -O VCD | mpeg2enc -f 1 -r 16 -o video.mpv
mplex -f 1 audio.mp2 video.mpv -o video.mpg
To create SVCD MPEG-1 files (non-interlaced):
mp2enc -V -e -o audio.mp2 < audio.wav
png2yuv -b 1 -f 29.97 -I p -L 0 -j %08d.png | \
yuvdenoise -t 2 | \
yuvscaler -M WIDE2STD -O SVCD | mpeg2enc -f 4 -q 7 -I 0 -V 200 -o video.mpv
mplex -f 4 -b 200 -r 2750 audio.mp2 video.mpv -o video.mpg
Note that in the two cases above the "-M WIDE2STD" parameter is only
necessary if the footage is in widescreen format (e.g. 16:9).
(if you have multiple videos repeat the above as necessary e.g. amv01.mpg,
amv02.mpg... etc.)
Make the VCD image:
vcdimager -t vcd2 amv01.mpg amv02.mpg amv03.mpg ...
or SVCD:
vcdimager -t svcd amv01.mpg amv02.mpg amv03.mpg ...
The files "videocd.cue" and "videocd.bin" are created. Burn the CD (as root):
nice -20 cdrdao write --speed 48 --driver generic-mmc --device 1,0,0 videocd.cue
Make sure you use the appropriate device in your system i.e. try "cdrdao scanbus"
as root. Also, check that the write speed is appropriate for both the driver
and the CD-Rs. The "generic-mmc" driver works for many burners. For a full list
of drivers see:
http://cdrdao.sourceforge.net/drives.html#dt
|
|
When you burn multiple SVCD videos the last few seconds (maybe 5) of each
clip are trimmed, so add some padding at the end if you plan to use this format.
VCD files are fine, though.
|
Creating a DVD
The best way to store an AMV for TV reproduction is by making a DVD. In
order to do this an appropriate MPEG-2 file must be encoded. This is
readably done by means of the following commands:
sox -t raw -r 44100 -w -c 2 -s audio audio.wav
DVD MPEG-2 file encoding:
mp2enc -r 48000 -o audio.mp2 < audio.wav
png2yuv -b 1 -f 29.97 -I p -L 0 -j %08d.png | \
yuvdenoise -t 2 | \
yuvscaler -M WIDE2STD -O DVD | mpeg2enc -f 8 -q 7 -4 1 -2 1 -P -I 0 -o video.mpv
mplex -f 8 audio.mp2 video.mpv -o video.mpg
|
Again, the above example has NTSC as target, with non-interlaced input.
The video is also assumed to be widescreen, but if it's 4:3 suffice not
to use the -M WIDE2STD option.
Once the files video01.mpg, video02.mpg ... have been created
the next step is to make the menus, titles, chapters, etc. This is unfortunately
beyond the scope of this guide, although the are various tutorials on the web
on how to do this e.g.
Some thoughts on DVD authoring
and
DVDAuthor documentation.
For the time being we shall simply present the commands necessary to burn a trivial
DVD which will simply start playing once loaded. First, make a configuration file called
dvdauthor.xml which contains the following text (assume there are
three clips):
<dvdauthor>
<vmgm />
<titleset>
<titles>
<pgc>
<vob file="video1.mpg" pause="1" />
<vob file="video2.mpg" pause="1" />
<vob file="video3.mpg" pause="1" />
</pgc>
</titles>
</titleset>
</dvdauthor>
|
Save the above in a directory containing the DVD MPEG files and then run:
dvdauthor -o amvdvd -x dvdauthor.xml
|
The appropriate file structure will be created in a directory called
amvdvd (make sure this directory doesn't already exist before
you run the command). Test the DVD by running:
mplayer amvdvd/VIDEO_TS/VTS_01_1.VOB
|
Last but not least, burn the DVD using growisofs from
dvd+rw-tools:
(Test it first)
growisofs -dry-run -Z /dev/dvdrw -V AMVS -dvd-video amvdvd
(OK, go for it!)
nice -20 growisofs -Z /dev/dvdrw -V AMVS -dvd-video amvdvd
|
In my case /dev/dvdrw is a symlink to /dev/scd1,
choose the appropriate device for your system.
|
Note regarding the DVD format
|
|
Strictly speaking the NTSC standard does not support MP2 audio
(PAL does, though). Hence mpeg_encoder can now create "strictly
DVD-conformant MPEG-2 streams" which use PCM audio. Unfortunately
dvdauthor is very sensitive to PCM audio as can been seen from
this post.
The bottom line is, MPEG-2/MP2/MPEG streams seem to play fine on most, if not
all,
hardware players and are the recommended encoding format for hardware
playback.
|
Return to the main LiVES guide
|