1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Variable in shell script

Discussion in 'Programming' started by sanyi007, Dec 5, 2009.

  1. #1
    Hi all!

    I'm a beginner, and would like to create a shell script, which will get the length of an avi file, then halves it for cutting with mencoder... here is what i have now:

    #!/bin/bash
    for file in /home/mysite/mydomain/myfiles/*.avi
    do
    moviedata= mplayer -vo dummy -ao dummy -identify $file 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d",$t/2/3600,$t/2/60%60,$t/2%60' | tail -n 1
    
    mencoder -endpos "$moviedata" -oac copy -ovc copy "$file" -o "$file.splitted.avi"
    done
    Code (markup):
    It is really close to working... if you echo $moviedata, you get the half time in a formatted way, for example: 00:32:22.
    If i insert it into mencoder, it says "Error parsing option on the command line: -endpos"

    After that, i echoed the mencoder converter line, and i saw, that the $moviedata variable moved into the beginning of the line:

    
    Here is the echoed line:
    [B]00:51:19[/B]mencoder -endpos  -oac copy -ovc copy /home/mysite/mydomain/myfiles/1.avi -o /home/mysite/mydomain/myfiles/1.avi.splitted.avi
    
    It should be like this:
    mencoder [B]-endpos  00:51:19[/B] -oac copy -ovc copy /home/mysite/mydomain/myfiles/1.avi -o /home/mysite/mydomain/myfiles/1.avi.splitted.avi
    
    Code (markup):
    I hope someone can help me to make this script working.
     
    sanyi007, Dec 5, 2009 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    try backticks

    `mencoder -endpos "$moviedata" -oac copy -ovc copy "$file" -o "$file.splitted.avi"`
    `mencoder -endpos "${moviedata}" -oac copy -ovc copy "${file}" -o "${file.splitted.avi}"`

    If you want parse literal quote, I think you need to escape it.

    which ever works

    btw there is an easier way to get duration, using ffmpeg

    ffmpeg -i ${file} 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//
     
    Kaizoku, Dec 5, 2009 IP
  3. sanyi007

    sanyi007 Peon

    Messages:
    189
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    `mencoder -endpos "$moviedata" -oac copy -ovc copy "$file" -o "$file.splitted.avi"`
    `mencoder -endpos "${moviedata}" -oac copy -ovc copy "${file}" -o "${file.splitted.avi}"`
    Code (markup):
    Hi, i tried both ways, but itdoesn't work, somehow it still ignores the data. ( $file and $file.splitted avi is accepted, only the $moviedata isn't, kinda weird, i'm sure there is something wrong with serving the variable, not the mencoder command itself)

    ffmpeg -i ${file} 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// 
    
    Code (markup):
    Well, the problem with this is that i'm just a beginner... i only want to cut movies to half, so i need to divide the whole lenght of the movie with 2, but i can't do this here because the lack of knowledge :(. If you can give me an example where i will get the half time of the movie in this format: 01:20:11 (h:m:s) i would be really glad.

    I really don't know why the first command which i found is not working, i think it is something with serving the moviedata variable, something is wrong with the way i get it, i think.
     
    Last edited: Dec 5, 2009
    sanyi007, Dec 5, 2009 IP