서문
Brightcove Live 시스템은 다양한 이벤트에 대한 알림을 보냅니다. 추가 작업을 트리거하도록 알림에 대한 리스너를 설정할 수 있습니다. 리스너는 사용하는 모든 서버 측 언어로 작성 될 수 있으며 수신 POST 요청을 찾고 JSON 요청 본문을 구문 분석 한 다음 원하는 작업을 수행합니다. 아래에서 알림을 요청하는 방법을 볼 수 있습니다.
알림 요청
하나 이상을 포함하여 알림을 요청할 수 있습니다. notifications출력의 필드일자리 만들기요구.
의notifications값은 알림 대상 객체의 배열입니다. "https://httpbin.org/post" url:과 함께 간단한 문자열을 사용하거나 다음 옵션과 함께 객체를 사용할 수{"url": "https://httpbin.org/post", "credentials": "reference_to_your_credentials"}있습니다. 출력 상태가 변경되면 지정한 대상으로 알림이 전송됩니다. 이 매개 변수를 VOD 출력에 적용하면 알림은 라이브 작업이 아닌 해당 VOD 작업에만 관련됩니다.
다음은 몇 가지 예입니다.
라이브 작업에 대한 알림
{
    "live_stream": true,
    "region": "us-west-2",
    "reconnect_time": 20,
    "notifications": [
      {"url": "https://httpbin.org/post/URLA",
        "credentials": "reference_to_your_credentials",
        "event": "first_segment_uploaded"},
      {"url": "https://httpbin.org/post/URLB",
      "credentials": "reference_to_your_credentials",
      "event": "state_changed"}
      ],
    "outputs": [
    {
        "label": "hls360p",
        "live_stream": true,
        "height": 360,
        "video_bitrate": 650,
        "segment_seconds": 6
    },
    {
        "url":"s3://YOURBUCKET/path/filename.mp4",
        "credentials": "accConfiguredCredsAWSIdSecret",
        "notifications":    [
        {
            "url": "https://httpbin.org/post?vodStateChange"
        },
        {
            "url": "https://httpbin.org/post?vodFinished",
            "event": "output_finished"
        }
        ]
    }]
}
라이브 투 VOD 알림 ( output_finished이벤트 전용)
{
  "videocloud": {
    "video": {
      "name": "video name"
    }
  },
  "notifications": [{
    "url": "https://httpbin.org/post?vodFinished",
    "event": "output_finished"
  }]
}
Live to VOD 알림 (모든 이벤트)
{
  "videocloud": {
    "video": {
      "name": "video name"
    }
  },
  "notifications": [{
    "url": "https://httpbin.org/post"
  }]
}
재시도 전략
알림 전송 요청이 실패한 경우 기본 재시도 전략은 시도 사이에 기하 급수적 인 지연을두고 50 번 재 시도하는 것입니다.
          max_retry_times = 50
          delay_delta_s = 5
          next_retry = now_s + retry_count * delay_delta_s
이벤트
다음은 수신 할 수있는 작업 수명주기의 이벤트입니다. 이벤트 범위는 작업 당이므로 라이브 작업의 이벤트 수명주기는 동일한 라이브 스트림을 기반으로하는 VOD 클리핑 작업의 수명주기와 분리됩니다.
state_changed-라이브 작업 상태가 변경되었습니다. 자세한 내용은 아래 표를 참조하십시오.first_segment_uploaded-라이브 스트림의 첫 번째 세그먼트가 원본에 업로드됩니다.output_finished- 라이브 이벤트가 종료되었으며 VOD 프로세싱으로 오디오와 비디오 렌디션이 하나 이상 생성되었거나 프로그레시브 MP4 렌디션이 하나 이상 생성되었습니다.
는state_changed아래 표에 설명된 다음 상태에 대해 알립니다.
| 주 | 설명 | 
|---|---|
작업 상태 (알림에 다음과 같이state보고됨) | 
		|
error | 
			오류가 발생했습니다. 작업이 처리되지 않습니다. | 
standby | 
			(정적 진입 점 [SEP] 작업에만 적용됩니다.) 작업이 할당되고 활성화 할 준비가되었습니다. | 
waiting | 
			작업이 스트리밍 작업자에게 할당되었으며 인코더를 연결할 준비가되었습니다. | 
processing | 
			인코더가 연결되고 작업을 재생할 수 있습니다. | 
disconnected | 
			인코더 연결이 끊어졌고 스트리밍 작업자가 재 연결을 기다리고 있습니다. | 
cancelling | 
			작업이 취소되었으며 작업자가 작업을 중지하고 보류 중인 VOD 출력을 처리하지 않습니다. | 
finishing | 
			인코더 연결이 끊긴 시간이 지난 후로 스트리밍 작업자가 작업을 중단하고 관련 VOD 출력을 생성하고 있습니다. reconnect_time | 
		
cancelled | 
			작업이 성공적으로 취소되었습니다. | 
finished | 
			작업이 성공적으로 완료되었습니다. | 
failed | 
			시스템 오류로 인해 작업이 중지되었습니다. | 
VOD 작업 상태 (알림에 다음과 같이jvod_state보고됨) | 
		|
error | 
			오류가 발생했습니다. 작업이 처리되지 않습니다. | 
waiting | 
			처리 대기중인 작업입니다. | 
waiting_finish_live | 
			라이브 작업이 완료되기를 기다리는 작업입니다 (클립이 이에 종속 된 경우). | 
processing | 
			클립이 처리 중입니다. | 
creating_asset | 
			VOD 자산이 생성되고 있습니다. | 
cancelling | 
			작업이 취소되었으며 작업자가 작업을 중지하고 보류 중인 VOD 출력을 처리하지 않습니다. | 
cancelled | 
			작업이 성공적으로 취소되었습니다. | 
finished | 
			작업이 성공적으로 완료되었습니다. | 
failed | 
			시스템 오류로 인해 작업이 중지되었습니다. | 
SSAI 상태 (알림에 다음과 같이ssai_state보고됨) | 
		|
none | 
			이 작업은 SSAI 작업이 아닙니다. | 
waiting_input | 
			스트리밍 작업자는 인코더가 연결되어 스트림 입력 정보를 제공하기를 기다리고 있습니다. | 
start_transcoding | 
			인코더가 연결되었고 SSAI 슬레이트가 스트림 입력 데이터 및 출력 데이터를 기반으로 트랜스 코딩을 위해 대기열에 추가되었습니다. | 
transcoding | 
			슬레이트가 트랜스 코딩되고 있습니다. | 
error | 
			슬레이트를 다운로드하거나 트랜스 코딩 할 수 없습니다. | 
ready | 
			슬레이트가 생성되었으며 작업이 SSAI 재생 준비가되었습니다. | 
SEP 상태 (알림에 다음과 같이sep_state보고됨) | 
		|
none | 
			이 작업은 SEP 작업이 아닙니다. | 
ready | 
			진입 점이 활성화되었으며 인코더를 연결할 준비가되었습니다. | 
pending_activation | 
			스트리밍 작업자 할당을 위해 진입 점이 대기열에 추가되었습니다. | 
activation_in_progress | 
			연결을 스트리밍 작업자로 라우팅하도록 진입 점이 업데이트됩니다. | 
pending_deactivation | 
			스트리밍 워커에서 정리를 위해 진입점이 대기되었습니다. | 
deactivation_in_progress | 
			진입 점이 스트리밍 워커에서 연결을 끊고 있습니다. | 
cancelled | 
			진입 점이 취소되었습니다. | 
finished | 
			진입 점이 성공적으로 완료되었습니다. | 
RTMP 출력 상태 ( rtmp_output_state_changed알림에 대해서는 다음과 같이state보고됨) | 
		|
starting | 
			스트림이 시작 중입니다. | 
connected | 
			엔코더가 연결되었습니다. | 
Disconnected | 
			인코더가 분리되었습니다. | 
error | 
			스트림에 연결하지 못했습니다. | 
pending_deactivation | 
			스트리밍 워커에서 정리를 위해 진입점이 대기되었습니다. | 
deactivation_in_progress | 
			진입 점이 스트리밍 워커에서 연결을 끊고 있습니다. | 
cancelled | 
			진입 점이 취소되었습니다. | 
finished | 
			진입 점이 성공적으로 완료되었습니다. | 
샘플 알림
라이브 스트림 알림
다음은 실시간 작업state_changed이벤트에 대한 샘플 알림입니다.
          {
              "outputs": [
                  {
                      "rfc_6381_video_codec": null,
                      "finished_at": "2017-10-19T20:08:11.115Z",
                      "segment_seconds": 4,
                      "created_at": "2017-10-19T19:47:04.534Z",
                      "privacy": false,
                      "md5_checksum": null,
                      "audio_codec": "AAC",
                      "error_class": null,
                      "updated_at": "2017-10-19T20:08:11.115Z",
                      "video_bitrate_in_kbps": 2150.4,
                      "id": "0-621669558be84a7da4ff20bccb9a6a1a",
                      "state": "cancelled",
                      "playback_url": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_0\/chunklist.m3u8",
                      "duration_in_ms": 1156873,
                      "file_size_bytes": null,
                      "height": 720,
                      "playback_url_dvr": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_0\/chunklist_dvr.m3u8",
                      "error_message": null,
                      "video_codec": "H.264",
                      "audio_bitrate_in_kbps": 196.608,
                      "fragment_duration_in_ms": null,
                      "test": false,
                      "playback_url_vod": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_0\/chunklist_vod.m3u8",
                      "total_bitrate_in_kbps": 2347.008,
                      "format": null,
                      "label": "hls720p",
                      "frame_rate": null,
                      "video_codec_profile": "high",
                      "keyframe_interval": 60,
                      "keyframe_interval_follow_source": false,
                      "live_stream": true,
                      "channels": null,
                      "playback_added_cdns": [
                      ],
                      "width": 1280,
                      "rfc_6381_audio_codec": null,
                      "audio_sample_rate": null
                  },
                  {
                      "rfc_6381_video_codec": null,
                      "finished_at": "2017-10-19T20:08:11.115Z",
                      "segment_seconds": 4,
                      "created_at": "2017-10-19T19:47:04.534Z",
                      "privacy": false,
                      "md5_checksum": null,
                      "audio_codec": "AAC",
                      "error_class": null,
                      "updated_at": "2017-10-19T20:08:11.115Z",
                      "video_bitrate_in_kbps": 1536,
                      "id": "1-621669558be84a7da4ff20bccb9a6a1a",
                      "state": "cancelled",
                      "playback_url": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_1\/chunklist.m3u8",
                      "duration_in_ms": 1156873,
                      "file_size_bytes": null,
                      "height": 540,
                      "playback_url_dvr": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_1\/chunklist_dvr.m3u8",
                      "error_message": null,
                      "video_codec": "H.264",
                      "audio_bitrate_in_kbps": 196.608,
                      "fragment_duration_in_ms": null,
                      "test": false,
                      "playback_url_vod": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_1\/chunklist_vod.m3u8",
                      "total_bitrate_in_kbps": 1732.608,
                      "format": null,
                      "label": "hls540p",
                      "frame_rate": null,
                      "video_codec_profile": "main",
                      "keyframe_interval": 60,
                      "keyframe_interval_follow_source": false,
                      "live_stream": true,
                      "channels": null,
                      "playback_added_cdns": [
                      ],
                      "width": 960,
                      "rfc_6381_audio_codec": null,
                      "audio_sample_rate": null
                  },
                  {
                      "rfc_6381_video_codec": null,
                      "finished_at": "2017-10-19T20:08:11.115Z",
                      "segment_seconds": 4,
                      "created_at": "2017-10-19T19:47:04.534Z",
                      "privacy": false,
                      "md5_checksum": null,
                      "audio_codec": "AAC",
                      "error_class": null,
                      "updated_at": "2017-10-19T20:08:11.115Z",
                      "video_bitrate_in_kbps": 819.2,
                      "id": "2-621669558be84a7da4ff20bccb9a6a1a",
                      "state": "cancelled",
                      "playback_url": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_2\/chunklist.m3u8",
                      "duration_in_ms": 1156873,
                      "file_size_bytes": null,
                      "height": 360,
                      "playback_url_dvr": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_2\/chunklist_dvr.m3u8",
                      "error_message": null,
                      "video_codec": "H.264",
                      "audio_bitrate_in_kbps": 196.608,
                      "fragment_duration_in_ms": null,
                      "test": false,
                      "playback_url_vod": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/profile_2\/chunklist_vod.m3u8",
                      "total_bitrate_in_kbps": 1015.808,
                      "format": null,
                      "label": "hls360p",
                      "frame_rate": null,
                      "video_codec_profile": "main",
                      "keyframe_interval": 60,
                      "keyframe_interval_follow_source": false,
                      "live_stream": true,
                      "channels": null,
                      "playback_added_cdns": [
                      ],
                      "width": 640,
                      "rfc_6381_audio_codec": null,
                      "audio_sample_rate": null
                  },
                  {
                      "playlist_type": "defaultS3",
                      "dvr_filename": "playlist_dvr.m3u8",
                      "filename": "playlist.m3u8",
                      "playback_url": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/playlist.m3u8",
                      "type": "playlist",
                      "playback_url_dvr": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/playlist_dvr.m3u8"
                  }
              ],
              "input": {
                  "finished_at": "2017-10-19T20:08:11.115Z",
                  "created_at": "2017-10-19T19:47:04.534Z",
                  "privacy": false,
                  "md5_checksum": null,
                  "audio_codec": null,
                  "error_class": null,
                  "updated_at": "2017-10-19T20:08:11.115Z",
                  "video_bitrate_in_kbps": null,
                  "id": "input-621669558be84a7da4ff20bccb9a6a1a",
                  "state": "cancelled",
                  "duration_in_ms": 1156873,
                  "file_size_bytes": null,
                  "audio_tracks": null,
                  "height": null,
                  "error_message": null,
                  "video_codec": null,
                  "audio_bitrate_in_kbps": null,
                  "test": false,
                  "total_bitrate_in_kbps": null,
                  "format": null,
                  "frame_rate": null,
                  "url": null,
                  "channels": null,
                  "width": null,
                  "audio_sample_rate": null
              },
              "event": "state_changed",
              "job": {
                  "event_length": 0,
                  "static": false,
                  "finished_at": "2017-10-19T20:08:11.115Z",
                  "test": false,
                  "submitted_at": "2017-10-19T19:47:04.534Z",
                  "created_at": "2017-10-19T19:47:04.534Z",
                  "privacy": false,
                  "out_worker_bytes_rate": 0,
                  "ad_insertion": false,
                  "metadata_passthrough": false,
                  "live_stream": true,
                  "out_worker_bytes": 147114065,
                  "live_dvr_sliding_window_duration_ms": 57600000,
                  "updated_at": "2017-10-19T20:08:11.115Z",
                  "encryption": [
                  ],
                  "live_dvr_sliding_window_duration_ms": 57600000,
                  "ssai_state": "none",
                  "id": "621669558be84a7da4ff20bccb9a6a1a",
                  "state": "cancelled",
                  "playback_url": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/playlist.m3u8",
                  "region": "us-west-2",
                  "reconnect_time": 1800,
                  "playback_url_dvr": "https:\/\/bcovlive-a.akamaihd.net\/621669558be84a7da4ff20bccb9a6a1a\/us-west-2\/NA\/playlist_dvr.m3u8"
              }
          }
          
S3 샘플로 클리핑
다음은 클립을 생성하여 S3 버킷으로 전송하기 위한 샘플state_changed이벤트입니다. 참고로 여기에는 클립의 S3 주소가 다음과 같이 포함되어jvod_url있습니다.
          {
              "jvod_id": "b750cce9e21a4cc894c4507208495b0c",
              "jvod_url": "s3:\/\/some.bucket\/test_dur60.mp4",
              "jvod_created_at": 1517520650785,
              "jvod_duration_s": 30,
              "jvod_cancelling_flag": false,
              "label": "last_30",
              "jvod_reported_duration_s": null,
              "jvod_finished_at": 0,
              "jvod_type": "s3",
              "account_id": "a95ac581551b4478b27910e5675db1f8",
              "jvod_worker_id": "b55b6fec738e4d2788544d3233b5ecf6",
              "user_id": "c2691d4d039040be96c190a949d754a7",
              "job_id": "7005c6e07bc24ca7b69b6b9d24052720",
              "jvod_last_state_change_at": 1517520652312,
              "jvod_region": "us-west-2",
              "cloud_id": "301c91a5d9254b5d944b108c355f12be",
              "event": "state_changed",
              "jvod_state": "processing"
          }
알림 처리
알림을 받으려면 HTTP/HTTPS POST요청을 수신할 수 있는 앱만 있으면 됩니다. 그런 다음 앱은 JSON 알림을 구문 분석하고 내용에 따라 원하는대로 수행 할 수 있습니다.
간단한 예로서 Brightcove Learning Services에서 알림을 수신하고 텍스트 파일에 작성하는 데 사용하는 PHP 앱이 있습니다.
           <  ?PHP
            //JSON 데이터에 대해 POST가 작동하지 않음
            $ 문제 = “오류 없음”;
            $ notificationType = null;
            {
                $json = 파일_겟_콘텐츠 ('php: //입력');
                $ 디코딩 = json_decode ($ JSON, 사실);
                //알림을 예쁜 인쇄 된 JSON으로 변환
                $ 알림 = json_인코딩 ($ 디코딩, JSON_PRETTY_인쇄);
            } catch (Exception $e) {
                $ problem = $ e ---> getMessage ();
                $ notification = $ json;
            }
            $ logEntry = $ notification. "\\ n \\ n";
            //PHP가 로그 파일을 찾을 수 있는 위치를 알려주고 PHP에 열도록 지시합니다.
            //이전에 만든 문자열을 추가합니다.
                $ logFileLocation = "live-log.txt";
                $ 파일 핸들 = fopen ($ 로그 파일 위치, 'a') 또는 다이 (“-1");
                fwrite ($ fileHandle, $ logEntry);
                fclose ($ fileHandle);
            //앱을 직접 탐색할 때 아래 줄이 표시됩니다.
            echo "라이브 콜백 앱이 실행 중입니다.";
            ?>
          
참고
- 경우에 따라 동일한 알림이 두 번 이상 전송됩니다. 핸들러가 알림을 기반으로 작업을 수행하는 경우 (단순 로깅은 제외) 중복 항목 (동일한
id및 AND를 가진 여러 알림status) 을 확인하고 무시하도록 구성해야 합니다. 
라이브 모듈에서 알림 설정
라이브 모듈에서 생성 된 라이브 이벤트에 대한 알림을 설정하려면 다음을 수행해야합니다.
- 이전 섹션에 표시된 PHP 앱과 같은 POST 요청을 수신 할 수있는 핸들러 애플리케이션을 만듭니다.
 - 공개 URL에서 앱을 호스팅합니다.
 - 라이브 모듈에서 라이브 작업을 생성할 때고급 옵션을 확장하십시오 .
 - 스트림 상태 알림활성화 옵션을선택하고 핸들러 앱의 URL을 입력합니다.
	
	라이브 모듈에서 알림 활성화