Search Results for

    Show / Hide Table of Contents

    Waiting for a Capture to Complete

    When a capture is stopped, there will still be remaining frames to process and some file post-processing operations to perform. The file is not usable until these operations have completed. These operations happen in the background so they do not block the main thread. They usually only take a second or two to complete, but it can take longer if the file is very large and post-process operations are enabled (eg fast-start, stereo injection).

    The FileWritingHandler class can be used to know when a captured video file is ready for use.

    There are two events that can be used:

    • BeginFinalFileWritingAction
    • CompletedFileWritingAction

    If you only want to know when the file is ready then the OnCompleteFinalFileWriting can be subscribed to:

    using UnityEngine;
    using RenderHeads.Media.AVProMovieCapture;
    
    public class FileCompleteExample : MonoBehaviour
    {
        [SerializeField] CaptureBase _capture = null;
    
        void Start()
        {
            _capture.CompletedFileWritingAction += OnCompleteFinalFileWriting;
        }
    
        void OnDestroy()
        {
            _capture.CompletedFileWritingAction -= OnCompleteFinalFileWriting;
        }
    
        void OnCompleteFinalFileWriting(FileWritingHandler handler)
        {
            Debug.Log("The file is at: " + handler.Path);
        }
    }
    

    If you want to track the progress from the beginning of file writing then use BeginFinalFileWritingAction, which can then be polled for the ready status, or could be used in conjunction with the CompletedFileWritingAction:

    using UnityEngine;
    using RenderHeads.Media.AVProMovieCapture;
    
    public class FileWriteHandlerExample : MonoBehaviour
    {
        [SerializeField] CaptureBase _capture = null;
        private FileWritingHandler _fileWritingHandler;
    
        void Start()
        {
            _capture.BeginFinalFileWritingAction += OnBeginFinalFileWriting;
        }
    
        void OnDestroy()
        {
            _capture.BeginFinalFileWritingAction -= OnBeginFinalFileWriting;
            if (_fileWritingHandlers != null)
            {
                _fileWritingHandlers.Dispose();
            }
        }
    
        void OnBeginFinalFileWriting(FileWritingHandler handler)
        {
            _fileWritingHandlers = handler;
        }
    
        void Update()
        {
            if (_fileWritingHandlers != null)
            {
                // Poll for the file writing to complete
                if (_fileWritingHandlers.IsFileReady())
                {
                    Debug.Log("File is ready at: " + _fileWritingHandlers.Path);
                    _fileWritingHandlers = null;
                }
            }
        }
    }
    

    Retreiving captured file path

    If you use the FileWriteHandler then you can retrieve the capture file path by using the Path property as shown in the two examples above.

    Otherwise, the CaptureFrom component has a LastFilePath that will return the full path to the last file written:

    using UnityEngine;
    using RenderHeads.Media.AVProMovieCapture;
    
    public class GetLastPathExample : MonoBehaviour
    {
        [SerializeField] CaptureBase _capture = null;
    
        void Update()
        {
            Debug.Log("The last captured file is at: " + _capture.LastFilePath);
        }
    }
    
    In This Article