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

Question How to play video and audio files with ffmpeg

Discussion in 'Scripting' started by achimmihca, Aug 4, 2023.

  1. achimmihca

    achimmihca

    Joined:
    Feb 13, 2016
    Posts:
    266
    I want to play at runtime user provided
    - video files like mkv, flv, f4v, etc.
    - audio files like flac, aac, etc

    Sadly, these formats are not supported by Unity.

    So far, I tried this ffmpeg plugin for Unity and it works kind of. But it is unstable (causing harsh editor and app crashes) and performance is bad (frame drops to 20 FPS or below instead of smooth 60 or above).

    There is an alternative ffmpeg integration called FFmpegUnityBind2. It can run ffmpeg commands. However, I am unsure how to use this to play video and audio files.

    Note that playback features like changing position, changing volume, pausing/resuming are all needed.
    Converting the files upfront is not the goal. This would take too long and would be a waste of resources.

    How to integrate ffmpeg in Unity to be
    - (a) stable
    - (b) with good enough performance (i.e. at least 30 FPS on old decade old desktop hardware)

    Would it be possible to run an ffmpeg command with FFmpegUnityBind2 that decodes an unsupported format to, e.g., mp4 (or plain rgb frames) and play this with Unity's VideoPlayer on the fly?
     
  2. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    I think that you could give a look to AVPro plugin