首页 > 解决方案 > PHP - Actively refresh exec function result?

问题描述

Im unexperienced in this way of using PHP, but Id like to like, create some variable for example $test, which would be exec("ffmpeg ...") as we know, ffmpeg does actively change its result, while PHP just waits till the command is finished, is there an option, that I would execute the command and by refreshing the page get active form of the result, since Id like to make a progress bar and things, but that seems to be impossible to me right now. I have tried basic things, but as I see, I have no idea how to do, it any suggestions how to make that? Please just do not close this, it is actually really hard for me to do these things and everytime people literally just reject me here with my questions

标签: phpffmpeg

解决方案


Since your question is so broad I can only give you a broad answer showing the basic steps for the ffmpeg part of your question (also I don't know PHP). It should be enough info for you to be able to implement it into your script.

Use -progress

You can use the -progress global option in ffmpeg to continuously output progress information to a text file:

ffmpeg -progress progress.txt -i input.avi output.mp4

From the documentation:

-progress url (global)
Send program-friendly progress information to url.

Progress information is written approximately every second and at the end of the encoding process. It is made of key=value lines. A key consists of only alphanumeric characters. The last key of a sequence of progress information is always progress.

Example output

Example excerpt from the progress file:

frame=106
fps=23.33
stream_0_0_q=28.0
bitrate=   0.2kbits/s
total_size=48
out_time_us=2080078
out_time_ms=2080078
out_time=00:00:02.080078
dup_frames=0
drop_frames=0
speed=0.458x
progress=continue

Note that this is only helpful if you know what the final duration or number of frames that the output will be. If you know your input and output will have approximately the same duration or frames then you should have no problem using it. But of course it depends on your command.

Getting duration or frames

Once you know the duration or number of frames you can utilize frame or out_time_ms to determine the progress for the queried interval.

You can use ffprobe to determine input info:

Also see:


推荐阅读