2017-12-29 91 views
0

mp4 비디오를 반환하는 끝점을 원했습니다.Slim 3에서 mp4 비디오를 반환하는 중

전체 엔드 포인트

$app->get('{userid}/clips/{clipid}/video', '\GameDVRController:clipGetVideo'); 

이었다 그리고 엔드 포인트의 기능은

public function clipGetVideo($request, $response, $args) { 
    $clipid = $args['clipid']; 
    $clip = GameClip::where('id', $clipid)->first(); 

    // (Note: clip->File is full path to file on disk) 
    $file = file_get_contents($clip->File); 
    $response->getBody()->write($file); 

    $response = $response->withHeader('Content-type', 'video/mp4'); 
    return $response; 
} 

내가 엔드 포인트로 이동, 크롬이 비디오하다는 인식이다,하지만 난 그게 생각하지 않습니다 실제 동영상을 반환합니다. 플레이어는 아무 것도 볼 수 없으며 1 초에로드됩니다.

+0

파일이 얼마나 큰 :

public function clipGetVideo($request, $response, $args) { set_time_limit(0); $clipid = $args['clipid']; $clip = GameClip::where('id', $clipid)->first(); $response = $response->withHeader('Content-type', 'video/mp4'); return $response->withBody(new Stream(fopen($clip->File, "rb"))) } 

또는 사용자 정의 버퍼링과하지 슬림 접근 방식을 사용하여

? – jmattheis

답변

0

이것은 아마도 큰 파일에서 발생하는 문제입니다. 저에게는 모두 20 메가 바이트 크기의 파일에서 작동하는 것 같습니다.

이 같은 스트림으로 파일을 설정하여 문제를 해결할 수 :

public function clipGetVideo($request, $response, $args) { 
    set_time_limit(0); 

    $clipid = $args['clipid']; 
    $clip = GameClip::where('id', $clipid)->first(); 

    header('Content-Type: video/mp4'); 
    header('Content-Length: ' . filesize($clip->File)); 

    $handle = fopen($clip->File, "rb"); 
    while (!feof($handle)){ 
     echo fread($handle, 8192); 
     ob_flush(); 
     flush(); 
    } 
    fclose($handle); 
    exit(0); 
}