Calling FFmpeg from PHP: How to set logfile? (report)

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling FFmpeg from PHP: How to set logfile? (report)

Peter B.
Hi everyone!

I'd like to call FFmpeg from PHP, and I'm very grateful for all the
information in the Wiki [1]!
It feels like the "-report" option [2] that writes a logfile seems like
the more straightforward way to write the output to a file rather than
redirecting stdout/stderr.

However, "-report" only allows setting the filename by environment
variable - which might be a problem in some PHP environments, and it
somehow seems overkill to me...


I'd be grateful for any comments, suggestions or insights on this matter!
I was also wondering if all of the information PHP wiki article is still
up-to-date, since it was last modified 5 years ago?


Thank you very much in advance!
Peter B.


# Links:
[1] https://trac.ffmpeg.org/wiki/PHP
[2] http://ffmpeg.org/ffmpeg-all.html#Generic-options

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Paul B Mahol
On Sat, Jul 27, 2019 at 8:33 PM Peter B. <[hidden email]> wrote:

> Hi everyone!
>
> I'd like to call FFmpeg from PHP, and I'm very grateful for all the
> information in the Wiki [1]!
> It feels like the "-report" option [2] that writes a logfile seems like
> the more straightforward way to write the output to a file rather than
> redirecting stdout/stderr.
>
> However, "-report" only allows setting the filename by environment
> variable - which might be a problem in some PHP environments, and it
> somehow seems overkill to me...
>
>
> I'd be grateful for any comments, suggestions or insights on this matter!
> I was also wondering if all of the information PHP wiki article is still
> up-to-date, since it was last modified 5 years ago?
>
>
For the reasons, PHP is dead and insecure.


>
> Thank you very much in advance!
> Peter B.
>
>
> # Links:
> [1] https://trac.ffmpeg.org/wiki/PHP
> [2] http://ffmpeg.org/ffmpeg-all.html#Generic-options
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald


Am 27.07.19 um 20:45 schrieb Paul B Mahol:
> For the reasons, PHP is dead and insecure

don't drink and post!

PHP is dead?
on which planet?

PHP itself is only unsecure as every other programming language when the
programmer is an clueluess idiot, and yes: every language has it's
pitfulls you are supposed to know how to handle


_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald
In reply to this post by Peter B.


Am 27.07.19 um 20:33 schrieb Peter B.:
> However, "-report" only allows setting the filename by environment
> variable - which might be a problem in some PHP environments, and it
> somehow seems overkill to me...

https://www.php.net/manual/en/function.putenv.php
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald


Am 27.07.19 um 21:14 schrieb Reindl Harald:
>
>
> Am 27.07.19 um 20:33 schrieb Peter B.:
>> However, "-report" only allows setting the filename by environment
>> variable - which might be a problem in some PHP environments, and it
>> somehow seems overkill to me...
>
> https://www.php.net/manual/en/function.putenv.php

but how does it matter anyways?

you are supposed to use things like
https://www.php.net/manual/en/function.exec.php when you execute
binaries like ffmpeg

and yes, ignore the other idiot, execute wahter application from PHP is
fine as long as you restrict it to an instacne for special purpose while
passthru and freinds should be diabled on random webservers

not because PHP is insecure but because the power of shell commands and
power always brings responsibility
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Peter B.
Thanks for your replies! :)


On 27/07/2019 21:18, Reindl Harald wrote:
>> https://www.php.net/manual/en/function.putenv.php 
> but how does it matter anyways?

Sure I found putenv before, but as I said: It felt a bit unnecessarily
complicated ("overkill"), so I thought I'd better ask.


> you are supposed to use things like
> https://www.php.net/manual/en/function.exec.php when you execute
> binaries like ffmpeg

I know. That's what I'm doing.
btw: The PHP article in the wiki only mentions "shell_exec()" - and no
means of evaluating any exitcode to see if the FFmpeg call was
successful or not. So I found "exec()" to actually be the better option
(for me?)

So I'm now doing the following and it seems to work quite well:

1) Add "2>$logfile" at the end of the command to redirect stderr to file.
2) Use "exec($command, $output, $exitcode)" - and then check if
($exitcode != 0).

Seems to work quite well!



> [...] execute wahter application from PHP is
> fine as long as you restrict it to an instacne for special purpose while
> passthru and freinds should be diabled on random webservers
>
> not because PHP is insecure but because the power of shell commands and
> power always brings responsibility

I'm aware of PHP's shortcomings, but this is not a web application and
it only runs locally.


Thanks again for your time and for somewhat confirming my approach!

Nice greetings,
Peter B.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald


Am 27.07.19 um 22:19 schrieb Peter B.:
> Thanks for your replies! :)
>
> On 27/07/2019 21:18, Reindl Harald wrote:
>>> https://www.php.net/manual/en/function.putenv.php 
>> but how does it matter anyways?
>
> Sure I found putenv before, but as I said: It felt a bit unnecessarily
> complicated ("overkill"), so I thought I'd better ask.

what is complicated when it comes to environment variables?

what do you gain from millions of options  compare dto follow standards?

>> you are supposed to use things like
>> https://www.php.net/manual/en/function.exec.php when you execute
>> binaries like ffmpeg
>
> I know. That's what I'm doing.
> btw: The PHP article in the wiki only mentions "shell_exec()" - and no
> means of evaluating any exitcode to see if the FFmpeg call was
> successful or not. So I found "exec()" to actually be the better option
> (for me?)
>
> So I'm now doing the following and it seems to work quite well:
>
> 1) Add "2>$logfile" at the end of the command to redirect stderr to file.
> 2) Use "exec($command, $output, $exitcode)" - and then check if
> ($exitcode != 0).
>
> Seems to work quite well!

that's how unix systems are supposd to work, no matter if the cvaller is
PHP or whatever binary or scripting language
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald
In reply to this post by Peter B.


Am 27.07.19 um 22:19 schrieb Peter B.:
> I'm aware of PHP's shortcomings, but this is not a web application and
> it only runs locally.

forgot: so matter what, your webserver *never* excutes such stuff
directly so it's always some sort of crojob or systemd service starting
with "while(true)" no matter what language and using as much as possible
restricitons and namespaces

smart web applications feed databases which are the source of
services/cronjobs nd so any call to ffmpeg is *always* local

if someone don't disallow exec and friends on a webserver he deserves to
be purged - yeah, it's often more work but security don't come for free
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Jim DeLaHunt-2
In reply to this post by Peter B.
On 2019-07-27 11:33, Peter B. wrote:
> …[snip]… I was also wondering if all of the information PHP wiki article is still
> up-to-date, since it was last modified 5 years ago?
>
> …[snip]…
> # Links:
> [1] https://trac.ffmpeg.org/wiki/PHP …

Perhaps this represents an opportunity for you to easily improve the page by updating it based on what you have found out about calling ffmpeg from PHP?  Since it's stale, there should be lots of opportunity for improvements.

--
     --Jim DeLaHunt, [hidden email]     http://blog.jdlh.com/ (http://jdlh.com/)
       multilingual websites consultant

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Peter B.
On 29/07/2019 04:48, Jim DeLaHunt wrote:

> On 2019-07-27 11:33, Peter B. wrote:
>> …[snip]… I was also wondering if all of the information PHP wiki
>> article is still
>> up-to-date, since it was last modified 5 years ago?
>>
>> …[snip]…
>> # Links:
>> [1] https://trac.ffmpeg.org/wiki/PHP …
>
> Perhaps this represents an opportunity for you to easily improve the
> page by updating it based on what you have found out about calling
> ffmpeg from PHP?  Since it's stale, there should be lots of
> opportunity for improvements.

True!
I do have my Trac account and it gives me an edit button :D

Just to be noted:
This use case is merely using PHP as scripting language instead of e.g.
BASH. No Apache, no webserver, just PHP locally. This also means that
I'm not running FFmpeg execution in the background, because there's no
user waiting for a webpage to refresh.


Thanks and kind regards,
Peter

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald


Am 29.07.19 um 11:51 schrieb Peter B.:
> Just to be noted:
> This use case is merely using PHP as scripting language instead of e.g.
> BASH. No Apache, no webserver, just PHP locally. This also means that
> I'm not running FFmpeg execution in the background, because there's no
> user waiting for a webpage to refresh.

completly irrelevant, the ffmpeg binary don't care from where it was called

"using PHP as scripting language instead of e.g. BASH" - besides that
PHP implicitly starts /bin/sh in the bckground which is the reason why
you can forbid exec() and friends with
"InaccessiblePaths=-/usr/bin/bash" in a webserver unit :-)
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Peter B.
On 29/07/2019 15:48, Reindl Harald wrote:
>
> Am 29.07.19 um 11:51 schrieb Peter B.:
>> Just to be noted:
>> This use case is merely using PHP as scripting language instead of e.g.
>> BASH. No Apache, no webserver, just PHP locally. This also means that
>> I'm not running FFmpeg execution in the background, because there's no
>> user waiting for a webpage to refresh.
> completly irrelevant, the ffmpeg binary don't care from where it was called

Sure ffmpeg doesn't care where it's called from, but users who read the
"PHP" article in ffmpeg wiki may care:
since this is not the typical use case for using PHP, I'd presume.


Nice greetings!
Peter
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Calling FFmpeg from PHP: How to set logfile? (report)

Reindl Harald


Am 29.07.19 um 18:36 schrieb Peter B.:

> On 29/07/2019 15:48, Reindl Harald wrote:
>>
>> Am 29.07.19 um 11:51 schrieb Peter B.:
>>> Just to be noted:
>>> This use case is merely using PHP as scripting language instead of e.g.
>>> BASH. No Apache, no webserver, just PHP locally. This also means that
>>> I'm not running FFmpeg execution in the background, because there's no
>>> user waiting for a webpage to refresh.
>> completly irrelevant, the ffmpeg binary don't care from where it was called
>
> Sure ffmpeg doesn't care where it's called from, but users who read the
> "PHP" article in ffmpeg wiki may care:
> since this is not the typical use case for using PHP, I'd presume

well, my typical usecase of PHP is "everything where i need structure,
object orientanted programming and easy reuse" for 17 years now

IMHO the real problem is the existence of the article at all because it
answers the wrong questions - the right one is "ok, there is a cli tool,
it has this params, well, how do i nicely code a php wrapper for my
needs" and for that you don#t need anything else then "ffmpeg --help"
and "man ffmpeg"

again:
* ffmpeg don't care from were it get called
* bash, php, python... don't care what system binary they call

and if someone don't get these basics he has a hard need to realize them
*before* even consider typing any sort of code


_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".