It is currently Thu Jan 21, 2021 5:54 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RunProgram, command line and MacOS
PostPosted: Tue Nov 03, 2020 11:18 am 
Offline
Addict
Addict

Joined: Wed Feb 28, 2007 9:13 am
Posts: 1084
Location: London
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:
*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.

_________________
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."


Top
 Profile  
Reply with quote  
 Post subject: Re: RunProgram, command line and MacOS
PostPosted: Tue Nov 03, 2020 6:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 672
Location: Cologne, Germany
Quote:
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:
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.

_________________
Regards,
JamiroKwai


Top
 Profile  
Reply with quote  
 Post subject: Re: RunProgram, command line and MacOS
PostPosted: Tue Nov 03, 2020 6:46 pm 
Offline
Addict
Addict

Joined: Wed Feb 28, 2007 9:13 am
Posts: 1084
Location: London
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.

_________________
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."


Top
 Profile  
Reply with quote  
 Post subject: Re: RunProgram, command line and MacOS
PostPosted: Wed Nov 04, 2020 7:45 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 672
Location: Cologne, Germany
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.

_________________
Regards,
JamiroKwai


Top
 Profile  
Reply with quote  
 Post subject: Re: RunProgram, command line and MacOS
PostPosted: Mon Nov 09, 2020 6:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jan 12, 2011 3:48 pm
Posts: 229
Location: Serbia
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'.

_________________
PB examples collection
pb-osx-globalhotkeys
pb-osx-notifications


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye