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!
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:
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:
Also, any tips on a good Bash Shell Script tutorial online?
You'll want the for line to read:
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 ;)
|All times are GMT -5. The time now is 10:20 PM.|