ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would appreciate help with a script which seems to run into problems because of nested pipes. I am trying to convert a series of cardiac ultrasound videos into flash with identifying info removed.
The ffmpeg command works well on its own for two pass encoding however as soon as I add the "find ... | while read file" pipe the script fails (BTW there are to many files so command line expansion is not an option)
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
No spaces in the file names?
Run your script with sh -x /path/to/your/script
It shows the value of all variables and you might get insight on why that is.
I recommend to avoid pipes in loops as the plague. In your original script code seems to be fine and this piping is allowed. However, in most other cases mistakes are easily made, not taking into account the piped process runs in its own subshell. Errors can be very hard to trace.
I unfortunately had to use the pipes with ffmpeg because the "croptop" option gave me an error about wrong format. I have also been unable to find info on how to use libavfilter (which apparently replaced vhook) to mask out a certain part of a video.
Quote:
done<$(find "$1" -name "*.avi" -type f -print)
This redirect gives me the following error:
Code:
line 13: $(find "$1" -name "*.avi" -type f -print): ambiguous redirect
The "bash -x script.sh" seems very useful and I was also unaware of the "< <(find ...)" construct. Strangely enough the same error happens ie when the loop repeats, the variable read into $file is truncated ie /home/user/test/video2.avi becomes /test/video2.avi.
I have solved the problem by making two scripts - maybe not very elegant but less pipes:
Code:
#!/bin/bash
#Convert avi to flash video
find "$1" -name "*.avi" -type f -print0 | xargs -0I {} ~/flv.sh '{}'
Hello,
fine you got it working.
But having to do such things to get that working seems really strange. The original script works here, does anyone get the same problem as profofol ?
Profofol, wich version of bash are you using ?
Is it always the substring "/home/user" that is removed regardless of the location of the files and of the directory of invocation ? Even if you put the files in /tmp/home/user/test/ ?
And if you remove the ffmpeg lines, I presume the $file variable is still truncated, isn't it ?
Do you use a special set of options at bash invocation ?
Does anyone know where the problem may come from or have any idea ?
My version of bash is: GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu)
When I do the same script but with
Code:
echo "abcdef" | cat -
in the place of ffmpeg statements, it works fine. Also, using variable expansion ie
Code:
for file in $(find "$1" -name "*.avi" -type f -print )
do
...
done
works as I would expect.
Also when I use:
The result of moving it to /data/test is:
Code:
~/newflv.sh /data/test/
Converting /data/test/Image-1.avi --> Image-1.flv
.... ffmpeg output ...
Converting avi --> avi.flv
// This should have been /data/test/Image-2.avi --> Image-2.flv
.... ffmpeg error - avi: no such file or directory ...
Converting /data/test/Image-3.avi --> Image-3.flv
.... ffmpeg ...
// execution stops however it should have continued to with one more avi
The file list in /data/test/ is:
Image-1.avi
Image-2.avi
Image-3.avi
Image-5.avi
the second ffmpeg continue to read stdin even when the first one doesn't produce any data (missing end of file or something ?) and then, since stdin is inherited from the parent shell, the second ffmpeg reads a part of a file name (why does it stops then, I don't know, maybe does ffmpeg read n bytes of data after some marker he read before or something ?).
So, redirecting stdin to /dev/null in the subshell should do the trick :
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.