Page 1 of 1

RunProgram, command line and MacOS

Posted: Tue Nov 03, 2020 11:18 am
by Seymour Clufley
I'm in an awkward situation where I'm having to code an app for Windows and Mac, but I have never programmed for Mac in my life, and I don't even have a Mac computer to do development work on. I will have access to a friend's Mac in order to compile the app - but only once a day.

Luckily, 95% of my code uses PB's internal commands. The only problems I can foresee come from using external utilities - Curl, FFMPEG and SoX.

I've learned that MacOS has Curl built in. Can anyone tell me what would be the equivalent of this Windows code?

Code: Select all

*Buffer = AllocateMemory(SizeOf(Double))
prog.i = RunProgram("H:\curl.exe",param,WorkingDirectory,#PB_Program_Open|#PB_Program_Read)
While ProgramRunning(prog)
  If AvailableProgramOutput(prog)
    NumOfBytes = ReadProgramData(prog, *Buffer, SizeOf(*Buffer))
    OutputString$ + PeekS(*Buffer, NumOfBytes, #PB_UTF8)
  EndIf
  Delay(50)
Wend
CloseProgram(prog)
The other two utilities (FFMPEG and SoX) are more complicated, because they are not built into MacOS. Would they have to be installed on the user's system by an installation process, or could they simply be included with the app as standalone utilities, like on Windows?

I realise these are all "newbie" questions, but I'm guessing that asking them here is the fastest way to get the answers. I'll be grateful for any help.

Re: RunProgram, command line and MacOS

Posted: Tue Nov 03, 2020 6:26 pm
by jamirokwai
The other two utilities (FFMPEG and SoX) are more complicated, because they are not built into MacOS. Would they have to be installed on the user's system by an installation process, or could they simply be included with the app as standalone utilities, like on Windows?
I use the official ffmpeg-binary for macOS in 64 bits flavor from https://evermeet.cx/ffmpeg/, because they have one binary with all libraries embedded. Just put the ffmpeg to /full/path/to/. This is how I call it in my code to convert Full-HD MP4 to lower res MP4.

Code: Select all

File$ = "file.mp4"
Order$ = "-y -vf scale=1280x720 -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -bf 2 -c:a aac -b:a 256k -profile:a aac_low"
Output$ = "file_out.mp4"

FFMPEG = RunProgram("/full/path/to/ffmpeg", " -i " + Chr(34) + File$ + Chr(34) + " " + Order$ + " " + Chr(34) + Output$ + Chr(34), "", #PB_Program_Open | #PB_Program_Read)

If FFMPEG
	While ProgramRunning(FFMPEG)
		Delay(15)
	Wend
	result = ProgramExitCode(FFMPEG)
	CloseProgram(FFMPEG)
EndIf
You can even put it in the .App, and ship it with your binary. But add some information about the license in your program.

Re: RunProgram, command line and MacOS

Posted: Tue Nov 03, 2020 6:46 pm
by Seymour Clufley
Thanks, Jamirokwai. Does the ffmpeg executable not have a file extension on MacOS? I downloaded the Mac zip and noticed that a lot of the files don't have extensions.

Re: RunProgram, command line and MacOS

Posted: Wed Nov 04, 2020 7:45 am
by jamirokwai
Seymour Clufley wrote:Thanks, Jamirokwai. Does the ffmpeg executable not have a file extension on MacOS? I downloaded the Mac zip and noticed that a lot of the files don't have extensions.
No, they do not need an extension. As macOS is a unix*, files are marked as executables. Have a you look into an .app using Finder -> Right Click -> Show Package Content - I suspect the name, my OS is in German.

Re: RunProgram, command line and MacOS

Posted: Mon Nov 09, 2020 6:41 pm
by deseven
Two things you may find useful:
1. libcurl bindings are integrated to PB, you can just use http library instead of calling system curl binary.
2. To find out the path to system utilities, you can simply open the terminal and use 'which' for that, for example 'which curl' will give you '/usr/bin/curl'.