php - 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
解决方案
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 alwaysprogress
.
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:
推荐阅读
- node.js - node npm run watch 退出状态 3221225725
- css - 在css中实现表格的最简洁方法,哪一列没有显式宽度(但包装内容),而其他列具有固定宽度?
- java - 为什么这个类是可变的?
- php - 创建子母公司 Laravel 的无限嵌套层次数组
- android - 如何在房间数据库中加入多个表
- mongodb - 您如何在 mongoose 的关联模式上对 2 个字段进行分组?
- angular - 如何在 Angular 中测试离子 Web 组件
- java - 堆栈溢出错误是否被视为内存泄漏错误?
- c# - 如何使uwp弹出全屏
- python-3.x - 如何在 Django 模型中的 C 结构中存储值