Skip to content

Commit

Permalink
新增H264的读取视频主要编码设置并应用到当前转码设置的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 28, 2023
1 parent 6de3014 commit a479ca0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion SimpleFFmpegGUI.Core/FFmpegLib/VideoCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class VideoCodec : CodecBase
public static VideoCodec GetCodec(string name)
{
name2codec ??= VideoCodecs.ToDictionary(p => p.Name, p => p);
return name2codec.GetValueOrDefault(name);
return name == null ? null : name2codec.GetValueOrDefault(name);
}


Expand Down
113 changes: 76 additions & 37 deletions SimpleFFmpegGUI.Core/Manager/MediaInfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Mapster;
using Newtonsoft.Json.Linq;
using SimpleFFmpegGUI.Dto;
using SimpleFFmpegGUI.FFmpegLib;
using SimpleFFmpegGUI.Model;
using SimpleFFmpegGUI.Model.MediaInfo;
using System;
Expand Down Expand Up @@ -142,19 +143,26 @@ private static MediaInfoGeneral ParseMediaInfoJSON(JObject json)
public static VideoCodeArguments ConvertToVideoArguments(MediaInfoGeneral mediaInfo)
{
VideoCodeArguments arguments = new VideoCodeArguments();

var tracks = JObject.Parse(mediaInfo.Raw)["media"]["track"] as JArray;
if (mediaInfo.Videos.Count == 0)
{
throw new Exception("源文件不含视频");
}
var video = mediaInfo.Videos[0];

arguments.Code = video.Format switch
{
"AVC" => VideoCodec.X264.Name,
"HEVC" => VideoCodec.X265.Name,
_ => throw new Exception("仅支持H264或H265")
};

if (video.EncodingSettings != null && video.EncodingSettings.Count > 0)
{
var settings = video.EncodingSettings.ToDictionary(p => p.Name, p => p.Value);
try
{
arguments = new VideoCodeArguments();
if (settings["rc"].Equals("crf"))
{
if (settings.ContainsKey("crf"))
Expand Down Expand Up @@ -182,37 +190,76 @@ public static VideoCodeArguments ConvertToVideoArguments(MediaInfoGeneral mediaI
}

int preset = 0;
if (settings.ContainsKey("no-signhide"))
{
preset = 8;
}
else if (settings.ContainsKey("no-sao"))
{
preset = 7;
}
else if (settings["subme"].Equals(1))
{
preset = 6;
}
else if (settings["ref"].Equals(2))
{
preset = 5;
}
else if (settings["max-merge"].Equals(2))
{
preset = 4;
}
else if (settings["ref"].Equals(3))
{
preset = 3;
}
else if (settings["ref"].Equals(4))

if (arguments.Code == VideoCodec.X264.Name)
{
preset = 2;
if (settings["cabac"].Equals(0))
{
preset = 8;
}
else if (settings["subme"].Equals(1))
{
preset = 7;
}
else if (settings["subme"].Equals(2))
{
preset = 6;
}
else if (settings["subme"].Equals(4))
{
preset = 5;
}
else if (settings["subme"].Equals(6))
{
preset = 4;
}
else if (settings["subme"].Equals(7))
{
preset = 3;
}
else if (settings["subme"].Equals(8))
{
preset = 2;
}
else if (settings["subme"].Equals(9))
{
preset = 1;
}
}
else if (settings["max-merge"].Equals(4))
else if (arguments.Code == VideoCodec.X265.Name)
{
preset = 1;
if (settings.ContainsKey("no-signhide"))
{
preset = 8;
}
else if (settings.ContainsKey("no-sao"))
{
preset = 7;
}
else if (settings["subme"].Equals(1))
{
preset = 6;
}
else if (settings["ref"].Equals(2))
{
preset = 5;
}
else if (settings["max-merge"].Equals(2))
{
preset = 4;
}
else if (settings["ref"].Equals(3))
{
preset = 3;
}
else if (settings["ref"].Equals(4))
{
preset = 2;
}
else if (settings["max-merge"].Equals(4))
{
preset = 1;
}
}
arguments.Preset = preset;
}
Expand All @@ -221,14 +268,6 @@ public static VideoCodeArguments ConvertToVideoArguments(MediaInfoGeneral mediaI
throw new Exception("源视频未提供编码设置信息,无法转换为输出参数");
}

arguments.Code = video.Format switch
{
"AVC" => "H264",
"HEVC" => "H265",
_ => video.Format
};


return arguments;
}
}
Expand Down
6 changes: 5 additions & 1 deletion 日志.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,8 @@

## 20230524

【Core】【WPF】基本实现了读取视频主要编码设置并应用到当前转码设置的功能:通过将文件拖放到视频编码设置上方。
【Core】【WPF】基本实现了读取H265视频主要编码设置并应用到当前转码设置的功能:通过将文件拖放到视频编码设置上方。

## 20230528

【Core】新增H264的读取视频主要编码设置并应用到当前转码设置的功能

0 comments on commit a479ca0

Please sign in to comment.