RenderHeads/UnityPlugin-AVProMovieCapture

[Question] How do I Save files with custom naming and fix "can't find moov or mdat chunks"

Opened this issue · 1 comments

AVPro Movie Capture Version

5.1.6f1 / Desktop Edition

Which platform is your question for?

Windows

Your question

I am trying to savea file with a specific name however I am getting an error:

can't find moov or mdat chunks
UnityEngine.Debug:LogError (object)
RenderHeads.Media.AVProMovieCapture.MP4FileProcessing:Process (System.IO.Stream,System.IO.Stream) (at Assets/Plugins/RenderHeads/AVProMovieCapture/Runtime/Scripts/Internal/Mp4FileProcessing.cs:270)
RenderHeads.Media.AVProMovieCapture.MP4FileProcessing:ProcessFile (string,string,RenderHeads.Media.AVProMovieCapture.MP4FileProcessing/Options) (at Assets/Plugins/RenderHeads/AVProMovieCapture/Runtime/Scripts/Internal/Mp4FileProcessing.cs:245)
RenderHeads.Media.AVProMovieCapture.MP4FileProcessing:ProcessFile (string,bool,RenderHeads.Media.AVProMovieCapture.MP4FileProcessing/Options) (at Assets/Plugins/RenderHeads/AVProMovieCapture/Runtime/Scripts/Internal/Mp4FileProcessing.cs:201)
RenderHeads.Media.AVProMovieCapture.MP4FileProcessing/<>c__DisplayClass32_0:b__0 () (at Assets/Plugins/RenderHeads/AVProMovieCapture/Runtime/Scripts/Internal/Mp4FileProcessing.cs:173)
System.Threading.ThreadHelper:ThreadStart ()

I'm setting the name and trying to make the file with:

`using UnityEngine;
using RenderHeads.Media.AVProMovieCapture;
using System;
using System.Text;
using UnityEngine.SceneManagement;

//[RequireComponent(typeof(CaptureFromScreen))]
public class ScreenCaptureManager : MonoBehaviour
{
[SerializeField] CaptureBase _capture = null;
private string videoFileName = string.Empty;

void Start()
{
    CaptureFromScreen capture = _capture.GetComponent<CaptureFromScreen>();
    capture.IsRealTime = false;
    capture.FrameRate = 15f;
    capture.StopMode = StopMode.FramesEncoded;
    //capture.StopAfterFramesElapsed = capture.FrameRate * 10f; //Can not convert Int to float but this is what the documentation recommends?
    capture.NativeForceVideoCodecIndex = -1;
    capture.VideoCodecPriorityWindows = new string[] { "H264", "HEVC" };
    //capture.StartCapture(); //If we want to start recording on start
}

void Update()
{
    //For testing with keyboard input
    if (Input.GetKeyDown(KeyCode.S))
    {
        _capture.StartCapture();
    }
    if (Input.GetKeyDown(KeyCode.S))
    {
        _capture.StopCapture();
    }
}

public string ResetFileName()
{
    DateTime now = DateTime.Now;
    //fileName = date_Module_UserName1_UserName2.mp4 
    string moduleName = SceneManager.GetActiveScene().name; //get from scene name
    string userName1 = "UserName"; //Get from user 1 input with new code later.
    string userName2 = "UserName"; //Get from user 2 input or null
    StringBuilder sb = new StringBuilder(); //Easier to read and more efficient/faster when concatenating more than two items.
    sb.Append(now.Year)
          .Append("-")
          .Append(now.Month.ToString("D2"))
          .Append("-")
          .Append(now.Day.ToString("D2"))
          .Append("_")
          .Append(now.Hour.ToString("D2"))
          .Append("-")
          .Append(now.Minute.ToString("D2"))
          .Append("-")
          .Append(now.Second.ToString("D2"))
          .Append("_")
          .Append(moduleName)
          .Append("--")
          .Append(userName1)
          .Append("--")
          .Append(userName2);
          //.Append(".mp4");

    videoFileName = sb.ToString();
    Debug.Log(videoFileName);
    return videoFileName;

}

public void StartScreenCapture()
{
    videoFileName = ResetFileName();
    _capture.FilenamePrefix = videoFileName;
    _capture.StartCapture(); //This seems to be making corrupted files? Can't find moov or mdat chunks.
}

public void StopScreenCapture()
{
    _capture.StopCapture();
}  

}`

It seemed like it was recording videos but with a different name and when I got the name working it started showing the "can't find moov or mdat chunks" error that seems to be linked to the h254 mp4 codec processing.

P.S. Unity 2022.3.20f1

When removing all of the code in the start function which was copied from the PDF and Web documentation

CaptureFromScreen capture = _capture.GetComponent<CaptureFromScreen>(); capture.IsRealTime = false; capture.FrameRate = 15f; capture.StopMode = StopMode.FramesEncoded; //capture.StopAfterFramesElapsed = capture.FrameRate * 10f; //Can not convert Int to float but this is what the documentation recommends? capture.NativeForceVideoCodecIndex = -1; capture.VideoCodecPriorityWindows = new string[] { "H264", "HEVC" }; //capture.StartCapture(); //If we want to start recording on start.

- I tried to edit this ↑ code formatting but it's not working. Sorry.

The video saves again. I will continue to test to see if the issue is intermittent as it may be similar to a few other issues reported by users or it may just be that the documentation examples are out of date.