1

When I change the speed of the video in Unity 5.6 with VideoPlayer.playbackSpeed it's working right except the audio. It starts to sounds bad. Any help or advice?

IEnumerator playVideo()
{
    videoPlayer = gameObject.AddComponent<VideoPlayer>();

    audioSource = gameObject.AddComponent<AudioSource>();

    videoPlayer.playOnAwake = false;
    audioSource.playOnAwake = false;
    audioSource.Pause();

    videoPlayer.source = VideoSource.Url;
    videoPlayer.url = @"C:\UnityRepo\VideoPlayer\Assets\musicsheet_8326cca0-f00c-11e5-86c5-ebc45ba9e8dc.mp4";
    //videoPlayer.url = "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4";

    videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;

    videoPlayer.EnableAudioTrack(0, true);
    videoPlayer.SetTargetAudioSource(0, audioSource);


    videoPlayer.Prepare();

    beginWaitTime = Time.time;
    while (!videoPlayer.isPrepared)
    {
        yield return new WaitForEndOfFrame();
    }
    endWaitTime = Time.time;

    Debug.Log(endWaitTime - beginWaitTime);
    PrepareTime.text = (endWaitTime - beginWaitTime).ToString();

    image.texture = videoPlayer.texture;

    videoPlayer.Play();
    audioSource.Play();
}`
Programmer
  • 104,912
  • 16
  • 182
  • 271
Dreuzor
  • 11
  • 3
  • 1
    Where is the code? Please post that! Also, the audio is supposed to match the video speed. I can't tell what exactly you expect to happen to the audio when you change the video speed. – Programmer May 11 '17 at 13:42
  • I posted the code. – Dreuzor May 11 '17 at 14:13
  • 1
    Ok, what do you expect to happen to the audio? Play without increasing its speed....If you do this, the audio will not sync with the video. Is this something you want? – Programmer May 11 '17 at 14:29

1 Answers1

0

If you change the speed of the video, the speed of the audio is also changed in order to match the video. If it does not matter in your case and you want the audio to keep its initial speed, you could try importing just the audio in a second player and muting the VideoPlayer.

You could check this topic regarding the extraction of audio from an mp4 file in C#.

Community
  • 1
  • 1
Setup
  • 331
  • 2
  • 20
  • That's what I try to avoid. Is there any way to separate the audio inside the unity? – Dreuzor May 11 '17 at 13:45
  • @Dreuzor What type of video are you using? Do you have any code? – Setup May 11 '17 at 13:49
  • @Dreuzor You can check [this topic](http://stackoverflow.com/questions/29014419/how-to-extract-just-the-audio-from-an-mp4-file-and-convert-it-to-flac-file-in-c) regarding the extraction of audio from an mp4 file in C#. – Setup May 11 '17 at 14:04