1

我正在处理一些关于 PHP 的视频,使用 zencoder 对视频进行编码,将它们保存在 s3 上,然后在完成后通知我的网站。一切正常,直到我必须处理以 json 形式返回的通知并将新 url 拉出到保存的视频。

这个:

$notification = $zencoder->notifications->parseIncoming();

if($notification->job->state == "finished")
{
    $encode_id=$notification->job->id;
}

工作正常。我只需要一些关于访问 url 的指示。

通知发送为:

{
    "output": {
        "frame_rate": 30.0,
        "label": "video_id_",
        "total_bitrate_in_kbps": 3115,
        "md5_checksum": null,
        "channels": "2",
        "audio_codec": "aac",
        "duration_in_ms": 4225,
        "video_codec": "h264",
        "url": "http://my_url/597bd3592bf4a9d70f04dc676c44de6d.mp4",
        "thumbnails": [{
            "label": null,
            "images": [{
                "url": "http://my_url/_key__0000.png",
                "format": "PNG",
                "dimensions": "640x360",
                "file_size_bytes": 482422
            }]
        }],
        "video_bitrate_in_kbps": 3052,
        "width": 640,
        "format": "mpeg4",
        "height": 360,
        "audio_sample_rate": 44100,
        "state": "finished",
        "audio_bitrate_in_kbps": 63,
        "id": 41424918,
        "file_size_in_bytes": 1625847
    },
    "input": {
        "frame_rate": 30.0,
        "total_bitrate_in_kbps": 3867,
        "md5_checksum": null,
        "channels": "2",
        "audio_codec": "aac",
        "duration_in_ms": 4167,
        "video_codec": "h264",
        "video_bitrate_in_kbps": 3764,
        "width": 640,
        "format": "mpeg4",
        "height": 360,
        "audio_sample_rate": 44100,
        "state": "finished",
        "audio_bitrate_in_kbps": 103,
        "id": 22371764,
        "file_size_in_bytes": 2028809
    },
    "job": {
        "created_at": "2012-07-14T22:25:08Z",
        "test": true,
        "updated_at": "2012-07-14T22:25:47Z",
        "submitted_at": "2012-07-14T22:25:08Z",
        "pass_through": null,
        "state": "finished",
        "id": 22377083
    }
}

但类似: $video_file=$notification->output->url;没有。我错过了什么?

4

1 回答 1

2

If you don't want to use the parseIncoming method... Use:

$notification = json_decode(trim(file_get_contents('php://input')), true);

as apposed to:

$notification = $zencoder->notifications->parseIncoming();

The second paramater of 'true' will format the results as an array as apposed to an object. From there, you can access all the values like:

$notification['output']['file_size_in_bytes'];

The parseIncoming method will return a stdClass, so referencing values within it is done with:

$notification->key
于 2012-07-30T23:34:15.493 回答