Re: NSTask argument list

2016-06-26 Thread Graham Cox

> On 26 Jun 2016, at 4:58 PM, Sandor Szatmari  
> wrote:
> 
> You can either asynchronously monitor the task's output with notifications, 
> or I have read about a new API, but never used it, 
> -setReadabilityHandler:^(NSFileHandle* file)
> 
> Sandor
> 


Thanks!

I was able to set a readability handler on a NSPipe, set as stdout for the 
NSTask. ffmpeg has a -progress option which spews a bit of easily-parsed text 
to the pipe, so I was able to extract the info I wanted from that. All pretty 
straightforward in the end.

—Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-26 Thread Sandor Szatmari
Graham,

> On Jun 26, 2016, at 01:29, Graham Cox  wrote:
> 
> 
>> On 26 Jun 2016, at 3:22 PM, dangerwillrobinsondan...@gmail.com wrote:
>> 
>> If it helps, you can think of it  as an object oriented wrapped around C 
>> system calls that keeps track of PID and all the other bits like stdout and 
>> so on. 
>> That helps to grok why the args is and array and the tool is separate.
> 
> 
> Yep, it makes perfect sense, and is a good fit for my needs.
> 
> A follow up question, but this may be something that I’ll just have to grok 
> from the ffmpeg documentation - is there a way to get feedback from the 
> ffmpeg tool while it’s running, via NSTask? It writes a log to stderr, and 
> there are settings to control how verbose that is, but it would be necessary 
> to parse the text output to look for specific things. I need to know whether 
> the input stream has finished, or how big the output file has become. The 
> latter I may be able to do by looking at the file itself, not sure about the 
> first bit.

You can either asynchronously monitor the task's output with notifications, or 
I have read about a new API, but never used it, 
-setReadabilityHandler:^(NSFileHandle* file)

Sandor
> 
> —Graham
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-26 Thread Sandor Szatmari
Graham,

> On Jun 25, 2016, at 23:37, Graham Cox  wrote:
> 
> HI all,
> 
> I am using NSTask to wrap ffmpeg, the video conversion utility.
> 
> I am able to invoke ffmpeg alright, but it’s unclear how the argument list 
> should be passed through NSTask. I tried making my various arguments into one 
> big string, but ffmeg doesn’t parse it, instead writing an error.
> 
> Here’s my code:
> 
>NSString* execPath = [[[self class] ffMPEGURL] path];
>
>NSString* argString = [NSString stringWithFormat:@"-i \"%@\" -c copy %@", 
> [url absoluteString], [self.outputFileURL absoluteString]];
>
>self.ffMPEGTask = [NSTask launchedTaskWithLaunchPath:execPath 
> arguments:@[argString]];

I believe you would pass the args to NSTask as follows.

self.ffMPEGTask = [NSTask launchedTaskWithLaunchPath:execPath 
arguments:@[@"-i",  [url absoluteString], @"-c", [self.outputFileURL 
absoluteString]]];

Type this in mail so it may not be exactly correct, but you get the idea.  Each 
token in your argument list is put in the argument array individually.

Sandor
> 
> 
> What the argument string should look like is:
> 
> -i  -c copy 
> 
> 
> ffmpeg responds:
> 
> Unrecognized option 'i "http://" -c copy file:/// file>'.
> Error splitting the argument list: Option not found
> 
> 
> Obviously I need to pass the arguments differently, but it’s not clear what I 
> need to do.
> 
> —Graham
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-25 Thread Graham Cox

> On 26 Jun 2016, at 3:22 PM, dangerwillrobinsondan...@gmail.com wrote:
> 
> If it helps, you can think of it  as an object oriented wrapped around C 
> system calls that keeps track of PID and all the other bits like stdout and 
> so on. 
> That helps to grok why the args is and array and the tool is separate. 


Yep, it makes perfect sense, and is a good fit for my needs.

A follow up question, but this may be something that I’ll just have to grok 
from the ffmpeg documentation - is there a way to get feedback from the ffmpeg 
tool while it’s running, via NSTask? It writes a log to stderr, and there are 
settings to control how verbose that is, but it would be necessary to parse the 
text output to look for specific things. I need to know whether the input 
stream has finished, or how big the output file has become. The latter I may be 
able to do by looking at the file itself, not sure about the first bit.

—Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-25 Thread dangerwillrobinsondanger
If it helps, you can think of it  as an object oriented wrapped around C system 
calls that keeps track of PID and all the other bits like stdout and so on. 
That helps to grok why the args is and array and the tool is separate. 

Sent from my iPhone

> On Jun 26, 2016, at 1:37 PM, Graham Cox  wrote:
> 
> Ah thanks Marco, Andy… this makes a lot more sense and works fine.
> 
> ―Graham
> 
> 
>>> On 26 Jun 2016, at 2:30 PM, Marco S Hyman  wrote:
>> 
>> I believe arguments is an array of arguments, not an array containing a 
>> string that matches a command line.
>> 
>> Then your arguments array should contain five items.
>> 
>> 1: -i
>> 2: 
>> 3: -c
>> 4: copy
>> 5: 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/dangerwillrobinsondanger%40gmail.com
> 
> This email sent to dangerwillrobinsondan...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-25 Thread Graham Cox
Ah thanks Marco, Andy… this makes a lot more sense and works fine.

—Graham


> On 26 Jun 2016, at 2:30 PM, Marco S Hyman  wrote:

> I believe arguments is an array of arguments, not an array containing a 
> string that matches a command line.
> 
> Then your arguments array should contain five items.
> 
> 1: -i
> 2: 
> 3: -c
> 4: copy
> 5: 
> 
> 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-25 Thread Marco S Hyman
> 
>   NSString* argString = [NSString stringWithFormat:@"-i \"%@\" -c copy 
> %@", [url absoluteString], [self.outputFileURL absoluteString]];
>   
>   self.ffMPEGTask = [NSTask launchedTaskWithLaunchPath:execPath 
> arguments:@[argString]];

I believe arguments is an array of arguments, not an array containing a string 
that matches a command line.

> What the argument string should look like is:
> 
> -i  -c copy 

Then your arguments array should contain five items.

1: -i
2: 
3: -c
4: copy
5: 



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSTask argument list

2016-06-25 Thread Andy Lee
Don't glom the arguments together.  Pass each as a separate array
element: "-i", the URL string, "-c", "copy", the output string.
 
And you don't need to quote the arguments, just pass them as is.
 
I hope that makes sense -- I'd make it more code-like if I were at my
desk rather than on my phone.
 
--Andy
 
 
On Sat, Jun 25, 2016, at 11:37 PM, Graham Cox wrote:
> HI all,
>
> I am using NSTask to wrap ffmpeg, the video conversion utility.
>
> I am able to invoke ffmpeg alright, but it’s unclear how the argument
> list should be passed through NSTask. I tried making my various
> arguments into one big string, but ffmeg doesn’t parse it, instead
> writing an error.
>
> Here’s my code:
>
>   NSString* execPath = [[[self class] ffMPEGURL] path];
>
>   NSString* argString = [NSString stringWithFormat:@"-i \"%@\" -c
>   copy %@", [url absoluteString], [self.outputFileURL
>   absoluteString]];
>
>   self.ffMPEGTask = [NSTask launchedTaskWithLaunchPath:execPath
>   arguments:@[argString]];
>
>
> What the argument string should look like is:
>
> -i  -c copy 
>
>
> ffmpeg responds:
>
> Unrecognized option 'i "http://" -c copy
> file:///'.
> Error splitting the argument list: Option not found
>
>
> Obviously I need to pass the arguments differently, but it’s not clear
> what I need to do.
>
> —Graham
>
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com
>
> This email sent to ag...@mac.com
 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

NSTask argument list

2016-06-25 Thread Graham Cox
HI all,

I am using NSTask to wrap ffmpeg, the video conversion utility.

I am able to invoke ffmpeg alright, but it’s unclear how the argument list 
should be passed through NSTask. I tried making my various arguments into one 
big string, but ffmeg doesn’t parse it, instead writing an error.

Here’s my code:

NSString* execPath = [[[self class] ffMPEGURL] path];

NSString* argString = [NSString stringWithFormat:@"-i \"%@\" -c copy 
%@", [url absoluteString], [self.outputFileURL absoluteString]];

self.ffMPEGTask = [NSTask launchedTaskWithLaunchPath:execPath 
arguments:@[argString]];


What the argument string should look like is:

-i  -c copy 


ffmpeg responds:

Unrecognized option 'i "http://" -c copy file:///'.
Error splitting the argument list: Option not found


Obviously I need to pass the arguments differently, but it’s not clear what I 
need to do.

—Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com