Register
It is currently Fri Oct 24, 2014 5:17 am

Youtube ready script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Mon Jul 16, 2007 9:02 am   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
So I want to have a script that will parse my videos to youtube format. If anyone know, youtube wil let you upload videos up to 10 minutes. So if I have a longer video I need to divide it by 10 minutes each.

I want to use ffmpeg which will let me parse the video using the following command:

Code:
ffmpeg -i master_video.avi -ss 00:52:21.0 -t 00:03:25.21 new_clip.avi


Where -ss put the starting time and -t the lenght of the time of the video. So in other words I will need to build a counter on the -ss parameter -ss 00: $10min :00.0 -t 00:10:00.00 or something similar.

Can anyone suggest a script for this?


Top
 Profile WWW ICQ YIM  
 PostPosted: Mon Jul 16, 2007 2:49 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
something like this might work... let me know if this is kind of what you are looking for.
I decided to invoke ffmpeg with seconds instead of the other syntax, as it was easier.
Code:
#!/bin/bash

video="file" # this is if the file name is actually file.avi we drop the .avi
totallen="00:52:23.02" # this is the length of the movie
minChunk=10 # set this to the minute sized chunks you want

function math
{
        newNumber=`bc -l 2> /dev/null<< EOF
        scale = 2
        ${1}
        EOF
        `
        if [[ "$newNumber" == "" ]]
        then
                newNumber="bc is not installed"
        fi
        echo "$newNumber"
}

thour=`echo $totallen | cut -d: -f1`
tmin=`echo $totallen | cut -d: -f2`
tsec=`echo $totallen | cut -d: -f3`
shour=`math "$thour * 60 * 60"`
smin=`math "$tmin * 60"`
usedsec=`echo $tsec | cut -d. -f1`
decsec=`echo $tsec | cut -d. -f2`
ssec=`math "$shour + $smin + $usedsec"`

secChunk=`math "$minChunk * 60"`

lenleft=$ssec
strstart=0 # this is the start point in seconds
i=1

until [ $lenleft -lt $secChunk ]
do
        echo "ffmpeg -i ${video}.avi -ss ${strstart} -t ${secChunk} ${video}_part_${i}.avi"
#       ffmpeg -i ${video}.avi -ss ${strstart} -t ${secChunk} ${video}_part_${i}.avi
        lenleft=`math "$lenleft - $secChunk"`
        strstart=`math "$strstart + $secChunk"`
        ((i++))
        echo "${i}|${lenleft}|${strstart}"
done
strstart=`math "$strstart + .$decsec"`

echo "ffmpeg -i ${video}.avi -ss ${strstart} ${video}_part_${i}.avi"
# ffmpeg -i ${video}.avi -ss ${strstart} ${video}_part_${i}.avi

comment out the echo "ffmpeg..." and remove the comment from the ffmpeg command itself under to make it actually run and not just display the command that it would run.

Edit: I had to make changes after the loop... the way the code was, it would have tried to make the last clip wrong. I removed the -t option for the last clip as well, because it shouldn't need it, if you tell it when to start, it should just go to the end.


Top
 Profile  
 PostPosted: Sun Aug 05, 2007 11:25 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
jza, i would really appreciate if you could let me know if this helped or not. if it didnt work... we need to post as much.


Top
 Profile  
 PostPosted: Sun Aug 05, 2007 11:57 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
Yes it work. Althought....
there was just so many things to specify that I got lost and I really solve it on a far easier way using {}. Thanks the curly braces I was able to batch the generation of ouput.
[/code]


Top
 Profile WWW ICQ YIM  
 PostPosted: Mon Aug 06, 2007 11:14 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
jza wrote:
Yes it work. Althought....
there was just so many things to specify that I got lost and I really solve it on a far easier way using {}. Thanks the curly braces I was able to batch the generation of ouput.
[/code]


I'm not sure how 3 things are alot to specify, or what curly braces has to do with it... but glad you got it resolved.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP