Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Audio AudioSampleProvider buffer overflow. XXX frames discarded

Discussion in 'Audio & Video' started by tr5414, Mar 10, 2020.

  1. tr5414

    tr5414

    Joined:
    Jan 23, 2019
    Posts:
    1
    Hey ya'll, Im a newbie unity dev trying to fix and understand this error that I keep getting when trying to play certain videos in my scenes. The error came up a while back but am only now just starting to work on it. Ive noticed the longer the video the more likely this is to happen. Ive found a sorta-solution in just ripping the audio files from my videos, decompressing them, and then adding them back into the videos, but I have a lot of videos and would rather understand why it is happening in the first place. Using 2018.3.5f1.
     
    Fenikkel likes this.
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    256
    Hi!

    This message is produced when audio samples are produced faster than whatever is consuming them in your specific setup.

    The AudioSampleProvider is the intermediate mechanism that sits between the audio output of the movie decoder and the audio engine (ultimately FMOD). As you may have found out, you can also obtain the samples yourself (via https://docs.unity3d.com/ScriptRefe...oPlayerExtensions.GetAudioSampleProvider.html) and pipe them into another engine or wherever you may find useful.

    We can't say what the problem is without knowing a bit more about your setup, platform and media files. It could be that there really are too many samples per second in the encoded track (showing a disconnect between the sample rate and the actual data). Or it could be that the audio/video interleaving is too wide (e.g.: 20s of video, then 20s of audio, and so on) and goes above internal assumptions for the given platform, which will typically be expecting around an interleaving around 1s.

    So if any of the above gives you hints on how get rid of this situation, then good! If not, then please submit a bug report so we can look at your setup and either suggest a workaround or fix whatever could be broken in the mechanism I just described.

    Hope this helps!

    Dominique Leroux
    A/V developer at Unity
     
  3. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    801
    This is actually easy to reproduce:
    • take a 2k video, play it back with VideoPlayer
    • render it into a 4k render texture
    • try to use Unity Recorder with movie mode on that RenderTexture, with audio

    The results are really bad, and there's continuous logging about
    Code (CSharp):
    1. AudioSampleProvider buffer overflow. 2048 sample frames discarded.
    .

    I'll try to make a bug report, but the above should be totally sufficient to see the issue for yourself.
     
    Alex-CG likes this.
  4. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    256
    This is a known issue, and probably not the same issue as what tr5414 is describing.

    The VideoPlayer doesn't support using setting Time.captureFramerate to a non-zero value (essentially hijacking the passage of time in Unity). This is what the recorder does in order to render "as fast as the game can run". This often makes recording faster/slower than real time, and the underlying implementations don't support this - or not yet anyways.

    This is pointed out in the limitations section of the Unity Recorder manual: https://unitytech.github.io/unity-recorder/manual/index.html

    Sorry for the annoyance...

    Dominique
     
  5. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    801
    Thanks for the link. Unfortunately yet another unexpected video player limitation preventing production usage for us... is fixing this on the roadmap? My expectation would be that VideoPlayer set to “don’t drop frames” in combination with movie recorder at constant rate should result in perfect video captures.
     
  6. Fenikkel

    Fenikkel

    Joined:
    Sep 24, 2019
    Posts:
    20
    "AudioSampleProvider buffer overflow. XXX frames discarded"

    In my case, my problem was that I went out of memory or something like that.
    The warning appeared when I exceed preparing/loading my videos (VideoPlayer.prepare).
    I prepared a total of 52 videos with 52 video players. The first half runs ok, but the other half got this warning and the audio never sound.
    If I started loading (preparing) the second half first, the first half was the one who gives me the warning and brokes the sound.

    My "solution" was evade preparing the videos or preparing less of them. They start with a delay but the warning and the audio were fixed.

    Hope it was useful
     
    khanhabib, VResearch and xeniaosense like this.
  7. azporispo

    azporispo

    Joined:
    Jul 19, 2012
    Posts:
    4
    Here is what worked for me.
    I was using 1 VideoPlayer and 15 videos. I was only changing the clips in the VideoPlayer.
    And I started getting the error "AudioSampleProvider buffer overflow. 2048 sample frames discarded".
    The problem was using this line
    videoPlayer.time = 0;

    On the profiler I saw that the "pre-buffered frames" and the "total Audio CPU" count was increasing every time I called that instruction. And after around 30 calls, the sound stoped working (on Editor and Windows build).
    So, you can just Play and Stop videos If you have only 1 videoPlayer like me. (The Stop already moves the time at the beggining of the video).
     
    khanhabib and Fenikkel like this.
  8. robertandriessen

    robertandriessen

    Joined:
    Feb 10, 2020
    Posts:
    33
    I seem to be getting this problem too, on Android pie, using standard unity videoplayer. It is a large video file and after a while a stop() is called with the audiotrack tag. The whole video stops. The video is encoded in mkv with hecv. I was unable to playback it in the mp4 container when it is this large.
     
  9. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    Yesterday I had the same problem (Unity 2021.1.24f1) but it vanished randomly and I was working with the video player for a couple of hours without a single message. Today, after starting up Unity, the message kept getting logged again once I pressed my in-app "play" button (didn't wear my headphones, so not sure if the sound was completely gone):
    Code (CSharp):
    1.  
    2. private void OnEnable() {
    3.     videoPlayer.url = StaticClass.videoLink;
    4.     videoPlayer.targetTexture.Release();
    5.     videoPlayer.Prepare();
    6. }
    7.  
    8. private void PressPlay() {
    9.     videoPlayer.Play();
    10.     playButton.SetActive(false);
    11.     pauseButton.SetActive(true);
    12. }
    The second time I ran the Unity player everything was back to normal - no more message and restarting Unity (including the hub) didn't make it appear again. I only use "videoPlayer.time" for skipping forwards/backwards (didn't use those buttons today though), otherwise I use the e.g. "Play()" function.
    The video I've been testing the player with is a 27mb 720p .mp4 file (downloaded from a server using the url) and I map it onto a 1080p render texture with the "fit inside" setting.
     
    Last edited: Feb 10, 2022
    AlonMixed likes this.
  10. scottdev333

    scottdev333

    Joined:
    Nov 20, 2021
    Posts:
    12
    Saw these warnings today. I have 7 videos that at one point are all playing simultaneously. But it's a warning, not an error.

    It doesn't happen all the time, but I believe it happened when I paused the player for a period of time and then stopped test mode. I am going to watch it more closely now to see if I can pinpoint when it happens and I notice any audio issues when that happens. I didn't notice any audio issues while testing, just saw those warnings after I stopped testing.
     
  11. AndyKorth

    AndyKorth

    Joined:
    Oct 19, 2009
    Posts:
    40
    I had the "AudioSampleProvider buffer overflow" message occurring in a different situation. I was playing a single fairly low resolution video via the Timeline while in the editor. I had regular buffer overflows while previewing the timeline video content, but it worked fine in builds and while the editor was playing. The problem for me was a VideoPlayer that had a playback speed other than 1.0. (it was unexpectedly getting set to 0.89 sometimes by an editor script). Perhaps this interacted with the 1.0 speed of the timeline.

    So... one more thing to check if you have this problem: check your playback speed. (VideoPlayer component, Timeline, or PlayableDirector!)