From 1b074c2e6febfc832b8cb66baef46732adf2a7ec Mon Sep 17 00:00:00 2001 From: Aric-Sun Date: Thu, 8 Oct 2020 16:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=9B=A0=E4=B8=BAindexOf?= =?UTF-8?q?=E9=80=A0=E6=88=90=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=A4=9A=E8=8B=B1=E6=96=87=E5=8F=A5=E5=8F=B7=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E7=9A=84=E9=97=AE=E9=A2=98=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E6=8F=90=E5=8F=96=E8=8E=B7=E5=8F=96=E6=97=A0?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=90=8D=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E8=BF=9BUtils=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E8=B0=83=E7=94=A8=20=E4=BF=AE=E5=A4=8D=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8ffmpeg=E5=88=87=E5=89=B2=E8=A7=86=E9=A2=91=E8=A2=ABPot?= =?UTF-8?q?Player=E8=AF=86=E5=88=AB=E4=B8=BA=E9=9F=B3=E9=A2=91=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E7=9B=B8=E5=AF=B9=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E9=81=82=E7=89=88=E6=9C=AC=E5=8F=B7=E5=8D=87=E8=87=B3?= =?UTF-8?q?1.1.0=20=E4=BC=98=E5=8C=96=20=E5=B0=86=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E8=BD=AC=E6=8D=A2=E4=B8=BA=E7=A7=92=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=BD=AC=E7=A7=BB=E5=88=B0Utils=E4=B8=8B=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E8=B0=83=E7=94=A8=EF=BC=8C=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E8=A7=84=E8=8C=83=20=E4=BC=98=E5=8C=96=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84import=20=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?=E5=8F=91=E5=B8=831.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InnoSetupConfig.iss | 10 ++++----- exe4jConfigFile.exe4j | 8 ++++---- src/FLVCutter/FastForwardMpeg.java | 7 ++++--- src/Utils/DataTypeConverter.java | 18 ++++++++++++++++ src/Utils/FileUtils/FilenameUtils.java | 24 ++++++++++++++++++++++ src/XMLGenerator/FlvInteractiveRebase.java | 8 ++++---- src/XMLParsing/DOM/XMLReader.java | 12 ++--------- src/XMLParsing/SAX/XMLReader.java | 2 +- src/XMLParsing/StAX/ParserXML.java | 9 ++++---- 9 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 src/Utils/DataTypeConverter.java create mode 100644 src/Utils/FileUtils/FilenameUtils.java diff --git a/InnoSetupConfig.iss b/InnoSetupConfig.iss index 30aa856..8640acc 100644 --- a/InnoSetupConfig.iss +++ b/InnoSetupConfig.iss @@ -2,7 +2,7 @@ ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "FirstKeyFrameFilter" -#define MyAppVersion "1.0.1-20.10.4" +#define MyAppVersion "1.1.0-20.10.8" #define MyAppPublisher "zsunqian69@gmail.com" #define MyAppURL "https://github.com/Aric-Sun/FirstKeyFrameFilter" #define MyAppExeName "FirstKeyFrameFilter.exe" @@ -25,8 +25,8 @@ AllowNoIcons=yes ; 移除以下行,以在管理安装模式下运行(为所有用户安装)。 PrivilegesRequired=lowest PrivilegesRequiredOverridesAllowed=commandline -OutputDir=D:\Downloads\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar -OutputBaseFilename=FirstKeyFrameFilter1.0.1-20.10.4_Setup +OutputDir=E:\Aric Sun\自学技术\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar +OutputBaseFilename=FirstKeyFrameFilter1.1.0-20.10.8_Setup Compression=lzma SolidCompression=yes WizardStyle=modern @@ -35,8 +35,8 @@ WizardStyle=modern Name: "chinesesimp"; MessagesFile: "compiler:Default.isl" [Files] -Source: "D:\Downloads\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar\FirstKeyFrameFilter\FirstKeyFrameFilter.exe"; DestDir: "{app}"; Flags: ignoreversion -Source: "D:\Downloads\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar\FirstKeyFrameFilter\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "E:\Aric Sun\自学技术\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar\FirstKeyFrameFilter\FirstKeyFrameFilter.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "E:\Aric Sun\自学技术\FirstKeyFrameFilter\out\artifacts\FirstKeyFrameFilter_jar\FirstKeyFrameFilter\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion” [Icons] diff --git a/exe4jConfigFile.exe4j b/exe4jConfigFile.exe4j index 340ebac..f70f36f 100644 --- a/exe4jConfigFile.exe4j +++ b/exe4jConfigFile.exe4j @@ -1,11 +1,11 @@ - - + + - + - + diff --git a/src/FLVCutter/FastForwardMpeg.java b/src/FLVCutter/FastForwardMpeg.java index 05fdb66..5902574 100644 --- a/src/FLVCutter/FastForwardMpeg.java +++ b/src/FLVCutter/FastForwardMpeg.java @@ -1,5 +1,6 @@ package FLVCutter; +import Utils.FileUtils.FilenameUtils; import Utils.RuntimeUtils.LocalCmdExecutor; import java.io.*; @@ -32,9 +33,8 @@ public String cutFlvWithSSTime(String flvPath, double ssTime){ return "-23"; } // 最终生成的文件 - String flvPathCut = flvPath.substring( - 0, flvPath.indexOf(".") - ) + "-cut_" + ssTime + "-end.flv"; + String flvPathCut = FilenameUtils.getFilenameWithoutExtension(flvPath) + + "-cut_" + ssTime + "-end.flv"; //判断目标生成文件是否存在,询问是否覆盖 Path FLVPathCut = Paths.get(flvPathCut); @@ -57,6 +57,7 @@ public String cutFlvWithSSTime(String flvPath, double ssTime){ "-i", flvPath, "-ss", String.valueOf(ssTime), "-c", "copy", + "-copyts", // keep the original timestamps flvPathCut}; // 执行命令 diff --git a/src/Utils/DataTypeConverter.java b/src/Utils/DataTypeConverter.java new file mode 100644 index 0000000..16f1b26 --- /dev/null +++ b/src/Utils/DataTypeConverter.java @@ -0,0 +1,18 @@ +package Utils; + +/** + * 数据类型转换工具类 + * @author AricSun + * @date 2020.10.07 23:02 + */ +public class DataTypeConverter{ + /* + * function: 将timestamp的PTxx.xxS通过正则匹配出浮点型数据 + * @Param: [timeStamp时间戳] + * @Return: java.lang.Double + */ + public static Double TimeStamp2Double(String timeStamp){ + return Double.parseDouble(timeStamp.replaceAll("[^\\d.]", "")); + } + +} diff --git a/src/Utils/FileUtils/FilenameUtils.java b/src/Utils/FileUtils/FilenameUtils.java new file mode 100644 index 0000000..5c95604 --- /dev/null +++ b/src/Utils/FileUtils/FilenameUtils.java @@ -0,0 +1,24 @@ +package Utils.FileUtils; + +/** + * 文件名工具类 + * @author AricSun + * @date 2020.10.07 22:36 + */ +public class FilenameUtils { + /* + * function: 获取不带扩展名的文件名 + * @Param [filename文件名] + * @Return java.lang.String + * from: https://my.oschina.net/liting/blog/535479 + */ + public static String getFilenameWithoutExtension(String filename){ + if ((filename != null) && (filename.length() > 0)){ + int dot = filename.lastIndexOf('.'); + if ((dot > -1) && (dot < filename.length())){ + return filename.substring(0,dot); + } + } + return filename; + } +} diff --git a/src/XMLGenerator/FlvInteractiveRebase.java b/src/XMLGenerator/FlvInteractiveRebase.java index 7baac19..fa30829 100644 --- a/src/XMLGenerator/FlvInteractiveRebase.java +++ b/src/XMLGenerator/FlvInteractiveRebase.java @@ -1,7 +1,6 @@ package XMLGenerator; import Utils.RuntimeUtils.LocalCmdExecutor; -import Utils.RuntimeUtils.ResourcesRelease; import java.io.*; import java.nio.file.Files; @@ -12,6 +11,8 @@ import java.util.Scanner; import java.util.stream.Stream; +import Utils.FileUtils.FilenameUtils; + /** * 调用fib读取flv * errorCodePrefix 1 @@ -37,9 +38,8 @@ public String parseFlvWithFib(String flvPath) { // Path flvFileName = flvPath.getFileName(); // flv文件名,带后缀,不带路径 // Path flvFolderPath = flvPath.getParent(); // flv所在目录路径 // String flvPathStr = String.valueOf(flvPath); - String xmlPath = flvPath.substring(0, - flvPath.lastIndexOf(".") - ).concat(".xml"); // 生成xml的绝对路径 + String xmlPath = FilenameUtils.getFilenameWithoutExtension(flvPath) + .concat(".xml"); // 生成xml的绝对路径 //判断目标生成文件是否存在,询问是否覆盖 Path XMLPath = Paths.get(xmlPath); diff --git a/src/XMLParsing/DOM/XMLReader.java b/src/XMLParsing/DOM/XMLReader.java index 577d831..acc13ea 100644 --- a/src/XMLParsing/DOM/XMLReader.java +++ b/src/XMLParsing/DOM/XMLReader.java @@ -1,5 +1,6 @@ package XMLParsing.DOM; +import Utils.DataTypeConverter; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -86,7 +87,7 @@ public static void main(String[] args) { 此处因废用而不再修复 */ if (CntKeyFrame == 3){ - System.out.println(TimeStamp2Double(timeStamp)); + System.out.println(DataTypeConverter.TimeStamp2Double(timeStamp)); break; } } @@ -94,13 +95,4 @@ public static void main(String[] args) { e.printStackTrace(); } } - - /* - * function: 将timestamp的PTxx.xxS通过正则匹配出浮点型数据 - * @Param: [timeStamp时间戳] - * @Return: java.lang.Double - */ - public static Double TimeStamp2Double(String timeStamp){ - return Double.parseDouble(timeStamp.replaceAll("[^\\d.]", "")); - } } diff --git a/src/XMLParsing/SAX/XMLReader.java b/src/XMLParsing/SAX/XMLReader.java index 7b24060..01a1d0a 100644 --- a/src/XMLParsing/SAX/XMLReader.java +++ b/src/XMLParsing/SAX/XMLReader.java @@ -24,7 +24,7 @@ public static void main(String[] args) { SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(new File("xml/352-TypicalCase.xml"),frameHandler); List frameList = frameHandler.getFrameList(); -// System.out.println(frameList); + System.out.println(frameList); } catch (ParserConfigurationException | SAXException | IOException e) { e.printStackTrace(); } diff --git a/src/XMLParsing/StAX/ParserXML.java b/src/XMLParsing/StAX/ParserXML.java index 9dbb830..60e97d9 100644 --- a/src/XMLParsing/StAX/ParserXML.java +++ b/src/XMLParsing/StAX/ParserXML.java @@ -1,5 +1,6 @@ package XMLParsing.StAX; +import Utils.DataTypeConverter; import dto.Frame; import javax.xml.stream.XMLInputFactory; @@ -12,8 +13,6 @@ import java.util.ArrayList; import java.util.List; -import static XMLParsing.DOM.XMLReader.TimeStamp2Double; - /** * StAX解析XML * StAX与SAX一样是基于XML事件的解析方式, @@ -42,9 +41,9 @@ public class ParserXML { private Frame frame; - public List getFrameList() { + /*public List getFrameList() { return frameList; - } + }*/ private List frameList; @@ -180,7 +179,7 @@ public double readXMLByCursor(String XMLFilePath){ * */ int cntKeyFrame = frameList.size(); if (cntKeyFrame >= 2){ - double secondKeyFrameTime = TimeStamp2Double( + double secondKeyFrameTime = DataTypeConverter.TimeStamp2Double( frameList.get(cntKeyFrame-1).getTimeStamp() ); /* 2020年10月4日