Skip to content

Commit

Permalink
removed audio timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 13, 2017
1 parent 0a3d4a3 commit c2822ca
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public class ExrEncoder : MovieEncoder
string m_outPath;
int m_frame;


public override Type type { get { return Type.Exr; } }


public override void Initialize(object config, string outPath)
{
m_config = (fcAPI.fcExrConfig)config;
Expand Down Expand Up @@ -45,7 +43,7 @@ public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, dou
++m_frame;
}

public override void AddAudioFrame(float[] samples, double timestamp = -1.0)
public override void AddAudioFrame(float[] samples)
{
// not supported
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class FlacEncoder : AudioEncoder
{
fcAPI.fcFlacContext m_ctx;
fcAPI.fcFlacConfig m_config;
fcAPI.fcStream m_ostream;

public override Type type { get { return Type.Flac; } }

Expand All @@ -20,17 +19,14 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcFlacCreateContext(ref m_config);

var path = outPath + ".flac";
m_ostream = fcAPI.fcCreateFileStream(path);
fcAPI.fcFlacAddOutputStream(m_ctx, m_ostream);
var stream = fcAPI.fcCreateFileStream(path);
fcAPI.fcFlacAddOutputStream(m_ctx, stream);
stream.Release();
}

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
m_ostream.Release();
});
m_ctx.Release();
}

public override void AddAudioFrame(float[] samples, double timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class GifEncoder : MovieEncoder
{
fcAPI.fcGifContext m_ctx;
fcAPI.fcGifConfig m_config;
fcAPI.fcStream m_ostream;

public override Type type { get { return Type.Gif; } }

Expand All @@ -19,25 +18,22 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcGifCreateContext(ref m_config);

var path = outPath + ".gif";
m_ostream = fcAPI.fcCreateFileStream(path);
fcAPI.fcGifAddOutputStream(m_ctx, m_ostream);
var stream = fcAPI.fcCreateFileStream(path);
fcAPI.fcGifAddOutputStream(m_ctx, stream);
stream.Release();
}

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
m_ostream.Release();
});
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
{
fcAPI.fcGifAddFramePixels(m_ctx, frame, format, timestamp);
}

public override void AddAudioFrame(float[] samples, double timestamp)
public override void AddAudioFrame(float[] samples)
{
// not supported
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public override void Initialize(object config, string outPath)

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
});
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
Expand All @@ -37,7 +34,7 @@ public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, dou
}
}

public override void AddAudioFrame(float[] samples, double timestamp)
public override void AddAudioFrame(float[] samples)
{
if (m_config.audio)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class MovieEncoderConfigs
public fcAPI.fcWebMConfig webmEncoderSettings = fcAPI.fcWebMConfig.default_value;
public fcAPI.fcMP4Config mp4EncoderSettings = fcAPI.fcMP4Config.default_value;

public MovieEncoderConfigs(MovieEncoder.Type t)
{
format = t;
}

public bool supportVideo
{
get {
Expand Down Expand Up @@ -116,7 +121,7 @@ public enum Type
// config: config struct (fcGifConfig, fcWebMConfig, etc)
public abstract void Initialize(object config, string outPath);
public abstract void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp = -1.0);
public abstract void AddAudioFrame(float[] samples, double timestamp = -1.0);
public abstract void AddAudioFrame(float[] samples);


public static MovieEncoder Create(Type t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class OggEncoder : AudioEncoder
{
fcAPI.fcOggContext m_ctx;
fcAPI.fcOggConfig m_config;
fcAPI.fcStream m_ostream;

public override Type type { get { return Type.Ogg; } }

Expand All @@ -20,17 +19,14 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcOggCreateContext(ref m_config);

var path = outPath + ".ogg";
m_ostream = fcAPI.fcCreateFileStream(path);
fcAPI.fcOggAddOutputStream(m_ctx, m_ostream);
var stream = fcAPI.fcCreateFileStream(path);
fcAPI.fcOggAddOutputStream(m_ctx, stream);
stream.Release();
}

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
m_ostream.Release();
});
m_ctx.Release();
}

public override void AddAudioFrame(float[] samples, double timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, dou
++m_frame;
}

public override void AddAudioFrame(float[] samples, double timestamp = -1.0)
public override void AddAudioFrame(float[] samples)
{
// not supported
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class WaveEncoder : AudioEncoder
{
fcAPI.fcWaveContext m_ctx;
fcAPI.fcWaveConfig m_config;
fcAPI.fcStream m_ostream;

public override Type type { get { return Type.Wave; } }

Expand All @@ -20,17 +19,14 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcWaveCreateContext(ref m_config);

var path = outPath + ".wave";
m_ostream = fcAPI.fcCreateFileStream(path);
fcAPI.fcWaveAddOutputStream(m_ctx, m_ostream);
var stream = fcAPI.fcCreateFileStream(path);
fcAPI.fcWaveAddOutputStream(m_ctx, stream);
stream.Release();
}

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
m_ostream.Release();
});
m_ctx.Release();
}

public override void AddAudioFrame(float[] samples, double timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class WebMEncoder : MovieEncoder
{
fcAPI.fcWebMContext m_ctx;
fcAPI.fcWebMConfig m_config;
fcAPI.fcStream m_ostream;

public override Type type { get { return Type.WebM; } }

Expand All @@ -21,17 +20,14 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcWebMCreateContext(ref m_config);

var path = outPath + ".webm";
m_ostream = fcAPI.fcCreateFileStream(path);
fcAPI.fcWebMAddOutputStream(m_ctx, m_ostream);
var stream = fcAPI.fcCreateFileStream(path);
fcAPI.fcWebMAddOutputStream(m_ctx, stream);
stream.Release();
}

public override void Release()
{
fcAPI.fcGuard(() =>
{
m_ctx.Release();
m_ostream.Release();
});
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
Expand All @@ -42,7 +38,7 @@ public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, dou
}
}

public override void AddAudioFrame(float[] samples, double timestamp)
public override void AddAudioFrame(float[] samples)
{
if (m_config.audio)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public struct fcMP4Context
[DllImport ("fccore")] private static extern IntPtr fcMP4GetAudioEncoderInfo(fcMP4Context ctx);
[DllImport ("fccore")] private static extern IntPtr fcMP4GetVideoEncoderInfo(fcMP4Context ctx);
[DllImport ("fccore")] public static extern Bool fcMP4AddVideoFramePixels(fcMP4Context ctx, byte[] pixels, fcPixelFormat fmt, double timestamp = -1.0);
[DllImport ("fccore")] public static extern Bool fcMP4AddAudioFrame(fcMP4Context ctx, float[] samples, int num_samples, double timestamp = -1.0);
[DllImport ("fccore")] public static extern Bool fcMP4AddAudioFrame(fcMP4Context ctx, float[] samples, int num_samples);

public static string fcMP4GetAudioEncoderInfoS(fcMP4Context ctx)
{
Expand Down Expand Up @@ -467,7 +467,7 @@ public static fcWebMConfig default_value
// timestamp=-1 is treated as current time.
[DllImport ("fccore")] public static extern Bool fcWebMAddVideoFramePixels(fcWebMContext ctx, byte[] pixels, fcPixelFormat fmt, double timestamp = -1.0);
// timestamp=-1 is treated as current time.
[DllImport ("fccore")] public static extern Bool fcWebMAddAudioFrame(fcWebMContext ctx, float[] samples, int num_samples, double timestamp = -1.0);
[DllImport ("fccore")] public static extern Bool fcWebMAddAudioFrame(fcWebMContext ctx, float[] samples, int num_samples);


// -------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Update(double time)

#region fields
[SerializeField] DataPath m_outputDir = new DataPath(DataPath.Root.Current, "Capture");
[SerializeField] MovieEncoderConfigs m_encoderConfigs = new MovieEncoderConfigs();
[SerializeField] MovieEncoderConfigs m_encoderConfigs = new MovieEncoderConfigs(MovieEncoder.Type.Exr);
[SerializeField] FrameBufferConponents m_fbComponents = FrameBufferConponents.default_value;
[SerializeField] bool m_fixDeltaTime = true;
[SerializeField] int m_targetFramerate = 30;
Expand Down
10 changes: 2 additions & 8 deletions FrameCapturer/Assets/UTJ/FrameCapturer/Scripts/MovieRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum CaptureControl
#region fields
// base settings
[SerializeField] DataPath m_outputDir = new DataPath(DataPath.Root.Current, "Capture");
[SerializeField] MovieEncoderConfigs m_encoderConfigs = new MovieEncoderConfigs();
[SerializeField] MovieEncoderConfigs m_encoderConfigs = new MovieEncoderConfigs(MovieEncoder.Type.WebM);

// video settings
[SerializeField] int m_resolutionWidth = -1;
Expand All @@ -58,9 +58,7 @@ public enum CaptureControl
CommandBuffer m_cb;
RenderTexture m_scratchBuffer;
bool m_recording = false;
int m_outputSampleRate;
int m_numVideoFrames = 0;
int m_numAudioSamples = 0;

MovieEncoder m_encoder;
#endregion
Expand Down Expand Up @@ -155,9 +153,7 @@ public bool BeginRecording()
}


m_outputSampleRate = AudioSettings.outputSampleRate;
m_numVideoFrames = 0;
m_numAudioSamples = 0;

// create scratch buffer
{
Expand Down Expand Up @@ -345,9 +341,7 @@ void OnAudioFilterRead(float[] samples, int channels)
{
if (m_recording && m_encoder != null)
{
double timestamp = (double)m_numAudioSamples / (double)m_outputSampleRate;
m_encoder.AddAudioFrame(samples, timestamp);
m_numAudioSamples += samples.Length / channels;
m_encoder.AddAudioFrame(samples);
}
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Tests/MP4Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void WriteMovieData(fcIMP4Context *ctx)
fcTime t = 0;
for (int i = 0; i < DurationInSeconds; ++i) {
CreateAudioData(&audio_sample[0], (int)audio_sample.size(), i, 1.0f);
fcMP4AddAudioFrame(ctx, &audio_sample[0], (int)audio_sample.size(), t);
fcMP4AddAudioFrame(ctx, &audio_sample[0], (int)audio_sample.size());
t += 1.0;
}
});
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Tests/WebMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void WebMTest(fcWebMVideoEncoder ve, fcWebMAudioEncoder ae)
fcTime t = 0;
while (t < (double)DurationInSeconds) {
CreateAudioData(audio_sample.data(), (int)audio_sample.size(), t, 1.0f);
fcWebMAddAudioFrame(ctx, audio_sample.data(), (int)audio_sample.size(), t);
fcWebMAddAudioFrame(ctx, audio_sample.data(), (int)audio_sample.size());
t += 1.0;
}
});
Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/Encoder/MP4/fcAACEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class fcIAACEncoder
virtual ~fcIAACEncoder() {}
virtual const char* getEncoderInfo() = 0;
virtual const Buffer& getDecoderSpecificInfo() = 0;
virtual bool encode(fcAACFrame& dst, const float *samples, size_t num_samples, fcTime timestamp) = 0;
virtual bool encode(fcAACFrame& dst, const float *samples, size_t num_samples) = 0;
virtual bool flush(fcAACFrame& dst) = 0;
};

Expand Down
4 changes: 2 additions & 2 deletions Plugin/fccore/Encoder/MP4/fcAACEncoderFAAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class fcAACEncoderFAAC : public fcIAACEncoder
~fcAACEncoderFAAC() override;
const char* getEncoderInfo() override;
const Buffer& getDecoderSpecificInfo() override;
bool encode(fcAACFrame& dst, const float *samples, size_t num_samples, fcTime timestamp) override;
bool encode(fcAACFrame& dst, const float *samples, size_t num_samples) override;
bool flush(fcAACFrame& dst) override;

bool isValid() const { return m_handle != nullptr; }
Expand Down Expand Up @@ -106,7 +106,7 @@ fcAACEncoderFAAC::~fcAACEncoderFAAC()
}
const char* fcAACEncoderFAAC::getEncoderInfo() { return "FAAC"; }

bool fcAACEncoderFAAC::encode(fcAACFrame& dst, const float *samples, size_t num_samples, fcTime timestamp)
bool fcAACEncoderFAAC::encode(fcAACFrame& dst, const float *samples, size_t num_samples)
{
m_aac_tmp_buf.resize(m_output_size);

Expand Down
4 changes: 2 additions & 2 deletions Plugin/fccore/Encoder/MP4/fcAACEncoderIntel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class fcAACEncoderIntel : public fcIAACEncoder

const char* getEncoderInfo() override;
const Buffer& getDecoderSpecificInfo() override;
bool encode(fcAACFrame& dst, const float *samples, size_t num_samples, fcTime timestamp) override;
bool encode(fcAACFrame& dst, const float *samples, size_t num_samples) override;
bool flush(fcAACFrame& dst) override;

bool isValid() { return m_encoder != nullptr; }
Expand Down Expand Up @@ -84,7 +84,7 @@ const Buffer& fcAACEncoderIntel::getDecoderSpecificInfo()
return m_aac_header;
}

bool fcAACEncoderIntel::encode(fcAACFrame& dst, const float *samples, size_t num_samples, fcTime timestamp)
bool fcAACEncoderIntel::encode(fcAACFrame& dst, const float *samples, size_t num_samples)
{
if (!isValid()) { return false; }

Expand Down
Loading

0 comments on commit c2822ca

Please sign in to comment.