Skip to content

Commit 4040641

Browse files
committed
frame tag is now dynamic in size
1 parent 65a19b7 commit 4040641

File tree

13 files changed

+60
-37
lines changed

13 files changed

+60
-37
lines changed

source/FrameRecorder/Core/Editor/FileNameDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Linq;
2-
using Assets.FrameRecorder.Core.Engine;
32
using UnityEngine;
3+
using UnityEngine.FrameRecorder;
44

55
namespace UnityEditor.FrameRecorder
66
{

source/FrameRecorder/Core/Editor/RecorderEditor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Linq;
3-
using Assets.FrameRecorder.Core.Engine;
42
using UnityEngine;
53
using UnityEngine.FrameRecorder;
64

source/FrameRecorder/Core/Engine/FileNameGenerator.cs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using UnityEngine;
2+
using System.Text.RegularExpressions;
3+
using UnityEngine.SceneManagement;
64

7-
namespace Assets.FrameRecorder.Core.Engine
5+
namespace UnityEngine.FrameRecorder
86
{
97
[Serializable]
108
public struct FileNameGenerator
119
{
1210
public static string[] tagLabels { get; private set; }
1311
public static string[] tags { get; private set; }
12+
static string m_projectName;
1413

1514
public enum ETags
1615
{
1716
Time,
1817
Date,
1918
Project,
19+
Product,
2020
Scene,
2121
Resolution,
2222
Frame,
@@ -26,6 +26,9 @@ public enum ETags
2626
[SerializeField]
2727
string m_Pattern;
2828

29+
string m_FramePattern;
30+
string m_FramePatternDst;
31+
2932
public string pattern {
3033
get { return m_Pattern;}
3134
set { m_Pattern = value; }
@@ -38,6 +41,7 @@ static FileNameGenerator()
3841
"<ts>",
3942
"<dt>",
4043
"<prj>",
44+
"<prd>",
4145
"<scn>",
4246
"<res>",
4347
"<00000>",
@@ -49,9 +53,10 @@ static FileNameGenerator()
4953
"<ts> - Time",
5054
"<dt> - Date",
5155
"<prj> - Project name",
56+
"<prd> - Product name (editor only)",
5257
"<scn> - Scene name",
5358
"<res> - Resolution",
54-
"<00000> - Frame number",
59+
"<000> - Frame number",
5560
"<ext> - Default extension"
5661
};
5762
}
@@ -81,16 +86,45 @@ public static string AddTag(string pattern, ETags t)
8186
return pattern;
8287
}
8388

84-
public string BuildFileName( int frame, int width, int height, string ext )
89+
public string BuildFileName( RecordingSession session, int frame, int width, int height, string ext )
8590
{
91+
if (string.IsNullOrEmpty(m_projectName))
92+
{
93+
#if UNITY_EDITOR
94+
var parts = Application.dataPath.Split('/');
95+
m_projectName = parts[parts.Length - 2];
96+
#else
97+
m_projectName = "N/A";
98+
#endif
99+
}
100+
101+
var regEx = new Regex("(<0*>)");
102+
var match = regEx.Match(pattern);
103+
if (match.Success)
104+
{
105+
m_FramePattern = match.Value;
106+
m_FramePatternDst = m_FramePattern.Substring(1,m_FramePattern.Length-2 );
107+
}
108+
else
109+
{
110+
m_FramePattern = "<0>";
111+
m_FramePatternDst = "0";
112+
}
113+
86114
var fileName = pattern.Replace(tags[(int)ETags.Extension], ext)
87115
.Replace(tags[(int)ETags.Resolution], string.Format("{0}x{1}", width, height))
88-
.Replace(tags[(int)ETags.Frame], frame.ToString("00000"))
89-
.Replace(tags[(int)ETags.Scene], "(scene-NA)")
90-
.Replace(tags[(int)ETags.Project], "(prj-NA)")
91-
.Replace(tags[(int)ETags.Time], "(time-NA)")
92-
.Replace(tags[(int)ETags.Date], "(date-NA)");
93-
116+
.Replace(m_FramePattern, frame.ToString(m_FramePatternDst))
117+
.Replace(tags[(int)ETags.Scene], SceneManager.GetActiveScene().name)
118+
.Replace(tags[(int)ETags.Project], m_projectName)
119+
#if UNITY_EDITOR
120+
.Replace(tags[(int)ETags.Product], UnityEditor.PlayerSettings.productName )
121+
#else
122+
.Replace(tags[(int)ETags.Product], "(prd-NA)")
123+
#endif
124+
.Replace(tags[(int)ETags.Time], string.Format( "{0}h{1}m",session.m_SessionStartTS.ToString("hh"),session.m_SessionStartTS.ToString("mm") ))
125+
.Replace(tags[(int)ETags.Date], session.m_SessionStartTS.ToShortDateString().Replace('/','-'))
126+
;
127+
94128
return fileName;
95129
}
96130

source/FrameRecorder/Core/Engine/FrameRateHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Text;
55

6-
namespace Assets.FrameRecorder.Core.Engine
6+
namespace UnityEngine.FrameRecorder
77
{
88
[Flags]
99
public enum EFrameRate

source/FrameRecorder/Core/Engine/Recorder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using Assets.FrameRecorder.Core.Engine;
43

54
namespace UnityEngine.FrameRecorder
65
{

source/FrameRecorder/Core/Engine/RecorderSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Assets.FrameRecorder.Core.Engine;
54

65
namespace UnityEngine.FrameRecorder
76
{

source/FrameRecorder/Core/Engine/RecordingSession.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class RecordingSession : IDisposable
2222
float m_FPSNextTimeStart;
2323
int m_FPSNextFrameCount;
2424

25+
public DateTime m_SessionStartTS;
26+
2527
public RecorderSettings settings { get { return m_Recorder.settings; } }
2628
public bool recording { get { return m_Recorder.recording; } }
2729
public int frameIndex {get { return m_FrameIndex; }}
@@ -39,7 +41,7 @@ public float RecorderTime
3941
public bool SessionCreated()
4042
{
4143
m_RecordingStartTS = (Time.time / Time.timeScale);
42-
44+
m_SessionStartTS = DateTime.Now;
4345
m_Recorder.SessionCreated(this);
4446
return true;
4547
}

source/FrameRecorder/Integrations/FrameCapturer/Recorders/EXR/EXRRecorder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using Assets.FrameRecorder.Core.Engine;
43
using UnityEngine.FrameRecorder;
54

65
namespace UTJ.FrameCapturer.Recorders
@@ -34,7 +33,7 @@ public override void RecordFrame(RecordingSession session)
3433

3534
var input = (BaseRenderTextureInput)m_Inputs[0];
3635
var frame = input.outputRT;
37-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, frame.width, frame.height, "exr");
36+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, frame.width, frame.height, "exr");
3837
var path = Path.Combine( settings.m_DestinationPath.GetFullPath(), fileName);
3938

4039
fcAPI.fcLock(frame, (data, fmt) =>

source/FrameRecorder/Integrations/FrameCapturer/Recorders/GIF/GIFRecorder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using Assets.FrameRecorder.Core.Engine;
43
using UnityEngine;
54
using UnityEngine.FrameRecorder;
65

@@ -41,7 +40,7 @@ public override void RecordFrame(RecordingSession session)
4140
settings.width = frame.width;
4241
settings.height = frame.height;
4342
m_ctx = fcAPI.fcGifCreateContext(ref settings);
44-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, frame.width, frame.height, "gif");
43+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, frame.width, frame.height, "gif");
4544
var path = Path.Combine( m_Settings.m_DestinationPath.GetFullPath(), fileName);
4645
m_stream = fcAPI.fcCreateFileStream(path);
4746
fcAPI.fcGifAddOutputStream(m_ctx, m_stream);

source/FrameRecorder/Integrations/FrameCapturer/Recorders/MP4/MP4Recorder.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using Assets.FrameRecorder.Core.Engine;
43
using UnityEngine;
54
using UnityEngine.FrameRecorder;
65

@@ -41,8 +40,8 @@ public override void RecordFrame(RecordingSession session)
4140
settings.audio = false;
4241
settings.videoWidth = frame.width;
4342
settings.videoHeight = frame.height;
44-
settings.videoTargetFramerate = 60; // ?
45-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, frame.width, frame.height, "mp4");
43+
settings.videoTargetFramerate = (int)Math.Ceiling(m_Settings.m_FrameRate);
44+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, frame.width, frame.height, "mp4");
4645
var path = Path.Combine( m_Settings.m_DestinationPath.GetFullPath(), fileName);
4746
m_ctx = fcAPI.fcMP4OSCreateContext(ref settings, path);
4847
}

source/FrameRecorder/Integrations/FrameCapturer/Recorders/PNG/PNGRecorder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using Assets.FrameRecorder.Core.Engine;
43
using UnityEngine;
54
using UnityEngine.FrameRecorder;
65

@@ -34,7 +33,7 @@ public override void RecordFrame(RecordingSession session)
3433

3534
var input = (BaseRenderTextureInput)m_Inputs[0];
3635
var frame = input.outputRT;
37-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, frame.width, frame.height, "mp4");
36+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, frame.width, frame.height, "mp4");
3837
var path = Path.Combine(m_Settings.m_DestinationPath.GetFullPath(), fileName);
3938

4039
fcAPI.fcLock(frame, (data, fmt) =>

source/FrameRecorder/Integrations/FrameCapturer/Recorders/WEBM/WEBMRecorder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.IO;
3-
using Assets.FrameRecorder.Core.Engine;
42
using UnityEngine;
53
using UnityEngine.FrameRecorder;
64

@@ -43,9 +41,9 @@ public override void RecordFrame(RecordingSession session)
4341
settings.audio = false;
4442
settings.videoWidth = frame.width;
4543
settings.videoHeight = frame.height;
46-
settings.videoTargetFramerate = 60; // ?
44+
settings.videoTargetFramerate = (int)Math.Ceiling(m_Settings.m_FrameRate);
4745
m_ctx = fcAPI.fcWebMCreateContext(ref settings);
48-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, settings.videoWidth, settings.videoHeight, "webm");
46+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, settings.videoWidth, settings.videoHeight, "webm");
4947
m_stream = fcAPI.fcCreateFileStream(fileName);
5048
fcAPI.fcWebMAddOutputStream(m_ctx, m_stream);
5149
}

source/FrameRecorder/Recorders/ImageRecorder/Engine/ImageRecorder.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
4-
using Assets.FrameRecorder.Core.Engine;
5-
using UnityEngine.FrameRecorder.Input;
63

74
namespace UnityEngine.FrameRecorder
85
{
@@ -58,7 +55,7 @@ public override void RecordFrame(RecordingSession session)
5855

5956
UnityHelpers.Destroy(tex);
6057

61-
var fileName = m_Settings.m_BaseFileName.BuildFileName( recordedFramesCount, width, height, ext);
58+
var fileName = m_Settings.m_BaseFileName.BuildFileName( session, recordedFramesCount, width, height, ext);
6259
var path = Path.Combine( m_Settings.m_DestinationPath.GetFullPath(), fileName);
6360

6461

0 commit comments

Comments
 (0)