2017-03-22 2 views
0

내 일반적인 문제는 Unity3D 세계에서 비디오의 속도 (사운드 없음)를 재생하고 제어해야 할 필요가 있으며 아마도 직접 디코딩을 제어해야하고 나는 어떻게 해야할지 전혀 모른다는 것입니다 효율적으로. 그래서 올바른 방향으로 어떤 힌트라도 환영합니다.Unity에서 비디오 재생 속도 설정

유니티의 머티리얼에 투영 된 비디오를 재생해야하며 런타임에 해당 비디오의 속도를 제어해야합니다. 모바일 장치를 대상으로하므로 MovieTexture를 사용할 수 없습니다. 예를 들어 다음과 같은 대안이 있습니다. Easy Movie Texture는 비디오의 속도를 제어하지 못하게합니다.

post에서 문제가있는 해결책을 발견했습니다. 간단히 말해서, 제작자는 비디오를 프레임으로 분할 한 다음 프레임별로 프레임을 표시합니다. 이렇게하면 다음 프레임을 표시 할 때까지 시간을 변경하여 비디오 속도를 제어 할 수 있습니다. 비디오에는 아무런 소리도 없으므로 쉽습니다. 문제는 이것이 기억과 performace의 관점에서 악몽이다. 이 응용 프로그램은 크고 비효율적 인 GB입니다.

정상적인 비디오 플레이어는 모든 프레임을 저장하고 표시하지 않고 그 사이에 델타 만 표시함으로써 해결할 수 있습니다. 만약 내가 그것을 할 수 있고 그것을 프레임 단위로 제어한다면 나는 나의 문제를 해결할 것이다.

런타임에 디코딩 한 다음 델타를 표시하는 것이 상상됩니다. 그러나 나는 그것을 어떻게하는지 모른다. 그러니 올바른 방향으로 나를 가리켜 주시거나 어쩌면 저에게 해결책을주십시오.

동영상 형식이 아직 수정되지 않았으므로 가장 쉽습니다.

답변

1

이렇게하려면 Easy Movie Texture가 필요하지 않으며이를 위해 비디오 프레임을 가져올 필요가 없습니다.

새로운 Unity VideoPlayer API를 사용하면 플랫폼에서 재생 속도를 VideoPlayer.canSetPlaybackSpeed으로 설정할 수 있는지 확인할 수 있습니다. true을 반환하면 videoPlayer.playbackSpeed 속성을 변경하여 비디오 재생 속도를 설정할 수 있습니다.

answer의 코드를 사용하여 RawImage의 동영상을 재생 한 다음 아래 코드를 추가하여 재생 속도를 설정할 수 있습니다.

if (videoPlayer.canSetPlaybackSpeed) 
{ 
    videoPlayer.playbackSpeed = 1f; 
} 

간단합니다.


이미지를 재료에 투영하고 싶다고 말했습니다. 이 경우 "으로 DisplayObject"라는 어떤 게임 오브젝트에 영상을 투사한다 아래 VideoPlayer.renderMode

VideoRenderMode.MaterialOverride;에 코드를 설정해야합니다. outputRenderer 또는 outputRenderer.material 변수의 비디오에서 자료에 액세스 할 수도 있습니다.

테스트 용 오디오가 있으며 게시물에서 언급 한 것처럼 오디오를 원하지 않으면 오디오를 제거 할 수 있습니다.

using UnityEngine; 
using UnityEngine.Video; 

public class VideoSpeedControl : MonoBehaviour 
{ 
    //The material that Video will output to 
    Renderer outputRenderer; 

    private VideoPlayer videoPlayer; 

    //Audio 
    private AudioSource audioSource; 

    void Start() 
    { 

     outputRenderer = gameObject.AddComponent<MeshRenderer>(); 

     //Add VideoPlayer to the GameObject 
     videoPlayer = gameObject.AddComponent<VideoPlayer>(); 

     //Add AudioSource 
     audioSource = gameObject.AddComponent<AudioSource>(); 

     //Disable Play on Awake for both Video and Audio 
     videoPlayer.playOnAwake = false; 
     audioSource.playOnAwake = false; 

     // We want to play from url 
     videoPlayer.source = VideoSource.Url; 
     videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"; 

     //Set Audio Output to AudioSource 
     videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; 

     //Assign the Audio from Video to AudioSource to be played 
     videoPlayer.EnableAudioTrack(0, true); 
     videoPlayer.SetTargetAudioSource(0, audioSource); 

     //Set the mode of output 
     videoPlayer.renderMode = VideoRenderMode.MaterialOverride; 

     //Set the renderer to store the images to 
     //outputRenderer = videoPlayer.targetMaterialRenderer; 
     videoPlayer.targetMaterialProperty = "_MainTex"; 

     //Prepare Video to prevent Buffering 
     videoPlayer.Prepare(); 

     //Subscribe to prepareCompleted event 
     videoPlayer.prepareCompleted += OnVideoPrepared; 
    } 

    void OnVideoPrepared(VideoPlayer source) 
    { 
     Debug.Log("Done Preparing Video"); 

     //Play Video 
     videoPlayer.Play(); 

     //Play Sound 
     audioSource.Play(); 

     //Change Play Speed 
     if (videoPlayer.canSetPlaybackSpeed) 
     { 
      videoPlayer.playbackSpeed = 1f; 
     } 
    } 

    bool firsrRun = true; 
    void Update() 
    { 
     if (firsrRun) 
     { 
      GameObject.Find("DisplayObject").GetComponent<MeshRenderer>().material = outputRenderer.material; 
      firsrRun = false; 
     } 
    } 
} 
+0

길고 정확한 답변을 주셔서 감사합니다. 현재 다른 긴급한 버그 수정이 있습니다.하지만 다시 돌아와서 테스트하고 올바르게 작동하는 것으로 표시 할 것입니다. 편집 한 경우에도 모바일 장치에서 작동하는 것이 특히 중요합니다 (예 : Movietexture가 작동하지 않음). 내 질문 제목과 태그에서 그 부분 ... – findusl

+0

사람들이 Unity에서 비디오를 재생한다고 말하면 비디오가 모든 플랫폼에서 작동해야한다고 자동으로 가정해야합니다. 질문을 읽은 후에 * 모바일 *을 태그 할 필요가 없습니다. 이 답변은 모바일 장치에서도 작동해야합니다. – Programmer

+0

답변 해 주셔서 감사합니다. 그것은 그것이 여기에있는 한 질문에 대답합니다, 슬프게도 나를 위해 완전히 작동하지 않습니다. 그러나 나는 그것에 대해 새로운 질문을 할 것입니다. 그 비디오 플레이어는 이미 나에게 더 많은 감사를 가져왔다 :) – findusl