Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Script for batch mencoder command

  1. #1
    Join Date
    Jun 2005
    Location
    Belgium
    Beans
    148
    Distro
    Ubuntu

    Script for batch mencoder command

    First of all, I am not familiar with shell scripting, so I'm asking for your help. I want to do
    mencoder aVideoFile.avi -of mpeg -oac lavc -lavcopts acodec=mp2:abitrate=192 -af resample=44100:0:0 -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=50 -vf scale,harddup -ofps 25 -zoom -xy 176 -o aVideoFile.mpg
    for all files in /media/ipod and its subdirectories. How can I do that?

  2. #2
    Join Date
    Apr 2005
    Location
    Austria
    Beans
    246
    Distro
    Kubuntu

    Re: Script for batch mencoder command

    Code:
    find /media/ipod -type f -exec mencoder {} -of mpeg -oac lavc -lavcopts acodec=mp2:abitrate=192 -af resample=44100:0:0 -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=50 -vf scale,harddup -ofps 25 -zoom -xy 176 -o {}.mpg \;
    johannes.truschnigg.info - meine Website.

  3. #3
    Join Date
    Jun 2005
    Location
    Belgium
    Beans
    148
    Distro
    Ubuntu

    Re: Script for batch mencoder command

    Thanks. There's one more thing I want to do: if both FILENAME.avi and FILENAME.avi.mpg exist, don't let mencoder convert the file again since it has already been converted. Is that possible by, perhaps, adding a "do-not-overwrite" parameter to the mencoder command?

  4. #4
    Join Date
    Feb 2007
    Beans
    2,729

    Re: Script for batch mencoder command

    Do you want FILENAME.avi to convert to FILENAME.mpg or FILENAME.avi.mpg ?

    Sometimes the find command gets too difficult to use to build complex commands, so its better to use find in combination with a shell script. The shell script does the basic job of encoding the file, but only if the file.mpg does not exist. The find command is responsible for sending do_encode the filenames to work on.

    Here's your new find command:

    Code:
    find /media/ipod  -name '*.avi' -type f  -exec ~/do_encode {} \;
    it will call a shell script called do_encode, which you will create as follows:

    Code:
    #!/bin/bash
    
    function encode
    {
        echo mencoder "$1" -o "$2" -of mpeg -oac lavc -lavcopts \
            acodec=mp2:abitrate=192 -af resample=44100:0:0 \
           -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=50 \
           -vf scale,harddup -ofps 25 -zoom -xy 176
    }
    
    mpg=$(echo $1 | sed 's/\.avi$/\.mpg/')
    if [ -e "$mpg" ] ; then
        echo $1 already encoded to $mpg
    else
        encode "$1" "$mpg"
    fi
    Save the code above into a file named do_encode in your home directory, and changer permissions on it:

    Code:
    chmod a+x ~/do_encode
    MrC
    Last edited by Mr. C.; August 13th, 2008 at 08:00 PM.

  5. #5
    Join Date
    Jun 2005
    Location
    Belgium
    Beans
    148
    Distro
    Ubuntu

    Re: Script for batch mencoder command

    Do you want FILENAME.avi to convert to FILENAME.mpg or FILENAME.avi.mpg ?
    I think FILENAME.avi.mpg is easier for the program to recognize, so I'll use that format.

    Does this work? ipodConvert:
    Code:
    #! /bin/bash
    find /media/ipod -wholename *.avi -exec mencoderAVI {} \;
    find /media/ipod -wholename *.mp4 -exec mencoderMP4 {} \;
    find /media/ipod -wholename *.mov -exec mencoderMOV {} \;
    mencoderAVI:
    Code:
    #!/bin/bash
    
    function encode
    {
        echo mencoder "$1" -o "$2" -of mpeg -oac lavc -lavcopts \
            acodec=mp2:abitrate=192 -af resample=44100:0:0 \
           -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=100 \
           -vf scale,harddup -ofps 25 -zoom -xy 176
    }
    
    mpg=$(echo $1 | sed 's/\.avi$/\.mpg/')
    if [ -e "$mpg" ] ; then
        echo $1 already encoded to $mpg
    else
        encode "$1" "$mpg"
    fi
    Same for mencoderMP4 and mencoderMOV, but I replaced
    Code:
    mpg=$(echo $1 | sed 's/\.avi$/\.mpg/')
    with
    Code:
    mpg=$(echo $1 | sed 's/\.mp4$/\.mpg/')
    and
    Code:
    mpg=$(echo $1 | sed 's/\.mov$/\.mpg/')
    ipodConvert and the mencoder scripts are included in $PATH.

  6. #6
    Join Date
    Feb 2007
    Beans
    2,729

    Re: Script for batch mencoder command

    It doesn't sound like there is a question here. You have it under control ?

    MrC

  7. #7
    Join Date
    Jun 2005
    Location
    Belgium
    Beans
    148
    Distro
    Ubuntu

    Re: Script for batch mencoder command

    I customized the script a little bit to suit my needs. I have a problem though:
    pdedecker@BETAubuntu:~/Scripts$ vipodconv
    [Skipped] /media/ipod/Video/EY5-full.avi
    [Skipped] /media/ipod/Video/EY6-full.avi
    [Skipped] /media/ipod/Video/EY7-full.avi
    [Skipped] /media/ipod/Video/EY3-full.avi
    [Skipped] /media/ipod/Video/EY4-full.avi
    [Skipped] /media/ipod/Podcasts/Family's Naturally Sadie/0111 - Spring break.mp4
    [Skipped] /media/ipod/Podcasts/Family's Naturally Sadie/0112 - Family and Friends.mp4
    [Convert] /media/ipod/Podcasts/- Video Package - A PodShow Channel/commandN Episode 83.mp4
    MEncoder 2:0.99+1.0pre8-0ubuntu8 (C) 2000-2006 MPlayer Team
    CPU: Intel(R) Celeron(R) CPU 2.40GHz (Family: 15, Model: 3, Stepping: 4)
    CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    File not found: '"/media/ipod/Podcasts/-'
    Failed to open "/media/ipod/Podcasts/-.
    Cannot open file/device.

    Exiting...
    As you can see, mencoder is having trouble interpreting a directory name that contains the - symbol. Do you know how I can fix this?

    This is vipodconv:
    Code:
    #! /bin/bash
    find /media/ipod -wholename *.avi -exec vipodconv_mencoder "{}" \;
    find /media/ipod -wholename *.mp4 -exec vipodconv_mencoder "{}" \;
    find /media/ipod -wholename *.mov -exec vipodconv_mencoder "{}" \;
    find /media/ipod -wholename *.m4v -exec vipodconv_mencoder "{}" \;
    This is vipodconv_mencoder:
    Code:
    #!/bin/bash
    
    function encode
    {
        mencoder \"$1\" -o \"$1.mpg\" -of mpeg -oac lavc -lavcopts \
            acodec=mp2:abitrate=192 -af resample=44100:0:0 \
           -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=100 \
           -vf scale,harddup -ofps 25 -zoom -xy 176 -quiet
    }
    
    if [ -e "$1.mpg" ] ; then
        echo [Skipped] $1
    else
        echo [Convert] $1
        encode "$1" "$1.mpg"
    fi
    Again: both programs are accessible via the $PATH stuff.
    And by the way, can mencoder also handle M4V files?

  8. #8
    Join Date
    Feb 2007
    Beans
    2,729

    Re: Script for batch mencoder command

    When you escaped the quotes with backslashes in

    Code:
    mencoder \"$1\" -o \"$1.mpg\"
    you removed the ability to protect the value passed as $1. The double quotes are required so that mencoder gets exactly what was passed inside $1.

    I don't know what mencoder does with its arguments. See if you can pass a filename that contains a dash directly to mencoder itself. I also have no idea what mencoder can handle. Search the web for mencoder to find its home page. Perhaps its this: http://www.mplayerhq.hu/DOCS/HTML-si....html#mencoder

    MrC

  9. #9
    Join Date
    Aug 2006
    Beans
    7

    Re: Script for batch mencoder command

    I'm trying to do something similar with FFMPEG, but I can't seem to make it work following this thread as an example. Here is what I'd like to do:

    I'd like to be able to run a script named "encode" in any given directory and have it take all the files in the directory that I execute the script from and have it run this:

    ffmpeg -i inputfile.avi -ab 128 -b 1000 -vcodec mpeg4 -s 360x240 -deinterlace outputfile.avi

    where inputfile.avi is every file in the directory, and all of the encoded output files go into a subdirectory called /output retaining their original file names.

    Is this possible to do? I'd really appreciate any help, I have about 500 home video files that I captured with Kino that I'm trying to encode and I can't find an easy way to do it.

  10. #10
    Join Date
    Feb 2007
    Beans
    2,729

    Re: Script for batch mencoder command

    Put this in a file called ~/encode:

    Code:
    #!/bin/bash
    
    mkdir output
    for movie in *.avi ; do
        echo Processing $movie
        ffmpeg -i $movie -ab 128 -b 1000 -vcodec mpeg4 -s 360x240 -deinterlace output/$movie
    done
    Run this command to make it executable:
    Code:
    chmod a+x encode
    and then run encode from inside your movie directory.
    Code:
    cd moviedir
    ~/encode
    MrC

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •