LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-03-2008, 12:11 PM   #1
jroyce
Member
 
Registered: Nov 2007
Posts: 34

Rep: Reputation: 15
Question Script to automatically convert video files using ffmpeg


I have a Linux box which resides on the same network as my TiVo. I spend a lot of time converting video from AVI and other formats to MPEG-2 so that I can view it on my TV via the TiVo. The conversion is done via ffmpeg.

Recently, I started thinking that it would be cool to write a script which would run daily and check the contents of a particular directory for new files. If any new files exist, it would then run the ffmpeg command to convert them and place the resulting MPEG-2 in my TiVo Recordings folder.

I imagine the algorithm would look like this:

Read contents of directory (e.g. /home/user/videos/queued video
Count number of files and parse file names into an array called INPUT_NAME
Run a FOR loop which contains the following commands:

ffmpeg -i INPUT_NAME(n) -target ntsc-dvd /home/user/videos/TiVo Recordings/INPUT_NAME(n).MPG
mv INPUT_NAME(n) /home/user/videos/originals

Is it possible to do this in a perl script?

I could easily write this in Visual Basic, but I am not familiar enough with Perl to know how to handle the variables. (Is there a good tutorial?)

Also, is there a good way to schedule Perl scripts to run daily?

Thanks in advance!
 
Old 01-03-2008, 01:12 PM   #2
i_grok
Member
 
Registered: Jun 2006
Location: Massachusetts
Distribution: Gentoo
Posts: 79

Rep: Reputation: 16
Honestly, this is simple enough to do in a bash shell script. Shell scripts are just files with a list of commands that you would normally enter into a terminal manually.

That way, you can use the find utility to determine which files are less than 24 hours old and convert them.

You'll have something like:
Code:
#!/bin/bash
#
# Convert files for Tivo

DIR=/home/videos

for i in `find $DIR -type f -mmin -1440`; do

  ffmpeg -i $i -target ntsc-dvd /home/user/videos/TiVo\ Recordings/$i.MPG
  mv $i /home/user/videos/originals

done
Then create a symlink in /etc/cron.daily/ to the shell script (which will need to be executable).
 
Old 01-04-2008, 11:58 AM   #3
jroyce
Member
 
Registered: Nov 2007
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks i_grok!

This is exactly what I was looking to do. One more question: Is it fair to assume that if I change the code to read:

Code:
#!/bin/bash
#
# Convert files for Tivo

DIR=/media/TiVo/queue

for i in `find $DIR -type f *`; do

  ffmpeg -i $i -target ntsc-dvd /media/TiVo/GoBack/$i.MPG
  mv $i /media/TiVo/original

done
that the script will convert ALL files in the 'DIR' directory (not just those modified in the last 24 hours)?

Also, any tips on a good Bash Shell Script tutorial online?
 
Old 01-04-2008, 11:17 PM   #4
i_grok
Member
 
Registered: Jun 2006
Location: Massachusetts
Distribution: Gentoo
Posts: 79

Rep: Reputation: 16
You'll want the for line to read:
Code:
for i in `find $DIR -type f`; do
You don't need to use the asterisk with find - you just give it the directory to search in. Note that, by default, this will be recursive and find every file in that directory.

You can run the find command outside of the script to see what files it will return.

As far as bash tutorials, I pretty much just search for "bash tutorial" on Google whenever I need to check something. There's not a particular resource to use, except maybe for the bash manpage
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert video files milkjerry3 Linux - Newbie 3 04-04-2007 12:18 AM
MythTV automatically convert video IBall Linux - Software 3 07-16-2006 11:40 PM
mencoder/ffmpeg convert video(wmv) for Windows Mobile? paulx Linux - Software 2 06-26-2006 11:24 AM
splitting video files with ffmpeg triXlife Linux - Software 0 12-27-2005 07:29 PM
Batch convert video files KimVette Linux - General 1 08-02-2005 09:13 PM


All times are GMT -5. The time now is 04:24 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration