LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Linux Answers > Applications / GUI / Multimedia
User Name
Password

Notices

By Steel_J at 2006-05-03 00:09
A lot of users have TV shows captured as MPEG files on their systems or personal video recorder.

I built a PVR that record's the satellite with an hardware MPEG2 encoder PCI card. It's all fine when I want to watch the shows within the week but for those shows I want to keep for later I convert them to high quality AVI files and transfer them elsewhere. Otherwise MPEG files take a lot of disk space.

Here is a little script I wrote to batch convert all MPEG files within a folder to quality AVI videos.

The only requirement for the script is mplayer. You can modify the "vbitrate" variable yourselves. I set it to 1100 because it produces a 500-550MB files from a one hour tv show. I find this to be a reasonable ratio between size and quality.

Copy and paste this code to a text file and name it "mpg2avi". You can then copy this file to /USR/LOCAL/BIN. Set permissions like so as root in a console: "chmod +rx mpg2avi" (without the quotes).

You can then run this in console from any directory and it will convert all MPEG files in it.

code:
Code:
#!/bin/bash

#mpg2avi (Convert mpeg streams into high quality mpeg4 avi with mp3 audio)

#requirements: mplayer

#Begin
clear

# variables
version=0.2b

current_directory=$( pwd )
# video bitrate (1100 = around 500 MB movie size)
vbitrate=1100

echo -e "* mpg2avi v${version}"

# remove spaces
for i in *.[Mm][Pp][Gg]; do mv "$i" `echo $i | tr ' ' '_'`; done > /dev/null 2>&1 &

# remove uppercase
for i in *.[Mm][Pp][Gg]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done > /dev/null 2>&1 &

# convert mpg movies into avi's with mencoder
for i in *.[Mm][Pp][Gg]; do nice -n 10 mencoder $i -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$vbitrate:vhq:vqmin=2:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01 -vf pp=md  -vop scale=640:480, -oac lavc -lavcopts acodec=mp3:abitrate=128 -o "`basename "$i"`.avi";echo "Conversion done";done

exit;



All times are GMT -5. The time now is 07:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration