Skip to content

Commit

Permalink
Merge pull request #13 from fediachov/master
Browse files Browse the repository at this point in the history
1.5.5
  • Loading branch information
RadiumByte committed Apr 15, 2020
2 parents 8b2eec2 + ec5c0bd commit 3e81f3c
Show file tree
Hide file tree
Showing 12 changed files with 1,948 additions and 1,695 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Features

- Converting Video to Audio.
- Converting Video to GIF.
- Sequential processing of multiple files.
- Joining several files into one (videos must be with the same resolution).
- Automatically determine the number of threads to encode based on the number of CPU cores.
Expand All @@ -16,8 +17,8 @@

## Video conversion

- Source Video File Formats: `*.avi; *.mov; *.mkv; *.mpg; *.3gp; *.flv; *.vob; *.mp4; *.ts; *.m2ts`.
- Convert to Video Formats: `AVI, MOV, MKV, TS, MP4`.
- Source Video File Formats: `*.avi; *.mov; *.mkv; *.mpg; *.3gp; *.flv; *.vob; *.mp4; *.ts; *.m2ts; *.gif`.
- Convert to Video Formats: `AVI, MOV, MKV, TS, MP4, GIF`.
- Video Codecs: `H.265, H.264, MJPEG, XVID, MPEG2`.
- Adaptive video bitrate.
- Ability to manually adjust the video bitrate (to reduce the size of the output file).
Expand All @@ -33,6 +34,7 @@
- Change the type of scan - progressive / interlaced.
- Selects a specific or all source audio tracks.
- Conversion HDR to SDR.
- Creation GIF images.

## Audio conversion

Expand Down
191 changes: 110 additions & 81 deletions SevenConverter/Actions/ConvertVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public partial class Main : Form
"MOV",
"MKV",
"TS",
"MP4"
"MP4",
"GIF"
};

private bool ConvertVideo(string sourceFile, string destFile, bool quoted = true)
Expand All @@ -59,107 +60,123 @@ private bool ConvertVideo(string sourceFile, string destFile, bool quoted = true
if (Directory.Exists(dest_path))
{
StringBuilder command = new StringBuilder();
// input file and video codec
command.AppendFormat("-hwaccel auto -i {0} -y -v error -vcodec {1}",
quoted ? String.Concat("\"", sourceFile, "\"") : sourceFile,
videoCodec[cbVideoCodec.SelectedIndex]);

// TS format
if (cbFormat.SelectedIndex == 3)
if (cbFormat.SelectedIndex == 5)
{
command.Append(" -f mpegts ");
// copy
if (cbVideoCodec.SelectedIndex == 0)
{
command.Append(" -bsf:v h264_mp4toannexb");
}
// GIF
command.AppendFormat(
"-ss {0} -t {1} -i {2} -vf \"fps={3},scale={4}:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse\" -loop 0",
tbGIFStart.Text,
tbGIFDuration.Text,
quoted ? String.Concat("\"", sourceFile, "\"") : sourceFile,
tbGIFFPS.Text,
tbGIFWidth.Text
);
command.AppendFormat(" -stats -threads 0 \"{0}\"", destFile);
}

// framerate
if (cbFramerate.SelectedIndex > 0)
else
{
command.Append(" -r ").Append(cbFramerate.Text);
}
// input file and video codec
command.AppendFormat("-hwaccel auto -i {0} -y -v error -vcodec {1}",
quoted ? String.Concat("\"", sourceFile, "\"") : sourceFile,
videoCodec[cbVideoCodec.SelectedIndex]);

// interlace
if (cbInterlaced.SelectedIndex > 0)
{
command.Append(interlaced[cbInterlaced.SelectedIndex - 1]);
}
// TS format
if (cbFormat.SelectedIndex == 3)
{
command.Append(" -f mpegts ");
// copy
if (cbVideoCodec.SelectedIndex == 0)
{
command.Append(" -bsf:v h264_mp4toannexb");
}
}

// audio codec
switch (cbAudioCodec.SelectedIndex)
{
case 0:
command.Append(" -acodec copy");
break;
// framerate
if (cbFramerate.SelectedIndex > 0)
{
command.Append(" -r ").Append(cbFramerate.Text);
}

case 1:
command.AppendFormat(" -acodec libmp3lame -ab {0} -ar {1} -ac 2", cbQuality.Text, cbFreq.Text);
break;
// interlace
if (cbInterlaced.SelectedIndex > 0)
{
command.Append(interlaced[cbInterlaced.SelectedIndex - 1]);
}

case 2:
command.AppendFormat(" -acodec ac3 -ab {0} -ar {1}", cbQuality.Text, cbFreq.Text);
break;
// audio codec
switch (cbAudioCodec.SelectedIndex)
{
case 0:
command.Append(" -acodec copy");
break;

case 3:
command.AppendFormat(" -acodec pcm_s16be -ar {0}", cbFreq.Text);
break;
case 1:
command.AppendFormat(" -acodec libmp3lame -ab {0} -ar {1} -ac 2", cbQuality.Text, cbFreq.Text);
break;

default:
command.Append(" -an");
break;
}
case 2:
command.AppendFormat(" -acodec ac3 -ab {0} -ar {1}", cbQuality.Text, cbFreq.Text);
break;

// aspect
if (cbAspect.SelectedIndex > 0)
{
command.AppendFormat(" -aspect {0}", cbAspect.Text);
}
case 3:
command.AppendFormat(" -acodec pcm_s16be -ar {0}", cbFreq.Text);
break;

if (cbLines.SelectedIndex > 0 || cbHDR.SelectedIndex > 0)
{
string rows = String.Empty;
string delim = String.Empty;
default:
command.Append(" -an");
break;
}

// scale
if (cbLines.SelectedIndex > 0)
// aspect
if (cbAspect.SelectedIndex > 0)
{
rows = String.Format("scale=-1:{0}", cbLines.Text);
command.AppendFormat(" -aspect {0}", cbAspect.Text);
}

string hdr = String.Empty;
if (cbHDR.SelectedIndex == 1)
if (cbLines.SelectedIndex > 0 || cbHDR.SelectedIndex > 0)
{
string rows = String.Empty;
string delim = String.Empty;

// scale
if (cbLines.SelectedIndex > 0)
delim = ",";
hdr = "zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p";
{
rows = String.Format("scale=-1:{0}", cbLines.Text);
}

string hdr = String.Empty;
if (cbHDR.SelectedIndex == 1)
{
if (cbLines.SelectedIndex > 0)
delim = ",";
hdr = "zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p";
}

command.AppendFormat(" -vf {0}{1}{2}", rows, delim, hdr);
}

command.AppendFormat(" -vf {0}{1}{2}", rows, delim, hdr);
}
command.Append(GetAudioFilters());

command.Append(GetAudioFilters());
// bitrate
if (cbBitrate.SelectedIndex > 0)
{
command.Append(bitRate[cbBitrate.SelectedIndex - 1]);
}

// bitrate
if (cbBitrate.SelectedIndex > 0)
{
command.Append(bitRate[cbBitrate.SelectedIndex - 1]);
}
// select track
if (cbTrack.SelectedIndex > 0)
{
command.AppendFormat(" -map 0:v? -map 0:s? -map 0:a:{0}", (cbTrack.SelectedIndex - 1).ToString());
}
else
{
command.Append(" -map 0:v? -map 0:s? -map 0:a?");
}

// select track
if (cbTrack.SelectedIndex > 0)
{
command.AppendFormat(" -map 0:v? -map 0:s? -map 0:a:{0}", (cbTrack.SelectedIndex - 1).ToString());
// multithreads
command.AppendFormat(" -stats -scodec copy -threads 0 \"{0}\"", destFile);
}
else
{
command.Append(" -map 0:v? -map 0:s? -map 0:a?");
}

// multithreads
command.AppendFormat(" -stats -scodec copy -threads 0 \"{0}\"", destFile);

// run ffmpeg
using (RunForm runForm = new RunForm())
{
Expand Down Expand Up @@ -215,9 +232,21 @@ private void TurnVideo()
cbLowpass.SelectedIndex = 0;
cbHighpass.SelectedIndex = 0;

cbAudioCodec.SelectedIndex = settings.outputAudioCodec;
cbVideoCodec.SelectedIndex = settings.outputVideoCodec;
cbFormat.SelectedIndex = settings.outputVideoFormat;
if (cbAudioCodec.Items.Count > settings.outputAudioCodec)
cbAudioCodec.SelectedIndex = settings.outputAudioCodec;
else
cbAudioCodec.SelectedIndex = 0;

if (cbVideoCodec.Items.Count > settings.outputVideoCodec)
cbVideoCodec.SelectedIndex = settings.outputVideoCodec;
else
cbVideoCodec.SelectedIndex = 0;

if (cbFormat.Items.Count > settings.outputVideoFormat)
cbFormat.SelectedIndex = settings.outputVideoFormat;
else
cbFormat.SelectedIndex = 0;

cbFreq.Text = "44100";
cbQuality.Text = "320k";
cbFramerate.SelectedIndex = 0;
Expand Down
3 changes: 2 additions & 1 deletion SevenConverter/Forms/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ partial class About : Form
#region Public Constructors

private const string latestURL = "https://github.com/SevenbytesSoftware/SevenConverter/releases/latest";
private const string updateURL = "http://converter.sevenbytes.com/download/";

public About()
{
Expand Down Expand Up @@ -146,7 +147,7 @@ private void btnUpdates_Click(object sender, EventArgs e)
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
Process.Start(latestURL);
Process.Start(updateURL);
}
}
}
Expand Down
Loading

0 comments on commit 3e81f3c

Please sign in to comment.