Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to make a clip out of video file by playing it only for certain interval.

make_mclip.sh

#!/bin/bash

mediafile=$@
mediafile_fullpath=$PWD/./$mediafile
tmpedlfile=$(mktemp)

mplayer -edlout $tmpedlfile "$mediafile" &> /dev/null

cat $tmpedlfile | while read f
do
    startpos=$(echo $f | awk '{print $1}')
    endpos=$(echo $f | awk '{print $2}')
    length=$(echo "$endpos-$startpos" | bc)

    tmpclip=$(mktemp --suffix='.mclip' --tmpdir=$PWD)
    echo -e "$mediafile_fullpath\t$startpos\t$length" > $tmpclip

    mplayer_clip.sh "$tmpclip" &>/dev/null

    echo -n "clip name : "
    read clipname < /dev/tty

    mv -nv "$tmpclip" "$clipname.mclip"
done

echo doing rm "$tmpedlfile"

mplayer_mclip.sh

#!/bin/bash

mediafile=$(cat "$@" | awk -F'\t' '{print $1}')
startpos=$(cat "$@" | awk -F'\t' '{print $2}')
length=$(cat "$@" | awk -F'\t' '{print $3}')

mplayer -ss $startpos -endpos $length "$mediafile" &> /dev/null

But for some reason the while loop in make_mclip.sh is only run once even if $tempedlfile contains more than one line; the only exception is if the line

    mplayer_clip.sh "$tmpclip" &>/dev/null

is removed.

Whats wrong ?

ps. I would also like to know if there is already a program for this .

share|improve this question

1 Answer 1

up vote 1 down vote accepted

mplayer is "consuming" tmpedlfile remaining content. You need to add an option for it not to ignore its stdin:

mplayer -noconsolecontrols -ss $startpos -endpos $length "$mediafile" &> /dev/null
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.