a very, very strange problem I am unable to solve - BASH
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
a very, very strange problem I am unable to solve - BASH
Hi there, nice to be here again after a long time.
I am writing a script to take snapshots of a directory full of movies when I found this strange behavior: looks like ffmpeg corrupts the script execution in some way.
The script bellow is not the original code. It is a reduced code that still have the problem.
Run it on a large folder of sub folders and files. I choose to run it on a /usr/share.
You should run it twice. On the first time, comment the ffmeg command; on the second, uncomment it. Notice how the filename is displayed differently between the runs. Obviously, in the second run the file names are corrupted at the very begin; for me, the "./" is missing. On a different set of files, more characters vanish at begin of string. At the end of set it miss even more characters (this is why I suggested to run in a large folder of files)
The input and output file for ffmpeg does not matter. Here, they are 2 fixed files. The input file is a movie (anyone you may have you should copy to /tmp as input.mp4). The output, a PNG snapshot, is always the same, overwritten each pass.
They are both on /tmp folder, just to show you the location is irrelevant and it has nothing to do with the folder where you run the script.
#!/bin/bash
find . -type f |sort | while read f; do
echo "f: ${f}"
#ffmpeg -v 8 -y -ss 12 -i "/tmp/input.mp4" -vframes 1 -q:v 2 "/tmp/out.png"
done
and changed the IFS to newline to deal with filenames with spaces, but this didn't changed the results.
I have tried to call ffmpeg as a bash function and even as a separate script. same results.
Sort of.... It worked on /usr/share folder, but not on a folder with tons of mp3 files. Look:
Code:
miguel@38Y46W1-x:/media/miguel/MUSICA-J3S$ IFS="
"
miguel@38Y46W1-x:/media/miguel/MUSICA-J3S$ for line in $(find . -type f); do echo "f: $line"; ffmpeg -v 8 -y -ss 12 -i "/tmp/input.mp4" -vframes 1 -q:v 2 "/tmp/out.png"; done
f: ./1_-_The_barber_of_Seville.mp3
f: /2_-_Willian_Tell.mp3
f: /3_-_La_gazza_ladra,_overture.mp3
f: /4_-_L_italiana_in_Algeri.mp3
f: /4-tissimo Guitar Quartet plays Tico Tico no Fubá.mp3
f: /5_-_Semiramide.mp3
f: /6_-_La_danza.mp3
f: /7_-_La_cenerentola.mp3
...
And it goes that until the end. It is missing the initial dot. At least the corruption is limited to the first char. Of course the rest of script fails because a relative path becomes an absolute one....
Anyway, why the code using "ffmpeg" has that behaviour ? Were you able to reproduce the same result ?
If yes, what do you think is the explanation ? A bug in BASH or in ffmpeg ?
cheers,
PS: And again, if I remove the ffmpeg command, there are no corruption on file names at all !
Last edited by marozsas; 11-17-2016 at 01:44 PM.
Reason: changed "while" with "ffmpeg"
What are you doing with that IFS declaration? In a brand new session, without any further changes, does the script provided still give that output in the mp3 directory?
But to re-iterate what is being discussed here. He is looking for an explanation of why the ffmpeg line in his script will mess with the directory listing.
I think some input/output redirection, as i mentioned above, might be the answer - because the good line with the ./ in front happens before ffmpeg is ever run. After the first iteration, ie after ffmpeg is run, the output does not have the . in front.
Last edited by szboardstretcher; 11-17-2016 at 03:12 PM.
"for" loops aren't what you want, "while" loops are. This should deal with spaces OK:
Code:
find $PWD -type f -iname \*.mp4| while read ITEM; do ffmpeg -v 8 -y -ss 12 -i "${ITEM}" -vframes 1 -q:v 2 "/tmp/$(basename "${ITEM}").png"; done
if unsure just use "echo" and escape quotes to see:
Code:
find $PWD -type f -iname \*.mp4| while read ITEM; do echo "ffmpeg -v 8 -y -ss 12 -i \"${ITEM}\" -vframes 1 -q:v 2 \"/tmp/$(basename "${ITEM}").png\""; done
Hi unSpawn, nice to see you here after so long !
No. Same behavior: It works for the first file and fail for the next. The initial dot is missing.
Code:
miguel@38Y46W1-x:~/Música$ find $PWD -type f | while read ITEM; do echo "file: ${ITEM}"; ffmpeg -v -8 -y -ss 12 -i "/tmp/input.mp4" -vframes 1 -q:v 2 "/tmp/$(basename "${ITEM}").png" ; done
file: /home/miguel/Música/Lovefool - Vintage Jazz Cardigans Cover ft. Haley Reinhart.mp3
file: home/miguel/Música/Hair- Aquarius.mp3
file: home/miguel/Música/Focus - Ray Charles Style Ariana Grande Cover ft. LaVance Colley.mp3
file: home/miguel/Música/Maps - Vintage 1970s Soul Maroon 5 Cover ft. Morgan James.mp3
...
Please, note I used a fixed input.mp4 file to test over a folder with mp3 files.
And I just notice this happens even on folders with just a handful of files.
So, the number of files and sub-directories is not relevant anyway....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.