Video editing Ubuntu

From Wiki

Jump to: navigation, search

Contents

preparation

First, make sure that mplayer, subtitleeditor, vlc and xvidcap are installed:

download the actual xvidcap debian package (.deb), save it to your Desktop and double-click it to install

if you don't like xvidcap, you can also try out recordmydesktop:

sudo apt-get install recordmydesktop gtk-recordmydesktop

See http://www.ubuntuguide.org for detailed instructions on how to set up mplayer and VLC:

sudo apt-get install mplayer subtitleeditor vlc mencoder audacity

If you have an webcam that works under Ubuntu, make sure that camorama is installed

sudo apt-get install camorama

recording

Record the video using xvidcap. Set the quality to 100% and the frames per second toward 12.5 fps.

Ian will convert the video to 800x600 for the showmedo-player, so use a smaller recording area or change the screen resolution (under Ubuntu: -> System -> Prefercences -> Screen Resolution) down to 800x600.

You can record a bigger area than 800x600, but keep in mind that this will make the video file larger and fonts and details will be hard to see after the video is transformed to 800x600.

It is a good idea to use large fonts. Remove unnecessary stuff from the gnome-panel. I like to make the xvidcap recording area (the red rectangle that you can "paint" with the pen icon of xvidcap) a bit lower then 600 pixel so that i can have the xvidcap control window outside and on top of the red recording area.

At the end of your recording session with xvidcap, save the video to the file myvideo0.avi.

If your filename is myvideo0.mpeg then rename the file to myvideo0.avi (it is most likely an .avi disguised as an .mpeg)

mv myvideo0.mpeg myvideo0.avi

adjust sound volume

Depending on your microphone, you probably want to increase the voice used in the videos unsing a sound editor program like audacity:

with audacity

First, you have to extract the sound from the .avi file:

mplayer -vo null -ao pcm:file=mysound.wav myvideo0.avi

Second, open this file in audacity, amplify / edit it and save it as myperfectsound.wav Now you can use mplayer to replace the old sound of your video with the improved sound:

 mencoder -o myvideo1.avi  -ovc copy -audiofile myperfectsound.wav -oac pcm  myvideo0.avi
If your sound is already in good quality, simply rename your myvideo0.avi into myvideo1.avi

crop/expand video

This step is very important. Do not skip it, because other steps depend on it.

Make sure the the video format (width and height) is a multitude of 16, ideally 800x600.

Check your video by watching it using the VLC player (right-click on file, "open with VLC media player").

In VLC go to the menuitem "View -> Stream and Media Info-> Advanced" while the video is playing. Check the x and the y dimension. Decide for yourself if you want to cut the video down some lines or expand it (up) some lines so that the hight of the video is 512 or 528 or 544 or 560 or any multitude of 16.

That is important to avoid black / white glint later.

If your video is too high (y-axis) than use the parameter crop, else use expand. In this example, i use expand because my video had 800x526 pixels hight and i want to have 800x528:

mencoder -oac copy -vf expand=800:528:0:0 -ovc raw -o myvideo2.avi myvideo1.avi
Note that myvideo2.avi will be very big and you will maybe see negative colors. Make sure you have enough space free on your harddisk
If you skip this step, rename your myvideo1.avi into myvideo2.avi

Logo

To permanetely render a logo image into your video, doe this steps:

create a pipe

mkfifo mylogo.fifo

create a logo bitmap file with an alpha channel (for transparent background) with an graphic program like GIMPG. Save it as mylogo.png convert the logo.png into mylogo.rgba

convert mylogo.png mylogo.rgba

now write a command into the pipe to render the logo with width 88, height 31 to position 20,10. Replace 80 and 40 with the width / height of your logo !

( echo "RGBA32 88 31 20 10 0 1" ; cat mylogo.rgba ) > mylogo.fifo &

now encode using mencode:

mencoder -oac copy -vf bmovl=0:0:mylogo.fifo -ovc raw -o myvideo3.avi myvideo2.avi
If you skip this step, rename your myvideo2.avi into myvideo3.avi

Subtitles

create subtitles

If you want to have Subtitles, make them with a program like SubtitleEditor:

In SubtitleEditor, navigate to the menui item "Timing -> Open Media" and open your video file myvideo2.avi

(myvideo2.avi is in most cases a smaller file than myvideo3.avi)

Navigate to "File->New" to create a new subitle file

Use the insert key of your keyboard to make a new subtitle-line. (Press it twice at the beginning)

Use your mouse to edit the time-selection for the actual subtitle-line.

write the subtitle-Text for this line

press insert key again and repeat this procedure until your subtitle file is finished.

Navigate to File->Save As and save this subtitle file as a Subrip (.srt) file, using utf-8 encoding

always give your subtitle file the same filename as your video file, but the extension .srt instead of .avi so that your media player software will display the subtitle automatic if you open the video file. (Look in the preferences menu of your media player software to make sure this works).

For this instruction, i name the subtitle file as myvideo.srt

merge video with subtitles

Now it is time to permanently merge the subtitles from the .srt file into your video. The subtitles will be rendered in white color, on a gray box. You can influence the color of the box by changing the value of 200 to some other value between 0 and 255: (150 makes for a dark box, 200 makes for a very transparent box).

mencoder -oac copy -ovc raw -sub myvideo.srt -sub-bg-alpha 150 -utf8 -o  myvideo4.avi myvideo3.avi 

international fonts: in the case that some characteres get not rendered into your video you must specify exactly the font to render and it's location. If you want to use the font /usr/share/fonts/truetype/arphic/ukai.ttf write:

mencoder -oac copy -ovc raw -sub myvideo.srt -sub-bg-alpha 150 -utf8 -subfont /usr/share/fonts/truetype/arphic/ukai.ttf -o myvideo4.avi myvideo3.avi
Note that myvideo4.avi will be very big too and may also have negative colors. Make sure you have still enough space free on your harddisk
Maybe Ian will make the showmedo player capable of handling selectable subtitles for different languages so that this step is not longer necessary in the future.
If you skip this step, rename your myvideo3.avi into myvideo4.avi

optimize video

  • Now it is time to optimize the video so that it use less disk space. This wil be in two turns, for better quality. The following lines are just one gigantic long line; use the \ (Backslash) Character to continue the same command line in a new line of the terminal:
mencoder -oac copy -ovc lavc \
   -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:dia=4:predia=4:preme=2:last_pred=3:vqcomp=0.7:cbp:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:vpass=1:qns=2:vbitrate=900 \
   -ffourcc DIVX myvideo4.avi -o myvideo5.avi
This step will take very long time.
  • Now comes the second turn. This parameter -vpass is different this time:
mencoder -oac copy -ovc lavc \
   -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:dia=4:predia=4:preme=2:last_pred=3:vqcomp=0.7:cbp:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:vpass=2:qns=2:vbitrate=900 \
   -ffourcc DIVX myvideo4.avi -o myvideo5.avi
This step will also take very long

cleaning up

remove no longer needed files:

rm myvideo1.avi myvideo2.avi myvideo3.avi myvideo4.avi divx2pass.log mylogo.fifo mylogo.rgba mysound.wav myperfectsound.wav

There will be a small difference (<.1 seconds) between the video and the sound. You can read about this difference if you watch the console output. At the moment, this is a known bug and no solution is available. If you know how to work around this, please contact me and/or update this wiki.

getting help

If any command option of mencoder gives you trouble, use the mencoder help function in this way:

mencoder -vf help
This will display the help page about the -vf parameter
or check out the official mplayer documentation

If you have trouble to copy this long line from the website to your console download this script of this example and edit it using Kate or any text-editor capable of handling long lines.

other commands

not fully tested / understood:

 mencoder -o credit4.avi  -ovc copy -audiofile film.mp3  -oac pcm  credit3.avi

this line made exteral sound instead intern sound


mencoder -o credit1.avi -ss 00:00:05 -ovc copy -oac pcm -af volume=10 credit.avi

this line snipped away the first five seconds


mencoder -o credit2.avi -frames 750 -ovc copy -oac pcm -af volume=10 credit1.avi

this line snipped away all frames after frame 750. Framerate was around 10 frames/second, so you can calculate the correct frame to begin snipping.


mencoder -o myvideo1.avi -ovc copy -oac pcm -af volume=30 myvideo0.avi	+	

this command makes the video 30db louder. Check the video and use a different value, like 10 if it is too loud.

mencoder -oac copy -ovc copy -o new_movie.avi part1.avi part2.avi

this command merge the two clips part1.avi and part2.avi together into the file movie.avi

Thanks

My deep gratitude goes toward Douglas for being a linux-guru of unbelievable super-human powers who researched and tested all those cryptic commands.

back to video editing

Personal tools