problem with SHELL

Post

Posted
Rating:
#1 (In Topic #466)
Regular
bill-lancaster is in the usergroup ‘Regular’
I wish to display audio metadata contained in audio files in a folder.

Using ffprobe in a shell command.

Code

Shell "ffprobe " & PathToAudioFile
Shows the metadata in the IDE console

Code

Shell "ffprobe " & PathToAudioFile TO sVar
Produces an empty string

Code

Shell "ffprobe " & PathToAudioFile For Read As "Process"
Does not invoke Process_Read()

I must be making a simple mistake here but I can't see it.  Any help would be welcome.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Bill, I have no idea why you can't use 'process' but I can't see the need. I suggest you try the excellent 'exiftool' to do this.  I have knocked together the attached program that will pull out the details, if they are there!

NOTE: - You need to install 'exiftool'. The good part is that you can add the 'exiftool' to your own program as I did with my program PhotoExif.

<IMG src="https://www.cogier.com/gambas/MusicEXIF.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
Thank you for the excellent code but it doesn't work for me.  There is something strange with my system.
The line:-

Code

Shell "exiftool " & User.Home &/ "Music/recordings" &/ "'" & GridViewTracks[Last.Row, 0].text & "'" To sData
yields an empty string.

I'm running Gambas 3.15.1 in Kubuntu 20.04

I'll try to find out why my system is mis-behaving.

Thanks again
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’

bill-lancaster said

…I'll try to find out why my system is mis-behaving…

Hi Bill, your variable is probably empty because the process does not complete before your code proceeds to the next step. You may be able to prove this by single stepping through your code in the IDE.

If this is the case, rewrite the Shell command using the Wait keyword.
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
ffprobe has some fancy text output formatting
You could do it with redirecting the output in the command and reading in the file…
(dont forget the 'Wait' arg or you might miss the output :))

Code

Shell "ffprobe " & Quote(PathToAudioFile) & " 2>/tmp/ffoutput" Wait
sVar = File.Load("/tmp/ffoutput")
Kill "/tmp/ffoutput"
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
bill-lancaster is in the usergroup ‘Regular’
 cogier's programme didn't work first time because, stupidly,  I hadn't installed exiftool!

Thanks also for suggesting the use of WAIT.

I still get a null string when using ffprobe or ffmpeg.  If I print the shell command, copy it and run it in console it works.  Doesn't make sense.

Anyway, exiftool does the job (probably better) so I'll move on.

Small point, splitting each line of the exiftool output based on the first ":" preserves the format of date/time values, otherwise for example Duration is shown as "3" instead of "3:30:00".

Thanks for all the ideas.
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
I still get a null string when using ffprobe or ffmpeg. If I print the shell command, copy it and run it in console it works. Doesn't make sense.

Yeah ffprobe and ffmpeg output in a non standard way.  redirecting 2> often works for that.
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Guru
cogier is in the usergroup ‘Guru’
Just one point about using WAIT. There is no need to use it if you are collecting the data in a variable as Gambas will always wait so that it can fill the variable.
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
I just found this code reading through the wiki Shell info and thought i'd try it out on this scenario.

Only the standard output of the process is retrieved. The error output is not redirected.
If you need to mix both output, use the shell redirection syntax:
Shell "command 2>&1" To Result

I tried it and

Code

Shell "ffprobe " & Quote(filename) & " 2>&1" Wait To mString

DID fill mString with the output.

A bit late for the solution there I guess but that lil bit of info could help someone else in a similar situation i think.
Online now: No Back to the top
1 guest and 0 members have just viewed this.