Fedora Linux Support Community & Resources Center
  #1  
Old 31st August 2010, 12:03 PM
CraigWatson Offline
Registered User
 
Join Date: Jan 2008
Location: Witham, Essex, UK
Age: 27
Posts: 341
windows_7firefox
Bash Script Needed!

Hi Guys,
I'm looking for someone that can cobble together a Bash script to automate extracting and splicing some audio files for me. I have a folder full of multi-part RAR'd video as follows:

Video1 --> CD1 --> *.rar
Video1 --> CD2 --> *.rar

Inside the RAR is an AVI file, and I need to splice the two files together to create a full-length video.

Rough algorithm is as follows:
1) Extract CD1
2) Extract CD2
3) Splice
4) Move spliced video to new folder

There's 23 video folders, so I'd need a script to loop through each of these folders and do the above in each. I have ffmpeg and mencoder installed.

I'm fairly good with scripting, but I'm not too keen on ruining about 35GB of video!

Cheers,
Craig
__________________
Personal Website | Windows to Linux - Tips from Experience

Desktop - Galileo
Dual-Boot: Fedora 13 x64, Windows 7 x64
Intel Core2Quad Q6600 @3.6GHz, 8GB PC2-8500 DDR2, ATI HD4870, 23" @ 1920x1080 + 20" @ 1600x900 (both DVI-D), 2TB ICH10R RAID0 array, Custom Watercooling

Laptop - MacBook 5.1 ('08 Aluminium)
Dual-Boot: Fedora 13 x64, Apple OS X
Intel Core2Duo, 2GB 1066MHz DDR3, nVidia 9400M, 13" LCD @ 1280x800, 160GB SATA
Reply With Quote
  #2  
Old 31st August 2010, 01:46 PM
errorxp Offline
Registered User
 
Join Date: Jul 2007
Posts: 371
linuxfedorafirefox
Re: Bash Script Needed!

One problem with joining two videos together is that after the point where it's joined video and audio may go out of sync - this is due to the fact that sometimes the audio track is shorter than the video track. The solution is to delay the audio track of the second file by the amount that the audio and video track differ in the first file. I remember having done this in Virtualdub a long time ago. You'd have to join the video and audio track separately, then mux them together. Anyway good luck if you manage to make all this work within a single script.
__________________
these command lines are like casino slot machines, every time I input commands NOTHING HAPPENS
Reply With Quote
  #3  
Old 31st August 2010, 01:52 PM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,779
linuxfedorafirefox
Re: Bash Script Needed!

My suggestion, (I'm not familar with handling video data this way)
If you want to test what you are doing, make a copy of one of your directories
to test in. Then use the "script" utility to record what you are doing.

Perform the steps you want - and let the script utility log file record what
you do. Then you can use the log file to extract only the commands that
do the work you want (removing the test verifications...)

The end result is a script that works with only one directory.

You can now use the script 35 times... or create another script that
will set the working directory to each of the real directories and then
invoke the other script.
Reply With Quote
  #4  
Old 3rd September 2010, 07:53 PM
CraigWatson Offline
Registered User
 
Join Date: Jan 2008
Location: Witham, Essex, UK
Age: 27
Posts: 341
linuxfedorafirefox
Re: Bash Script Needed!

Just to update people, I managed to write a script to do what I wanted, but in PHP rather than Bash (string manipulation in Bash isn't my strong point!):

PHP Code:
<?php

// Path to files
$path "/tmp/Video";

// Open the directory
$dir opendir($path);

$mtime microtime();
$mtime explode(" ",$mtime);
$mtime $mtime[1] + $mtime[0];
$starttime $mtime

    
// Loop through directory
    
while (false !== ($file readdir($dir))) {
    
        
// Ignore dot-files
        
if (($file == ".") || ($file == "..") || ($file == "Final")) { continue;}
    
        
// Extract name and year
        
preg_match("/007(.*)\.(\d\d\d\d)/"$file$matches);
        
$name trim(str_replace("."," ",$matches[1]));
        
$year $matches[2];

        
// Unrar CD1
        
echo "Extracting $name CD 1\n";
        
exec("unrar e -inul -y \"$path/$file/CD1/*.rar\" \"$path/$file/\"");
        
        
// Unrar CD2
        
echo "Extracting $name CD 2\n";
        
exec("unrar e -inul -y \"$path/$file/CD2/*.rar\" \"$path/$file/\"");
        
        
// Create Final Dir
        
echo "Creating \"$year - $name\" Directory\n";
        
mkdir("$path/Final/$year - $name");
        
        
// Merge
        
$merge_path "$path/$file/";
        echo 
"Merging $name ...\n";
        echo 
"\tUsing cat\n";
        
exec("cd \"$merge_path\" && cat *.avi > \"$path/Final/$year - $name/$name-tmp.avi\"");
        echo 
"\tUsing mencoder\n";
        
exec("mencoder -forceidx -oac copy -ovc copy \"$path/Final/$year - $name/$name-tmp.avi\" -o \"$path/Final/$year - $name/$name.avi\"");
        
        
// Cleanup
        
echo "Cleaning up $name\n";
        
exec("rm -Rf \"$path/$file\"");
        
exec("rm -f \"$path/Final/$year - $name/$name-tmp.avi\"");
        echo 
"---------------------------\n";
    }
    
   
$mtime microtime();
   
$mtime explode(" ",$mtime);
   
$mtime $mtime[1] + $mtime[0];
   
$endtime $mtime;
   
$totaltime = ($endtime $starttime);
   
$totaltime round($totaltime,1);
   echo 
"Execution time: ".$totaltime." seconds\n";
   echo 
"---------------------------\n";
    
echo 
"\n";

?>
The basic algorithm is:

1) Do string manipulation to get nice clean data (mine was formatted with dots instead of spaces and with the year of the film hidden within the folder name)
2) Unrar each CD using unrar
3) Merge the CDs using cat
4) Fix the AVI headers and sync audio by using mencoder with the -forceidx flag

The manipulation in step 1 is optional, but it allows me to save the files in a nice, neat format (I'm pedantic when it comes to my movie collection!).

Any questions, by all means ask
__________________
Personal Website | Windows to Linux - Tips from Experience

Desktop - Galileo
Dual-Boot: Fedora 13 x64, Windows 7 x64
Intel Core2Quad Q6600 @3.6GHz, 8GB PC2-8500 DDR2, ATI HD4870, 23" @ 1920x1080 + 20" @ 1600x900 (both DVI-D), 2TB ICH10R RAID0 array, Custom Watercooling

Laptop - MacBook 5.1 ('08 Aluminium)
Dual-Boot: Fedora 13 x64, Apple OS X
Intel Core2Duo, 2GB 1066MHz DDR3, nVidia 9400M, 13" LCD @ 1280x800, 160GB SATA
Reply With Quote
Reply

Tags
automation, bash script, video

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash script help needed please snoopo71 Using Fedora 4 27th June 2010 01:10 PM
Bash Script Help Jamwa Using Fedora 5 17th June 2008 05:26 PM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM
[BASH] i need script coxis Programming & Packaging 2 11th June 2005 05:07 PM
Bash Script on FC3 Clunixchit Programming & Packaging 7 8th April 2005 09:29 PM


Current GMT-time: 13:10 (Saturday, 26-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat