Ejemplo n.º 1
0
        public override void RecordFrame(RecordingSession session)
        {
            if (m_Inputs.Count != 1)
            {
                throw new Exception("Unsupported number of sources");
            }

            var input = (BaseRenderTextureInput)m_Inputs[0];
            var frame = input.outputRT;

            if (!m_ctx)
            {
                var settings = m_Settings.m_MP4EncoderSettings;
                settings.video                = true;
                settings.audio                = false;
                settings.videoWidth           = frame.width;
                settings.videoHeight          = frame.height;
                settings.videoTargetFramerate = 60; // ?
                m_ctx = fcAPI.fcMP4OSCreateContext(ref settings, BuildOutputPath(session));
            }

            fcAPI.fcLock(frame, TextureFormat.RGB24, (data, fmt) =>
            {
                fcAPI.fcMP4AddVideoFramePixels(m_ctx, data, fmt, session.m_CurrentFrameStartTS);
            });
        }
Ejemplo n.º 2
0
        public override void RecordFrame(RecordingSession session)
        {
            if (m_Inputs.Count != 1)
            {
                throw new Exception("Unsupported number of sources");
            }

            var input = (BaseRenderTextureInput)m_Inputs[0];
            var frame = input.outputRT;

            if (!m_ctx)
            {
                var settings = m_Settings.m_MP4EncoderSettings;
                settings.video                = true;
                settings.audio                = false;
                settings.videoWidth           = frame.width;
                settings.videoHeight          = frame.height;
                settings.videoTargetFramerate = (int)Math.Ceiling(m_Settings.m_FrameRate);
                if (m_Settings.m_AutoSelectBR)
                {
                    settings.videoTargetBitrate = (int)(((frame.width * frame.height / 1000.0) / 245 + 1.16) * (settings.videoTargetFramerate / 48.0 + 0.5) * 1000000);
                }
                var fileName = m_Settings.m_BaseFileName.BuildFileName(session, recordedFramesCount, frame.width, frame.height, "mp4");
                var path     = Path.Combine(m_Settings.m_DestinationPath.GetFullPath(), fileName);
                m_ctx = fcAPI.fcMP4OSCreateContext(ref settings, path);
            }

            fcAPI.fcLock(frame, TextureFormat.RGB24, (data, fmt) =>
            {
                fcAPI.fcMP4AddVideoFramePixels(m_ctx, data, fmt, session.recorderTime);
            });
        }
Ejemplo n.º 3
0
    public override void ResetRecordingState()
    {
        fcAPI.fcMP4DestroyContext(m_ctx);
        m_ctx.ptr = IntPtr.Zero;
        if(m_scratch_buffer != null)
        {
            m_scratch_buffer.Release();
            m_scratch_buffer = null;
        }

        int capture_width = m_resolution_width;
        int capture_height = (int)((float)m_resolution_width / ((float)m_cam.pixelWidth / (float)m_cam.pixelHeight));
        m_scratch_buffer = new RenderTexture(capture_width, capture_height, 0, RenderTextureFormat.ARGB32);
        m_scratch_buffer.wrapMode = TextureWrapMode.Repeat;
        m_scratch_buffer.Create();

        m_frame = 0;
        fcAPI.fcMP4Config conf = default(fcAPI.fcMP4Config);
        conf.setDefaults();
        conf.video = m_video ? 1 : 0;
        conf.audio = m_audio ? 1 : 0;
        conf.video_width = m_scratch_buffer.width;
        conf.video_height = m_scratch_buffer.height;
        conf.video_framerate = m_frame_rate;
        conf.video_bitrate = m_video_bitrate;
        conf.video_max_frame = m_max_frame;
        conf.video_max_data_size = m_max_data_size;
        conf.audio_bitrate = m_audio_bitrate;
        conf.audio_sampling_rate = AudioSettings.outputSampleRate;
        switch (AudioSettings.speakerMode)
        {
            case AudioSpeakerMode.Mono: conf.audio_num_channels = 1; break;
            case AudioSpeakerMode.Stereo: conf.audio_num_channels = 2; break;
            // todo: maybe need more case
        }
        m_ctx = fcAPI.fcMP4CreateContext(ref conf);
    }