2

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 .

1 Answer 1

2

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.