28 lines
750 B
C#
28 lines
750 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using FFmpeg.AutoGen;
|
|
|
|
namespace VideoReader;
|
|
|
|
internal class SaveVideo
|
|
{
|
|
private unsafe AVFormatContext* pFormatContext;
|
|
|
|
private unsafe AVStream* st;
|
|
|
|
private unsafe void Write_Frame(byte[] buff, long number)
|
|
{
|
|
AVPacket aVPacket = default(AVPacket);
|
|
AVPacket* ptr = &aVPacket;
|
|
ffmpeg.av_init_packet(ptr);
|
|
IntPtr intPtr = Marshal.AllocHGlobal(buff.Length);
|
|
Marshal.Copy(buff, 0, intPtr, buff.Length);
|
|
ptr->data = (sbyte*)intPtr.ToPointer();
|
|
ptr->size = buff.Length;
|
|
ptr->pts = ffmpeg.av_rescale_q(number, st->codec->time_base, st->time_base);
|
|
int num = ffmpeg.av_interleaved_write_frame(pFormatContext, ptr);
|
|
Marshal.FreeHGlobal(intPtr);
|
|
ffmpeg.av_free_packet(ptr);
|
|
}
|
|
}
|