Reading ffmpeg progress with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


I need to read ffmpeg progress output with php, but since ffmpeg started using chunked transfer I am not able to make it work

nginx block

#FFmpeg Report Progress
location = /progress.php
deny all;
                        chunked_transfer_encoding on;
fastcgi_keep_conn on;
fastcgi_pass fpm-php;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

I tried with this code to read it, but it doesn't work. Very old versions of ffmpeg that did not use chunked transfer worked fine


// Validate the client IP and required query parameters
if ($_SERVER["REMOTE_ADDR"] != "" || empty($_GET["stream_id"])) {
    die('Unauthorized access');

$streamId = intva
$filePath = "/var/log/ffmpeg/{$streamId}_.progress";

// Open the PHP input stream and file for writing
$handle = fopen("php://input", "r");
$file = fopen($filePath, "w");

// Initialize data block
$dataBlock = [];

// Continue to read from the input stream as long as the connection is alive
while (!feof($handle)) {
    $line = fgets($handle);
    if ($line === false || trim($line) === '') {
        continue; // Skip any empty reads or handle whitespace

    // Check if line contains '=' to ensure it's a key-value pair
    if (strpos($line, '=') === false) {
        // Optionally log or handle lines without '='
        // For example, you could write to an error log or just ignore:
        // error_log("Invalid line format: $line");

    // Parse line by line, extracting key-value pairs
    list($key, $value) = explode("=", $line, 2);
    $key = trim($key);
    $value = trim($value);
    if (!empty($key)) {
        $dataBlock[$key] = $value;
        // Write updates to file as they come
        fwrite($file, json_encode([$key => $value]) . "\n");


Can anyone help me or let me know if what I want to do is just not possible with php?

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux