Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
Preview fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CherryPerry committed Jul 11, 2015
1 parent 591f847 commit 75a7d03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
35 changes: 23 additions & 12 deletions VpxEncode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,29 @@ static string DownloadVideo()
return vd.SavePath;
}

static string GetEndTime(string filePath)
{
Regex regex = new Regex(@".*Duration:(\s\d{2,}:\d{2}:\d{2}.\d{1,3}).*");
Match match = regex.Match(new Executer(Executer.FFPROBE).Execute('"' + filePath + '"'));
if (match.Success)
{
string value = match.Groups[1].Value.Trim();
int doti = value.LastIndexOf('.');
int delta = 3 - (value.Length - 1 - doti);
for (int i = 0; i < delta; i++)
value += '0';
return value;
}
return null;
}

static void LookupEndTime(string filePath)
{
if (!ArgList.Get(Arg.END_TIME))
{
Regex regex = new Regex(@".*Duration:(\s\d{2,}:\d{2}:\d{2}.\d{1,3}).*");
Match match = regex.Match(new Executer().Execute('"' + filePath + '"'));
if (match.Success)
{
string value = match.Groups[1].Value.Trim();
int doti = value.LastIndexOf('.');
int delta = 3 - (value.Length - 1 - doti);
for (int i = 0; i < delta; i++)
value += '0';
string value = GetEndTime(filePath);
if (value != null)
ArgList.Get(Arg.END_TIME).Value = value;
}
}
}

Expand Down Expand Up @@ -451,7 +459,7 @@ static void GeneratePreview(string filePath)
// preview.webm
long time = DateTime.Now.ToFileTimeUtc();
string previewWebm = GetFolder(filePath) + "\\preview_" + time.ToString() + ".webm";
string args = String.Format("-ss {0} -i \"{1}\" -c:v vp9 -b:v 0 -crf 4 -t 00:00:00.05 -quality best -an -sn {3} \"{2}\"",
string args = String.Format("-ss {0} -i \"{1}\" -c:v vp9 -b:v 0 -crf 4 -vframes 1 -quality best -an -sn {3} \"{2}\"",
previewTiming,
previewSource,
previewWebm,
Expand All @@ -468,7 +476,10 @@ static void GeneratePreview(string filePath)
ExecuteFFMPEG(args, pu);

// Audio
args = String.Format("-y -i \"{0}\" -itsoffset 00:00:00.05 -i \"{1}\" -map 0:0 -map 1:1 -c copy \"{2}\"", concatedWebm, filePath, output);
string dur = GetEndTime(previewWebm);
if (dur == null)
dur = "0.04";
args = String.Format("-y -i \"{0}\" -itsoffset {3} -i \"{1}\" -map 0:0 -map 1:1 -c copy \"{2}\"", concatedWebm, filePath, output, dur);
ExecuteFFMPEG(args, pu);

// Delete
Expand Down
3 changes: 1 addition & 2 deletions VpxEncode/TimingGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -30,7 +29,7 @@ public void Generate(bool toFile)

void GetTimings(bool toFile)
{
Regex reg = new Regex(@"Chapter #\d:\d: start (\d+.\d+), end (\d+.\d+)");
Regex reg = new Regex(@"Chapter #\d+:\d+: start (\d+.\d+), end (\d+.\d+)");
MatchCollection res = reg.Matches(output);
StringBuilder sb = new StringBuilder();
LinkedList<string> asList = new LinkedList<string>();
Expand Down

0 comments on commit 75a7d03

Please sign in to comment.