0

I am a noob and trying to build a post processing type script for Plex. With help from some co workers and google I have put together the following script to convert mkv files to mp4 files.

The script is to "find" any and all files in the media directory and convert them to mp4 files.

It finds the first one, processes correctly and quits - why?? I need help getting this scrip to loop. I have have the quirky find command written this way so the "find" command will will capture the file name with spaces and the dirname command will work.

Script ---

find -L "/media/4tbdisk/test/" -type f -name '*.mkv' -print0 | while IFS=      read -r -d $'\0' FILE; do
echo "filename is ---" "$FILE";
DIR=$(dirname "${FILE}");
echo "directory is --" $DIR;
transcode-video --mp4 --quick "$FILE" --output "$DIR";
done

What happens is that the script will find an mkv file and process it but will not continue looping through to process the rest. If the first file it finds already has been processed the "transcode" script will say "out put file exists..." and will continue on to the next, but after it creates the first mp4 file it stops

thanks in advance haeffnkr

haeffnkr
  • 3
  • 1
  • works here. I suspect that simplifying your first line would work better: `find -L "/media/4tbdisk/test/" -type f -name '*.mkv' | while read -r FILE; do` – Jean-François Fabre Nov 04 '16 at 16:42
  • As a first test, you can try to run `find -L "/media/4tbdisk/test/" -type f -name '*.mkv'` alone (and without `-print0`) to see how many files are found – yolenoyer Nov 04 '16 at 16:45
  • Try `transcode-video < /dev/null .....`. ffmpeg and mencoder will eat stdin and cause the issue you're describing, and chances are this tool is based on one of those – that other guy Nov 04 '16 at 16:59
  • The find command works and will return several files. – haeffnkr Nov 04 '16 at 17:00

1 Answers1

0

You appear to be using this transcode-video script. It's based on HandbrakeCLI and mplayer, both of which have a tendency to overconsume stdin and thereby breaking while read loops after the first iteration (ex1, ex2, ex3, ex4).

You can avoid this by redirecting input from /dev/null so it doesn't consume any of the loop's input:

find -L "/media/4tbdisk/test/" -type f -name '*.mkv' -print0 | while IFS=      read -r -d $'\0' FILE; do
echo "filename is ---" "$FILE";
DIR=$(dirname "${FILE}");
echo "directory is --" $DIR;
transcode-video < /dev/null --mp4 --quick "$FILE" --output "$DIR";
done
Community
  • 1
  • 1
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • "that other guy" this is working :) :) :) :) :) :) :) -- big grin -- super awesome ... you rock and yes that is the script I am using and yes it is based on HandBrake. thanks a million !!!!! – haeffnkr Nov 05 '16 at 02:43