Skip to content

Commit

Permalink
[1.0.2.15]
Browse files Browse the repository at this point in the history
1.增加了房间号绑定Settings,实现自动保存。
2.增加了自动转码为MP4的功能,可解决Tag不完整问题。
3.移除了UI上一个没有意义的提示label。
  • Loading branch information
LeoChen98 committed Jun 6, 2018
1 parent a3798c3 commit 8561929
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 149 deletions.
68 changes: 65 additions & 3 deletions AutoLiveRecorder/B_Live.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class B_Live
{
#region Private 字段

private bool _IsProcessing = false;
private bool _IsRecording = false;

/// <summary>
Expand Down Expand Up @@ -77,6 +78,12 @@ public B_Live(int id)

#region Public 委托

/// <summary>
/// 处理状态改变事件委托
/// </summary>
/// <param name="ProcessStatus">录制状态</param>
public delegate void ProcessStatusChangedEventHandler(bool ProcessStatus);

/// <summary>
/// 录制状态改变事件委托
/// </summary>
Expand All @@ -87,6 +94,11 @@ public B_Live(int id)

#region Public 事件

/// <summary>
/// 处理状态改变事件
/// </summary>
public event ProcessStatusChangedEventHandler ProcessStatusChanged;

/// <summary>
/// 录制状态改变事件
/// </summary>
Expand All @@ -96,6 +108,30 @@ public B_Live(int id)

#region Public 属性

/// <summary>
/// 指示是否自动转码
/// </summary>
public bool IsAutoTranscode
{
get; set;
}

/// <summary>
/// 是否正在转码
/// </summary>
public bool IsProcessing
{
get
{
return _IsProcessing;
}
private set
{
_IsProcessing = value;
ProcessStatusChanged(value);
}
}

/// <summary>
/// 指示是否正在录制
/// </summary>
Expand Down Expand Up @@ -133,7 +169,7 @@ public void ReadyToRecord(string savepath)
{
while (true)
{
if (IsLive()&& !IsRecording) StartRecord(savepath);
if (IsLive() && !IsRecording) StartRecord(savepath);
System.Threading.Thread.Sleep(1000);
}
}
Expand Down Expand Up @@ -241,11 +277,21 @@ public void StopRecord()
/// <param name="savepathn">文件名称(不含扩展名)</param>
private void ArrangeFile(string savepath)
{
IsProcessing = true;
string savepathn = savepath.Substring(0, savepath.LastIndexOf("."));
if (filelist.Count == 1)
{
File.Move(filelist[0], savepath);
Process.Start("explorer.exe","/select," + savepath);
if (IsAutoTranscode)
{
VideoProcess.TranscodeFinished += TranscodeFinished;
VideoProcess.TranscodeToMp4(new List<string>() { savepath }, savepath);
}
else
{
Process.Start("explorer.exe", "/select," + savepath);
IsProcessing = false;
}
}
else
{
Expand All @@ -255,8 +301,18 @@ private void ArrangeFile(string savepath)
string[] tmp = Regex.Split(i, "\\");
string filename = tmp[tmp.Length - 1];
File.Move(i, savepath + "\\" + filename);
filelist[filelist.IndexOf(i)] = savepath + "\\" + filename;
}
if (IsAutoTranscode)
{
VideoProcess.TranscodeFinished += TranscodeFinished;
VideoProcess.TranscodeToMp4(filelist, savepath);
}
else
{
Process.Start("explorer.exe", savepathn);
IsProcessing = false;
}
Process.Start("explorer.exe",savepathn);
}
}

Expand All @@ -282,6 +338,12 @@ private bool IsLive()
}
}

private void TranscodeFinished(string savepath)
{
Process.Start("explorer.exe", "/select," + savepath);
IsProcessing = false;
}

#endregion Private 方法

#region Private 类
Expand Down
205 changes: 109 additions & 96 deletions AutoLiveRecorder/FLVAnalysis.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,109 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AutoLiveRecorder
{
/// <summary>
/// FLV分析类
/// </summary>
class FLVAnalysis
{
/// <summary>
/// 初始化实例
/// </summary>
/// <param name="filename">文件地址</param>
public FLVAnalysis(string filename)
{
fs = new FileStream(filename, FileMode.Open);
}

/// <summary>
/// 分析
/// </summary>
public void Analysis()
{
byte[] header = new byte[FLV_TAG_HEADER_SIZE];
byte[] tmp;
_i = FLV_HEADER_SIZE + FLV_TAG_SIZE_SIZE;
header = FsRead(FLV_TAG_HEADER_SIZE);
int datasize = GetDataSize(header);
byte[] body = new byte[datasize];
body = FsRead(datasize);
switch (header[0])
{
case 0x08:

break;
case 0x09:

break;
case 0x12:

break;
default:
break;
}
}

private int GetDataSize(byte[] header)
{
byte[] tmp = new byte[3];
Array.Copy(header, 1, tmp, 0, 3);
return BitConverter.ToInt32(tmp, 0);
}

private byte[] FsRead(int count)
{
byte[] tmp = new byte[count];
if (fs.Length < _i + count)
{
fs.Read(tmp, _i, count);
_i += count;
return tmp;
}else
{
fs.Read(tmp, _i, Convert.ToInt32(fs.Length)-_i);
_i = Convert.ToInt32(fs.Length-1);
return tmp;
}


}

private class FLVInfo
{

}


#region Private 字段

private const int FLV_HEADER_SIZE = 9;

private const int FLV_TAG_HEADER_SIZE = 11;

private const int FLV_TAG_SIZE_SIZE = 4;

private FileStream fs;

private int _i;

#endregion Private 字段
}
}
using System;
using System.IO;

namespace AutoLiveRecorder
{
/// <summary>
/// FLV分析类
/// </summary>
internal class FLVAnalysis
{
#region Private 字段

private const int FLV_HEADER_SIZE = 9;

private const int FLV_TAG_HEADER_SIZE = 11;

private const int FLV_TAG_SIZE_SIZE = 4;

private int _i;

private FileStream fs;

#endregion Private 字段

#region Public 构造函数

/// <summary>
/// 初始化实例
/// </summary>
/// <param name="filename">文件地址</param>
public FLVAnalysis(string filename)
{
fs = new FileStream(filename, FileMode.Open);
}

#endregion Public 构造函数

#region Public 方法

/// <summary>
/// 分析
/// </summary>
public void Analysis()
{
byte[] header = new byte[FLV_TAG_HEADER_SIZE];
byte[] tmp;
_i = FLV_HEADER_SIZE + FLV_TAG_SIZE_SIZE;
header = FsRead(FLV_TAG_HEADER_SIZE);
int datasize = GetDataSize(header);
byte[] body = new byte[datasize];
body = FsRead(datasize);
switch (header[0])
{
case 0x08:

break;

case 0x09:

break;

case 0x12:

break;

default:
break;
}
}

#endregion Public 方法

#region Private 方法

private byte[] FsRead(int count)
{
byte[] tmp = new byte[count];
if (fs.Length < _i + count)
{
fs.Read(tmp, _i, count);
_i += count;
return tmp;
}
else
{
fs.Read(tmp, _i, Convert.ToInt32(fs.Length) - _i);
_i = Convert.ToInt32(fs.Length - 1);
return tmp;
}
}

private int GetDataSize(byte[] header)
{
byte[] tmp = new byte[3];
Array.Copy(header, 1, tmp, 0, 3);
return BitConverter.ToInt32(tmp, 0);
}

#endregion Private 方法

#region Private 类

private class FLVInfo
{
}

#endregion Private 类
}
}
26 changes: 15 additions & 11 deletions AutoLiveRecorder/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8561929

Please sign in to comment.