Updates to changes done while the server was down

Better reading
Better output
Things which can be final are final
Adds more lines to prevent signs + songs instead of full subtitles
This commit is contained in:
Kristian Knarvik 2020-01-20 20:15:19 +01:00
parent 31637425a3
commit 6143ec9e3c
20 changed files with 238 additions and 1856 deletions

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -3,7 +3,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8.0_191" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FFmpegConvert1.iml" filepath="$PROJECT_DIR$/.idea/FFmpegConvert1.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/FFmpegConvert.iml" filepath="$PROJECT_DIR$/.idea/FFmpegConvert.iml" />
</modules>
</component>
</project>

View File

@ -6,173 +6,33 @@
</artifacts-to-build>
</component>
<component name="ChangeListManager">
<list default="true" id="e9b48a04-29ff-46ce-9630-42742dc34d68" name="Default" comment="Rewrites a lot of code&#10;&#10;Streams are now parsed to objects, making it easier to get required information.&#10;Improved styling.&#10;Some better comments.&#10;Better input parsing.">
<change afterPath="$PROJECT_DIR$/src/ffmpegconverter/streams/AudioStream.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/ffmpegconverter/streams/StreamObject.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/ffmpegconverter/streams/VideoStream.java" afterDir="false" />
<list default="true" id="e9b48a04-29ff-46ce-9630-42742dc34d68" name="Default" comment="Updates to changes done while the server was down&#10;&#10;Better reading&#10;Better output&#10;Things which can be final are final&#10;Adds more lines to prevent signs + songs instead of full subtitles">
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/FFmpegConvert1.iml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/FFmpegConvert.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/pom.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/Main.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/converter/AnimeConverter.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/converter/AudioConverter.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/converter/Converter.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/converter/VideoConverter.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/streams/AudioStream.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/streams/StreamObject.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/streams/SubtitleStream.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/FFmpegConvert/src/main/java/net/knarcraft/ffmpegconvert/streams/VideoStream.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/META-INF/MANIFEST.MF">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" selection-start-line="3" selection-end-line="3" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="398" column="80" selection-start-line="398" selection-start-column="80" selection-end-line="398" selection-end-column="80" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#fileCollisionPrevention#0;class#Converter#0" />
<element signature="docComment;method#read#0;class#Converter#0" />
<element signature="method#read#0;class#Converter#0" />
<element signature="docComment;method#ffmpegWebVideo#0;class#Converter#0" />
<element signature="method#ffmpegWebVideo#0;class#Converter#0" />
<element signature="docComment;method#generalFile#0;class#Converter#0" />
<element signature="method#generalFile#0;class#Converter#0" />
<element signature="docComment;method#listIndexes#0;class#Converter#0" />
<element signature="docComment;method#stringBetween#0;class#Converter#0" />
<element signature="docComment;method#stringBetweenSingle#0;class#Converter#0" />
<element signature="method#stringBetweenSingle#0;class#Converter#0" />
<element signature="e#7792#7793#0" expanded="true" />
<element signature="e#7875#7876#0" expanded="true" />
<element signature="e#7924#7925#0" expanded="true" />
<element signature="e#7987#7988#0" expanded="true" />
<element signature="docComment;method#concatenate#0;class#Converter#0" />
<element signature="method#concatenate#0;class#Converter#0" />
<element signature="docComment;method#parseStreams#0;class#Converter#0" />
<element signature="method#parseStreams#0;class#Converter#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/AudioStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="27" column="5" selection-start-line="27" selection-start-column="5" selection-end-line="27" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="284">
<caret line="47" column="4" selection-start-line="47" selection-start-column="4" selection-end-line="47" selection-end-column="4" />
<folding>
<element signature="e#980#981#0" expanded="true" />
<element signature="e#1066#1067#0" expanded="true" />
<element signature="e#1658#1659#0" expanded="true" />
<element signature="e#1723#1724#0" expanded="true" />
<element signature="e#1809#1810#0" expanded="true" />
<element signature="e#1893#1894#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/VideoStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="38" selection-start-line="3" selection-start-column="38" selection-end-line="3" selection-end-column="38" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/StreamObject.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="191">
<caret line="23" column="4" selection-start-line="23" selection-start-column="4" selection-end-line="23" selection-end-column="4" />
<folding>
<element signature="e#313#314#0" expanded="true" />
<element signature="e#350#351#0" expanded="true" />
<element signature="e#469#470#0" expanded="true" />
<element signature="e#506#507#0" expanded="true" />
<element signature="e#639#640#0" expanded="true" />
<element signature="e#680#681#0" expanded="true" />
<element signature="e#841#842#0" expanded="true" />
<element signature="e#882#883#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="147">
<caret line="71" column="52" lean-forward="true" selection-start-line="71" selection-start-column="52" selection-end-line="71" selection-end-column="52" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#5093#5094#0" expanded="true" />
<element signature="e#5129#5130#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="27" selection-start-line="6" selection-start-column="27" selection-end-line="6" selection-end-column="27" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="395">
<caret line="138" column="53" lean-forward="true" selection-start-line="138" selection-start-column="53" selection-end-line="138" selection-end-column="53" />
<folding>
<element signature="imports" expanded="true" />
<element signature="class#converterArgumentValueType#0;class#Main#0" />
<element signature="method#tokenizer#0;class#Main#0" />
<element signature="method#getList#0;class#Main#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="191">
<caret line="61" column="12" selection-start-line="61" selection-start-column="12" selection-end-line="61" selection-end-column="12" />
<folding>
<element signature="imports" expanded="true" />
<element signature="docComment;method#processFile#0;class#VideoConverter#0" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
@ -204,107 +64,39 @@
<option name="ROOT_SYNC" value="DONT_SYNC" />
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/ffmpegconverter/streams/Video.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/streams/AudioStream.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/streams/StreamObject.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/streams/VideoStream.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/Main.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-7" />
<option name="width" value="974" />
<option name="height" value="1047" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="ffmpegconverter" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="ffmpegconverter" type="462c0819:PsiDirectoryNode" />
<item name="converter" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="ffmpegconverter" type="462c0819:PsiDirectoryNode" />
<item name="streams" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope" />
</panes>
<component name="ProjectId" id="1WfbPiqozXBDbQKoOXR3kRo6QDL" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1570316553479" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../rogue-one-oh-one" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/ffmpegconverter" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.last.edited" value="Problems" />
<property name="project.structure.proportion" value="0.15332031" />
<property name="project.structure.side.proportion" value="0.2" />
<property name="settings.editor.selected.configurable" value="vcs.Git" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Kristian\IdeaProjects\FFmpegConvert1" />
<recent name="$PROJECT_DIR$/src/ffmpegconverter" />
<recent name="C:\Users\Kristian\IdeaProjects\FFmpegConvert" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/.idea" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ffmpegconverter.Main" />
<module name="FFmpegConvert1" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<module name="FFmpegConvert" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ffmpegconverter.*" />
@ -329,6 +121,7 @@
</method>
</configuration>
<configuration default="true" type="TestNG">
<option name="TEST_OBJECT" value="CLASS" />
<option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
<properties />
<listeners />
@ -342,6 +135,18 @@
</list>
</recent_temporary>
</component>
<component name="ServiceViewManager">
<option name="viewStates">
<list>
<serviceView>
<treeState>
<expand />
<select />
</treeState>
</serviceView>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
@ -475,44 +280,6 @@
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1433902" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
<window_info id="UI Designer" order="4" />
<window_info id="Capture Tool" order="5" />
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Duplicate detector" visible="true" weight="0.32936078" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32936078" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.75054705" weight="0.31310943" />
<window_info anchor="bottom" id="Debug" order="3" sideWeight="0.49895614" weight="0.39869988" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" sideWeight="0.49946696" weight="0.32936078" />
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.4989059" weight="0.32827735" />
<window_info anchor="bottom" id="Database Changes" order="8" show_stripe_button="false" />
<window_info anchor="bottom" id="Statistic" order="9" sideWeight="0.49946696" weight="0.32932165" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.4989059" weight="0.32822758" />
<window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.24945295" side_tool="true" weight="0.47811815" />
<window_info anchor="bottom" id="Messages" order="12" sideWeight="0.49840087" weight="0.32719395" />
<window_info anchor="bottom" id="Docker" order="13" show_stripe_button="false" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Palette" order="3" />
<window_info anchor="right" id="Capture Analysis" order="4" />
<window_info anchor="right" id="Theme Preview" order="5" />
<window_info anchor="right" id="Database" order="6" />
<window_info anchor="right" id="Palette&#9;" order="7" />
<window_info anchor="right" id="Maven Projects" order="8" />
<window_info anchor="right" id="Maven" order="9" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
@ -523,231 +290,45 @@
<MESSAGE value="Adds surround to stereo" />
<MESSAGE value="Improves reading of input" />
<MESSAGE value="Rewrites a lot of code&#10;&#10;Streams are now parsed to objects, making it easier to get required information.&#10;Improved styling.&#10;Some better comments.&#10;Better input parsing." />
<option name="LAST_COMMIT_MESSAGE" value="Rewrites a lot of code&#10;&#10;Streams are now parsed to objects, making it easier to get required information.&#10;Improved styling.&#10;Some better comments.&#10;Better input parsing." />
<MESSAGE value="Updates to changes done while the server was down&#10;&#10;Better reading&#10;Better output&#10;Things which can be final are final&#10;Adds more lines to prevent signs + songs instead of full subtitles" />
<option name="LAST_COMMIT_MESSAGE" value="Updates to changes done while the server was down&#10;&#10;Better reading&#10;Better output&#10;Things which can be final are final&#10;Adds more lines to prevent signs + songs instead of full subtitles" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/misc.xml" />
<entry file="file://$PROJECT_DIR$/uiDesigner.xml" />
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="7" lean-forward="true" selection-start-line="2" selection-start-column="7" selection-end-line="2" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/META-INF/MANIFEST.MF">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" selection-start-line="3" selection-end-line="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="27" selection-start-line="6" selection-start-column="27" selection-end-line="6" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/VideoStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="3" column="38" selection-start-line="3" selection-start-column="38" selection-end-line="3" selection-end-column="38" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/AudioStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="27" column="5" selection-start-line="27" selection-start-column="5" selection-end-line="27" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/StreamObject.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="191">
<caret line="23" column="4" selection-start-line="23" selection-start-column="4" selection-end-line="23" selection-end-column="4" />
<folding>
<element signature="e#313#314#0" expanded="true" />
<element signature="e#350#351#0" expanded="true" />
<element signature="e#469#470#0" expanded="true" />
<element signature="e#506#507#0" expanded="true" />
<element signature="e#639#640#0" expanded="true" />
<element signature="e#680#681#0" expanded="true" />
<element signature="e#841#842#0" expanded="true" />
<element signature="e#882#883#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/streams/SubtitleStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="284">
<caret line="47" column="4" selection-start-line="47" selection-start-column="4" selection-end-line="47" selection-end-column="4" />
<folding>
<element signature="e#980#981#0" expanded="true" />
<element signature="e#1066#1067#0" expanded="true" />
<element signature="e#1658#1659#0" expanded="true" />
<element signature="e#1723#1724#0" expanded="true" />
<element signature="e#1809#1810#0" expanded="true" />
<element signature="e#1893#1894#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="398" column="80" selection-start-line="398" selection-start-column="80" selection-end-line="398" selection-end-column="80" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#fileCollisionPrevention#0;class#Converter#0" />
<element signature="docComment;method#read#0;class#Converter#0" />
<element signature="method#read#0;class#Converter#0" />
<element signature="docComment;method#ffmpegWebVideo#0;class#Converter#0" />
<element signature="method#ffmpegWebVideo#0;class#Converter#0" />
<element signature="docComment;method#generalFile#0;class#Converter#0" />
<element signature="method#generalFile#0;class#Converter#0" />
<element signature="docComment;method#listIndexes#0;class#Converter#0" />
<element signature="docComment;method#stringBetween#0;class#Converter#0" />
<element signature="docComment;method#stringBetweenSingle#0;class#Converter#0" />
<element signature="method#stringBetweenSingle#0;class#Converter#0" />
<element signature="e#7792#7793#0" expanded="true" />
<element signature="e#7875#7876#0" expanded="true" />
<element signature="e#7924#7925#0" expanded="true" />
<element signature="e#7987#7988#0" expanded="true" />
<element signature="docComment;method#concatenate#0;class#Converter#0" />
<element signature="method#concatenate#0;class#Converter#0" />
<element signature="docComment;method#parseStreams#0;class#Converter#0" />
<element signature="method#parseStreams#0;class#Converter#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="191">
<caret line="61" column="12" selection-start-line="61" selection-start-column="12" selection-end-line="61" selection-end-column="12" />
<folding>
<element signature="imports" expanded="true" />
<element signature="docComment;method#processFile#0;class#VideoConverter#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="395">
<caret line="138" column="53" lean-forward="true" selection-start-line="138" selection-start-column="53" selection-end-line="138" selection-end-column="53" />
<folding>
<element signature="imports" expanded="true" />
<element signature="class#converterArgumentValueType#0;class#Main#0" />
<element signature="method#tokenizer#0;class#Main#0" />
<element signature="method#getList#0;class#Main#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="147">
<caret line="71" column="52" lean-forward="true" selection-start-line="71" selection-start-column="52" selection-end-line="71" selection-end-column="52" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#5093#5094#0" expanded="true" />
<element signature="e#5129#5130#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
<state key="ArtifactsStructureConfigurable.UI">
<settings>
<artifact-editor />
<last-edited>FFmpegConvert</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.5" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="FacetStructureConfigurable.UI">
<settings>
<last-edited>No facets are configured</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="GlobalLibrariesConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="JdkListConfigurable.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ModuleStructureConfigurable.UI">
<settings>
<last-edited>FFmpegConvert1</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.6" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectLibrariesConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
<component name="WindowStateProjectService">
<state x="379" y="60" key="#Main" timestamp="1579543971698">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state x="379" y="60" key="#Main/0.36.1366.732@0.36.1366.732" timestamp="1579543971698" />
<state x="0" y="36" width="1366" height="732" key="CommitChangelistDialog2" timestamp="1579545452859">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state x="0" y="36" width="1366" height="732" key="CommitChangelistDialog2/0.36.1366.732@0.36.1366.732" timestamp="1579545452859" />
<state width="1320" height="162" key="GridCell.Tab.0.bottom" timestamp="1579544838853">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state width="1320" height="162" key="GridCell.Tab.0.bottom/0.36.1366.732@0.36.1366.732" timestamp="1579544838853" />
<state width="1320" height="162" key="GridCell.Tab.0.center" timestamp="1579544838853">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state width="1320" height="162" key="GridCell.Tab.0.center/0.36.1366.732@0.36.1366.732" timestamp="1579544838853" />
<state width="1320" height="162" key="GridCell.Tab.0.left" timestamp="1579544838848">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state width="1320" height="162" key="GridCell.Tab.0.left/0.36.1366.732@0.36.1366.732" timestamp="1579544838848" />
<state width="1320" height="162" key="GridCell.Tab.0.right" timestamp="1579544838853">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state width="1320" height="162" key="GridCell.Tab.0.right/0.36.1366.732@0.36.1366.732" timestamp="1579544838853" />
<state x="0" y="36" width="1032" height="732" key="SettingsEditor" timestamp="1579544527545">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state x="0" y="36" width="1032" height="732" key="SettingsEditor/0.36.1366.732@0.36.1366.732" timestamp="1579544527545" />
<state x="279" y="136" key="Vcs.Push.Dialog.v2" timestamp="1579547079762">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state x="279" y="136" key="Vcs.Push.Dialog.v2/0.36.1366.732@0.36.1366.732" timestamp="1579547079762" />
<state x="364" y="230" key="com.intellij.ide.util.TipDialog" timestamp="1579543587189">
<screen x="0" y="36" width="1366" height="732" />
</state>
<state x="364" y="230" key="com.intellij.ide.util.TipDialog/0.36.1366.732@0.36.1366.732" timestamp="1579543587189" />
</component>
</project>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.knarcraft</groupId>
<artifactId>FFmpegConvert</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>

View File

@ -1,352 +0,0 @@
package net.knarcraft.ffmpegconvert;
import ffmpegconverter.converter.AnimeConverter;
import ffmpegconverter.converter.AudioConverter;
import ffmpegconverter.converter.Converter;
import ffmpegconverter.converter.VideoConverter;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Predicate;
/**
* Converts a files or files in a folder to a web playable mp4.
*/
public class Main {
private static final String FFPROBE_PATH = "ffprobe"; //Can be just ffprobe if it's in the path
private static final String FFMPEG_PATH = "ffmpeg"; //Can be just ffmpeg if it's in the path
private static final Scanner READER = new Scanner(System.in, "UTF-8");
private static final BufferedWriter WRITER = new BufferedWriter(new OutputStreamWriter(System.out));
private static Converter con = null;
public static void main(String[] args) throws IOException {
//System.out.println(tokenizer("AnimeConverter -audiolang jap,eng -sublang eng,nor,* \"C:\\Users\\Kristian\\Downloads\\Anime\\[Kametsu] ERASED (BD 1080p Hi10 FLAC)\""));
//parser(tokenizer("AnimeConverter \"C:\\Users\\Kristian\\Downloads\\Anime\\[Kametsu] ERASED (BD 1080p Hi10 FLAC)\""));
//System.exit(1);
int choice = getChoice("Which converter do you want do use?\n1. Anime to web mp4\n2. Audio converter\n3. VideoStream converter", 1, 3);
printl("Input for this converter:");
switch (choice) {
case 1:
animeConverter();
break;
case 2:
con = new AudioConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
break;
case 3:
con = new VideoConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
break;
default:
System.exit(1);
}
int recursionSteps = 1;
printl("<Folder/File> [Recursions]: ");
List<String> input = readInput(2);
while (input.isEmpty()) {
print("File path required.");
input = readInput(2);
}
File folder = new File(input.get(0));
if (input.size() > 1) {
try {
recursionSteps = Integer.parseInt(input.get(1));
} catch (NumberFormatException e) {
printl("Recursion steps is invalid and will be ignored.");
}
}
if (folder.isDirectory()) {
File[] files = listFilesRec(folder, con.getValidFormats(), recursionSteps);
if (files != null && files.length > 0) {
for (File file : files) {
con.convert(file);
}
} else {
printl("No valid files found in folder.");
}
} else if (folder.exists()) {
con.convert(folder);
} else {
System.out.println("Path " + folder.getAbsolutePath() + " does not point to any file or folder.");
}
WRITER.close();
}
/**
* Prints a string
* @param input <p>The string to print.</p>
* @throws IOException
*/
private static void print(String input) throws IOException {
WRITER.write(input);
WRITER.flush();
}
/**
* Prints a string and a line break
* @param input <p>The string to print.</p>
* @throws IOException
*/
private static void printl(String input) throws IOException {
WRITER.write(input);
WRITER.newLine();
WRITER.flush();
}
private enum converterArgumentValueType {
BOOLEAN,
COMMA_SEPARATED_LIST,
SINGLE_VALUE,
INT
}
private static class converterArgument {
private String name;
private boolean valueRequired;
private converterArgumentValueType valueType;
private converterArgument(String name, boolean valueRequired, converterArgumentValueType valueType) {
this.name = name;
this.valueRequired = valueRequired;
this.valueType = valueType;
}
private boolean testArgumentValue(String value) {
if (value.length() == 0) {
return !valueRequired;
}
if (valueRequired && value.startsWith("-")) {
return false;
}
switch (valueType) {
case BOOLEAN:
String lower = value.toLowerCase();
return lower.equals("true") || lower.equals("false");
case COMMA_SEPARATED_LIST:
return !value.contains(" ");
case SINGLE_VALUE:
return !value.contains(" ");
case INT:
Integer.parseInt(value);
return true;
}
return false;
}
}
private static void parser(List<String> tokens) {
String[] types = {"animeconverter", "audioconverter", "videoconverter"};
converterArgument[] commonArgs = {
new converterArgument("-recursions", true, converterArgumentValueType.INT)
};
converterArgument[] animeArgs = {
};
converterArgument[] audioArgs = {
new converterArgument("-outext", true, converterArgumentValueType.SINGLE_VALUE)
};
converterArgument[] videoArgs = {
new converterArgument("-outext", true, converterArgumentValueType.SINGLE_VALUE)
};
String type = tokens.get(0).toLowerCase();
if (!listContains(types, s -> s.equals(type))) {
throw new IllegalArgumentException("Unknown converter type chosen.");
}
if (tokens.size() < 2) {
throw new IllegalArgumentException("No file/folder path in argument.");
}
for (int i = 1; i < tokens.size() - 1; i++) {
//TODO: Find the type of argument and check the value
//TODO: Find an executable way to represent the chain of commands parsed
}
}
/**
* Tokenizes a string
* @param input <p>A string.</p>
* @return <p>A list of tokens.</p>
*/
private static List<String> tokenizer(String input) {
List<String> tokens = new ArrayList<>();
boolean startedQuote = false;
StringBuilder currentToken = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
switch (c) {
case ' ':
if (!startedQuote) {
//If not inside "", a space marks the end of a parameter
if (!currentToken.toString().trim().equals("")) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
} else {
currentToken = new StringBuilder();
}
} else {
currentToken.append(c);
}
break;
case '"':
if (startedQuote) {
if (!currentToken.toString().trim().equals("")) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
}
startedQuote = false;
} else {
startedQuote = true;
currentToken = new StringBuilder();
} break;
default:
currentToken.append(c);
if (i == input.length() - 1) {
tokens.add(currentToken.toString());
} break;
}
}
return tokens;
}
/**
* Initializes the anime converter
* @throws IOException
*/
private static void animeConverter() throws IOException {
printl("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: ");
List<String> input = readInput(4);
String[] audioLang = new String[]{"jpn", "*"};
String[] subtitleLang = new String[]{"eng", "*"};
boolean toStereo = true;
boolean preventSigns = true;
if (input.size() > 0 && getList(input, 0) != null) {
audioLang = getList(input, 0);
}
if (input.size() > 1 && getList(input, 1) != null) {
subtitleLang = getList(input, 1);
}
if (input.size() > 2) {
toStereo = Boolean.parseBoolean(input.get(2));
}
if (input.size() > 3) {
preventSigns = Boolean.parseBoolean(input.get(3));
}
con = new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLang, subtitleLang, toStereo, preventSigns);
}
/**
* Gets a list from a comma separated string at index in list
* @param list <p>A list of tokens.</p>
* @param index <p>The index of the token containing comma separated entries.</p>
* @return <p>A string list.</p>
*/
private static String[] getList(List<String> list, int index) {
String[] result = null;
if (list.size() > index) {
if (list.get(index).contains(",")) {
result = list.get(index).split(",");
} else {
result = new String[]{list.get(index)};
}
}
return result;
}
/**
* Reads a number of tokens from the user input
* @param max <p>The number of tokens expected.</p>
* @return <p>A list of tokens.</p>
*/
private static List<String> readInput(int max) {
List<String> tokens = tokenizer(READER.nextLine());
if (max < tokens.size()) {
throw new IllegalArgumentException("Input contains " + tokens.size() +
" arguments, but the input only supports " + max + " arguments.");
}
return tokens;
}
/**
* Gets the user's choice
* @param prompt <p>The prompt shown to the user.</p>
* @return <p>The non-empty choice given by the user.</p>
* @throws IOException
*/
private static String getChoice(String prompt) throws IOException {
printl(prompt);
String choice = "";
while (choice.equals("")) {
printl("Your input: ");
choice = READER.nextLine();
}
return choice;
}
/**
* Gets an integer from the user
* @param prompt The prompt to give the user
* @param min The minimum allowed value
* @param max The maximum allowed value
* @return The value given by the user
*/
private static int getChoice(String prompt, int min, int max) throws IOException {
printl(prompt);
int choice = 0;
while (choice < min || choice > max) {
printl("Your input: ");
try {
choice = Integer.parseInt(READER.next());
} catch (NumberFormatException e) {
printl("Invalid choice. Please try again.");
} finally {
READER.nextLine();
}
}
return choice;
}
/**
* Tests if any element in a list fulfills a condition.
*
* @param list The list to test against
* @param predicate A predicate to use on every element in the list
* @param <T> Anything which can be stored in a list
* @return True if at least one element fulfills the predicate
*/
private static <T> boolean listContains(T[] list, Predicate<T> predicate) {
for (T item : list) {
if (predicate.test(item)) {
return true;
}
}
return false;
}
/**
* Recursively lists all files in a folder
*
* @param folder The folder to start from
* @param maxRec Maximum number of recursions
* @return A list of files
*/
private static File[] listFilesRec(File folder, String[] extensions, int maxRec) {
if (maxRec == 0) { return null; }
File[] listOfFiles = folder.listFiles((file) -> file.isFile() && listContains(extensions, (item) -> file.getName().endsWith(item)));
if (listOfFiles == null) { return null; }
if (maxRec > 1) {
File[] listOfFolders = folder.listFiles((dir, name) -> new File(dir, name).isDirectory());
if (listOfFolders != null) {
for (File file : listOfFolders) {
File[] nextLevel = listFilesRec(file, extensions, maxRec - 1);
if (nextLevel != null) {
listOfFiles = Converter.concatenate(listOfFiles, nextLevel);
}
}
}
}
return listOfFiles;
}
}

View File

@ -1,130 +0,0 @@
package ffmpegconverter.converter;
import ffmpegconverter.streams.AudioStream;
import ffmpegconverter.streams.StreamObject;
import ffmpegconverter.streams.SubtitleStream;
import ffmpegconverter.streams.VideoStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class AnimeConverter extends Converter {
private String[] audioLang;
private String[] subtitleLang;
private boolean toStereo;
private boolean preventSignsAndSongs;
private boolean debug = false;
/**
* @param ffprobePath Path/command to ffprobe
* @param ffmpegPath Path/command to ffmpeg
* @param audioLang List of wanted audio languages in descending order
* @param subtitleLang List of wanted subtitle languages in descending order
* @param toStereo Convert video with several audio channels to stereo
* @param preventSignsAndSongs Prevent subtitles only converting signs and songs (not speech)
*/
public AnimeConverter(String ffprobePath, String ffmpegPath, String[] audioLang, String[] subtitleLang, boolean toStereo, boolean preventSignsAndSongs) {
this.ffprobePath = ffprobePath;
this.ffmpegPath = ffmpegPath;
this.audioLang = audioLang;
this.subtitleLang = subtitleLang;
this.toStereo = toStereo;
this.preventSignsAndSongs = preventSignsAndSongs;
}
public void convert(File file) throws IOException {
processFile(file.getParentFile(), file);
}
/**
* Reads streams from a file, and converts it to an mp4.
*
* @param folder The folder of the file to process
* @param file The file to process
* @throws IOException If the BufferedReader fails
*/
private void processFile(File folder, File file) throws IOException {
List<StreamObject> streams = probeFile(ffprobePath, file);
if (streams.isEmpty()) {
throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and is not corrupt.");
}
String newPath = fileCollisionPrevention(folder.getAbsolutePath() + File.separator + stripExtension(file) + ".mp4", "mp4");
printl("Preparing to start process...");
String[] command = builderCommand(ffmpegPath, file.getName(), streams, newPath);
ProcessBuilder processBuilder = new ProcessBuilder(command);
convertProcess(processBuilder, folder);
}
/**
* Generates a command for a ProcessBuilder.
*
* @param executable The executable file for ffmpeg
* @param fileName The input file
* @param streams A list of ffprobe streams
* @param outFile The output file
* @return A list of commands
*/
private String[] builderCommand(String executable, String fileName, List<StreamObject> streams, String outFile) {
List<String> command = ffmpegWebVideo(executable, fileName);
if (this.debug) {
addDebug(command, 50, 120);
}
List<AudioStream> audioStreams = filterStreamsByType(streams, "audio");
List<VideoStream> videoStreams = filterStreamsByType(streams, "video");
List<SubtitleStream> subtitleStreams = filterStreamsByType(streams, "subtitle");
audioStreams = filterAudioStreams(audioStreams, audioLang);
subtitleStreams = filterSubtitleStreams(subtitleStreams, subtitleLang, preventSignsAndSongs);
VideoStream videoStream = null;
AudioStream audioStream = null;
SubtitleStream subtitleStream = null;
if (videoStreams.size() > 0) {
videoStream = videoStreams.get(0);
}
if (audioStreams.size() > 0) {
audioStream = audioStreams.get(0);
}
if (subtitleStreams.size() > 0) {
subtitleStream = subtitleStreams.get(0);
}
if (videoStream == null) {
throw new IllegalArgumentException("The file does not have any valid video streams.");
}
if (audioStream != null) {
command.add("-map");
command.add("0:" + audioStream.getAbsoluteIndex());
if (toStereo && audioStream.getChannels() > 2) {
command.add("-af");
command.add("pan=stereo|FL=FC+0.30*FL+0.30*BL|FR=FC+0.30*FR+0.30*BR");
}
}
if (subtitleStream != null && subtitleStream.getIsImageSubtitle()) {
command.add("-filter_complex");
command.add("[0:v:" + videoStream.getAbsoluteIndex() + "][0:" + subtitleStream.getAbsoluteIndex() + "]overlay");
} else if (subtitleStream != null) {
command.add("-map");
command.add("0:" + videoStream.getAbsoluteIndex());
command.add("-vf");
command.add("subtitles='" + fileName.replace("'", "\'") + "':si=" +
subtitleStream.getRelativeIndex());
} else {
command.add("-map");
command.add("0:" + videoStream.getAbsoluteIndex());
}
command.add(outFile);
return command.toArray(new String[0]);
}
@Override
public String[] getValidFormats() {
return VIDEO_FORMATS;
}
}

View File

@ -1,68 +0,0 @@
package ffmpegconverter.converter;
import ffmpegconverter.streams.AudioStream;
import ffmpegconverter.streams.StreamObject;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class AudioConverter extends Converter {
private String newExt;
public AudioConverter(String ffprobePath, String ffmpegPath, String newExt) {
this.ffprobePath = ffprobePath;
this.ffmpegPath = ffmpegPath;
this.newExt = newExt;
}
/**
* Reads streams from a file, and converts it to an mp4.
*
* @param folder The folder of the file to process
* @param file The file to process
* @throws IOException If the BufferedReader fails
*/
private void processFile(File folder, File file, String newExt) throws IOException {
List<StreamObject> streams = probeFile(ffprobePath, file);
if (streams.size() == 0) {
throw new IllegalArgumentException("The file has no streams");
}
String newPath = stripExtension(file) + "." + newExt;
convertProcess(new ProcessBuilder(builderCommand(ffmpegPath, file.getName(), streams, newPath)), folder);
}
/**
* Generates a command for a ProcessBuilder.
*
* @param executable The executable file for ffmpeg
* @param fileName The input file
* @param streams A list of ffprobe streams
* @param outFile The output file
* @return A list of commands
*/
private String[] builderCommand(String executable, String fileName, List<StreamObject> streams, String outFile) {
List<String> command = generalFile(executable, fileName);
List<AudioStream> audioStreams = filterStreamsByType(streams, "audio");
AudioStream audioStream = null;
if (audioStreams.size() > 0) {
audioStream = audioStreams.get(0);
}
if (audioStreams.size() > 0) {
command.add("-map");
command.add("0:" + audioStream.getAbsoluteIndex());
}
command.add(outFile);
return command.toArray(new String[0]);
}
@Override
public String[] getValidFormats() {
return AUDIO_FORMATS;
}
@Override
public void convert(File file) throws IOException {
processFile(file.getParentFile(), file, newExt);
}
}

View File

@ -1,441 +0,0 @@
package ffmpegconverter.converter;
import ffmpegconverter.streams.AudioStream;
import ffmpegconverter.streams.StreamObject;
import ffmpegconverter.streams.SubtitleStream;
import ffmpegconverter.streams.VideoStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
/**
* Implements all methods which can be usefull for any implementation of a converter.
*/
public abstract class Converter {
String ffprobePath;
String ffmpegPath;
private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
public abstract String[] getValidFormats();
public abstract void convert(File file) throws IOException;
final String[] AUDIO_FORMATS = new String[] {".3gp", ".aa", ".aac", ".aax", ".act", ".aiff", ".amr", ".ape", ".au",
".awb", ".dct", ".dss", ".dvf", ".flac", ".gsm", ".iklax", ".ivs", ".m4a", ".m4b", ".m4p", ".mmf", ".mp3",
".mpc", ".msv", ".ogg", ".oga", ".mogg", ".opus", ".ra", ".rm", ".raw", ".sln", ".tta", ".vox", ".wav",
".wma", ".wv", ".webm", ".8svx"};
final String[] VIDEO_FORMATS = new String[] {".avi", ".mpg", ".mpeg", ".mkv", ".wmv", ".flv", ".webm", ".3gp",
".rmvb", ".3gpp", ".mts", ".m4v", ".mov", ".rm", ".asf", ".mp4", ".vob", ".ogv", ".drc", ".qt", ".yuv",
".asm", ".m4p", ".mp2", ".mpe", ".mpv", ".m2v", ".svi", ".3g2", ".roq", ".nsv"};
/**
* Gets streams from a file
* @param ffprobePath The path/command to ffprobe
* @param file The file to probe
* @return A list of StreamObjects
* @throws IOException If the process can't be read
*/
static List<StreamObject> probeFile(String ffprobePath, File file) throws IOException {
ProcessBuilder builderProbe = new ProcessBuilder(
ffprobePath,
"-v",
"error",
"-show_entries",
"stream_tags=language,title:stream=index,codec_name,codec_type,channels",
file.toString()
);
print("Probe command: ");
printl(builderProbe.command().toString());
builderProbe.redirectErrorStream(true);
Process processProbe = builderProbe.start();
BufferedReader readerProbe = new BufferedReader(new InputStreamReader(processProbe.getInputStream()));
StringBuilder output = new StringBuilder();
while (processProbe.isAlive()) {
String read = read(readerProbe, PROBE_SPLIT_CHARACTER);
if (!read.equals("")) {
print(read);
output.append(read);
}
}
return parseStreams(stringBetween(output.toString(), "[STREAM]", "[/STREAM]"));
}
static String fileCollisionPrevention(String targetPath, String extension) {
File file = new File(targetPath);
int i = 1;
while (file.exists()) {
file = new File(stripExtension(file) + "(" + i + ")" + "." + extension);
}
return file.toString();
}
/**
* Starts and prints output of a process
* @param process The process to run
* @param folder The folder the process should run in
* @throws IOException If the process can't be read
*/
static void convertProcess(ProcessBuilder process, File folder) throws IOException {
print("Command to be run: ");
printl(process.command().toString());
process.directory(folder);
process.redirectErrorStream(true);
Process processConvert = process.start();
BufferedReader readerConvert = new BufferedReader(new InputStreamReader(processConvert.getInputStream()));
while (processConvert.isAlive()) {
String read = read(readerConvert, "\n");
if (!read.equals("")) {
printl(read);
}
}
printl("FFMPEG is finished.");
}
/**
* Reads from a process reader.
*
* @param reader The reader of a process
* @return The output from the read
* @throws IOException On reader failure
*/
private static String read(BufferedReader reader, String spacer) throws IOException {
String line;
StringBuilder text = new StringBuilder();
while (reader.ready() && (line = reader.readLine()) != null && !line.equals("") && !line.equals("\n")) {
text.append(line).append(spacer);
}
return text.toString().trim();
}
/**
* @return A base list of ffmpeg commands for converting a video for web
*/
static List<String> ffmpegWebVideo(String executable, String fileName) {
List<String> command = generalFile(executable, fileName);
command.add("-vcodec");
command.add("h264");
command.add("-pix_fmt");
command.add("yuv420p");
command.add("-ar");
command.add("48000");
command.add("-movflags");
command.add("+faststart");
return command;
}
/**
* @return A base list of ffmpeg commands for converting a file
*/
static List<String> generalFile(String executable, String fileName) {
List<String> command = new ArrayList<>();
command.add(executable);
command.add("-nostdin");
command.add("-i");
command.add(fileName);
return command;
}
/**
* Adds debugging parameters for only converting parts of a file
* @param command The list containing the command to run
* @param start The offset before converting
* @param length The offset for stopping the conversion
*/
static void addDebug(List<String> command, int start, int length) {
command.add("-ss");
command.add("" + start);
command.add("-t");
command.add("" + length);
}
/**
* Lists all indexes fulfilling a predicate.
*
* @param list A list of ffprobe indexes
* @return An integer list containing just the wanted indexes
*/
private static List<Integer> listIndexes(String[] list, Predicate<String> p) {
List<Integer> indexes = new ArrayList<>();
for (String str : list) {
if (p.test(str)) {
indexes.add(Integer.parseInt(stringBetweenSingle(str, "index=", PROBE_SPLIT_CHARACTER)));
}
}
return indexes;
}
/**
* Tests a predicate on a list
* @param list A list
* @param p A predicate
* @param <T> Any type
* @return True if the list have an element for which the predicate is true
*/
private static <T> boolean testPredicate(T[] list, Predicate<T> p) {
for (T o : list) {
if (p.test(o)) {
return true;
}
}
return false;
}
/**
* Finds all substrings between two substrings in a string.
*
* @param string The string containing the substrings
* @param start The substring before the wanted substring
* @param end The substring after the wanted substring
* @return A list of all occurrences of the substring
*/
private static String[] stringBetween(String string, String start, String end) {
int startPos = string.indexOf(start) + start.length();
if (!string.contains(start) || string.indexOf(end, startPos) < startPos) {
return new String[]{};
}
int endPos = string.indexOf(end, startPos);
String outString = string.substring(startPos, endPos).trim();
String nextString = string.substring(endPos + end.length());
return concatenate(new String[]{outString}, stringBetween(nextString, start, end));
}
/**
* Finds a substring between two substrings in a string.
*
* @param string The string containing the substrings
* @param start The substring before the wanted substring
* @param end The substring after the wanted substring
* @return The wanted substring.
*/
private static String stringBetweenSingle(String string, String start, String end) {
int startPos = string.indexOf(start) + start.length();
if (!string.contains(start) || string.indexOf(end, startPos) < startPos) {
return "";
}
return string.substring(startPos, string.indexOf(end, startPos));
}
/**
* Gets filename without extension from File object
* @param file A file object
* @return A filename
*/
static String stripExtension(File file) {
return file.getName().substring(0, file.getName().lastIndexOf('.'));
}
/**
* Removes the extension from a file name
* @param file A filename
* @return A filename without its extension
*/
static String stripExtension(String file) {
return file.substring(0, file.lastIndexOf('.'));
}
/**
* Combines two arrays to one
*
* @param a The first array
* @param b The second array
* @param <T> Any type
* @return A new array containing all elements from the two arrays
*/
public static <T> T[] concatenate(T[] a, T[] b) {
int aLen = a.length;
int bLen = b.length;
@SuppressWarnings("unchecked")
T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(), aLen + bLen);
System.arraycopy(a, 0, c, 0, aLen);
System.arraycopy(b, 0, c, aLen, bLen);
return c;
}
/**
* Filters parsed streams into one of the stream types
* @param streams A list of stream objects
* @param codecType The codec type of the streams to select
* @param <G> The correct object type for the streams with the selected codec type
* @return A potentially shorter list of streams
*/
static <G extends StreamObject> List<G> filterStreamsByType(List<StreamObject> streams, String codecType) {
Iterator<StreamObject> i = streams.iterator();
List<G> newStreams = new ArrayList<>();
while (i.hasNext()) {
StreamObject next = i.next();
if (next.getCodecType().equals(codecType)) {
newStreams.add((G) next);
}
}
return newStreams;
}
/**
* Filters and sorts audio streams according to chosen languages
* @param audioStreams A list of audio streams
* @param audioLanguages A list of languages
* @return A list containing just audio tracks of chosen languages, sorted in order of languages
*/
static List<AudioStream> filterAudioStreams(List<AudioStream> audioStreams, String[] audioLanguages) {
List<AudioStream> filtered = new ArrayList<>();
for (String language : audioLanguages) {
for (AudioStream stream : audioStreams) {
if ((stream.getLanguage() != null && stream.getLanguage().equals(language)) || language.equals("*")) {
filtered.add(stream);
}
}
//Tries to reduce execution time from n^2
audioStreams.removeAll(filtered);
}
return filtered;
}
/**
* Filters and sorts subtitle streams according to chosen languages
* @param subtitleStreams A list of subtitle streams
* @param subtitleLanguages A list of languages
* @param preventSignsAndSongs Whether partial subtitles should be avoided
* @return A list containing just subtitles of chosen languages, sorted in order of languages
*/
static List<SubtitleStream> filterSubtitleStreams(List<SubtitleStream> subtitleStreams, String[] subtitleLanguages,
boolean preventSignsAndSongs) {
List<SubtitleStream> filtered = new ArrayList<>();
//Go through languages. Select all subtitles of the language
for (String language : subtitleLanguages) {
for (SubtitleStream stream : subtitleStreams) {
String streamLanguage = stream.getLanguage();
if (((streamLanguage != null && streamLanguage.equals(language)) || language.equals("*")) &&
(!preventSignsAndSongs || stream.getIsFullSubtitle())) {
filtered.add(stream);
}
}
//Tries to reduce execution time from n^2
subtitleStreams.removeAll(filtered);
}
return filtered;
}
/**
* Takes a list of all streams and parses each stream into one of three objects
* @param streams A list of all streams for the current file
* @return A list of StreamObjects
*/
private static List<StreamObject> parseStreams(String[] streams) {
List<StreamObject> parsedStreams = new ArrayList<>();
int relativeAudioIndex = 0;
int relativeVideoIndex = 0;
int relativeSubtitleIndex = 0;
for (String stream : streams) {
String[] streamParts = stream.split(PROBE_SPLIT_CHARACTER);
if (stream.contains("codec_type=video")) {
parsedStreams.add(parseVideoStream(streamParts, relativeVideoIndex++));
} else if (stream.contains("codec_type=audio")) {
parsedStreams.add(parseAudioStream(streamParts, relativeAudioIndex++));
} else if (stream.contains("codec_type=subtitle")) {
parsedStreams.add(parseSubtitleStream(streamParts, relativeSubtitleIndex++));
}
}
return parsedStreams;
}
/**
* Parses a list of video stream parameters to a video stream object
* @param streamParts A list of parameters belonging to an video stream
* @param relativeIndex The relative index of the video stream
* @return A SubtitleStream object
* @throws NumberFormatException If codec index contains a non-numeric value
*/
private static VideoStream parseVideoStream(String[] streamParts, int relativeIndex) throws NumberFormatException {
String codec = null;
int absoluteIndex = -1;
for (String streamPart : streamParts) {
if (streamPart.contains("codec_name=")) {
codec = streamPart.replace("codec_name=", "");
} else if (streamPart.contains("index=")) {
absoluteIndex = Integer.parseInt(streamPart.replace("index=", ""));
}
}
return new VideoStream(codec, absoluteIndex, relativeIndex);
}
/**
* Parses a list of audio stream parameters to an audio stream object
* @param streamParts A list of parameters belonging to an audio stream
* @param relativeIndex The relative index of the audio stream
* @return A SubtitleStream object
* @throws NumberFormatException If codec index contains a non-numeric value
*/
private static AudioStream parseAudioStream(String[] streamParts, int relativeIndex) throws NumberFormatException {
String codec = null;
int absoluteIndex = -1;
String language = null;
int channels = 0;
String title = "";
for (String streamPart : streamParts) {
if (streamPart.contains("codec_name=")) {
codec = streamPart.replace("codec_name=", "");
} else if (streamPart.contains("index=")) {
absoluteIndex = Integer.parseInt(streamPart.replace("index=", ""));
} else if (streamPart.contains("TAG:language=")) {
language = streamPart.replace("TAG:language=", "");
} else if (streamPart.contains("channels=")) {
channels = Integer.parseInt(streamPart.replace("channels=", ""));
} else if (streamPart.contains("TAG:title=")) {
title = streamPart.replace("TAG:title=", "");
}
}
return new AudioStream(codec, absoluteIndex, relativeIndex, language, title, channels);
}
/**
* Parses a list of subtitle stream parameters to a subtitle stream object
* @param streamParts A list of parameters belonging to a subtitle stream
* @param relativeIndex The relative index of the subtitle
* @return A SubtitleStream object
* @throws NumberFormatException If codec index contains a non-numeric value
*/
private static SubtitleStream parseSubtitleStream(String[] streamParts, int relativeIndex) throws NumberFormatException {
String codecName = null;
int absoluteIndex = -1;
String language = null;
String title = "";
for (String streamPart : streamParts) {
if (streamPart.contains("codec_name=")) {
codecName = streamPart.replace("codec_name=", "");
} else if (streamPart.contains("index=")) {
absoluteIndex = Integer.parseInt(streamPart.replace("index=", ""));
} else if (streamPart.contains("TAG:language=")) {
language = streamPart.replace("TAG:language=", "");
} else if (streamPart.contains("TAG:title=")) {
title = streamPart.replace("TAG:title=", "");
}
}
return new SubtitleStream(codecName, absoluteIndex, relativeIndex, language, title);
}
static void print(String input) throws IOException {
if (!input.equals("")) {
writer.write(input);
writer.flush();
}
}
static void printl(String input) throws IOException {
if (!input.equals("")) {
writer.write(input);
}
writer.newLine();
writer.flush();
}
}

View File

@ -1,129 +0,0 @@
package ffmpegconverter.converter;
import ffmpegconverter.streams.AudioStream;
import ffmpegconverter.streams.StreamObject;
import ffmpegconverter.streams.VideoStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class VideoConverter extends Converter {
private String newExt;
private boolean debug = false;
public VideoConverter(String ffprobePath, String ffmpegPath, String newExt) {
this.ffprobePath = ffprobePath;
this.ffmpegPath = ffmpegPath;
this.newExt = newExt;
}
/**
* Reads streams from a file, and converts it to an mp4.
*
* @param folder The folder of the file to process
* @param file The file to process
* @throws IOException If the BufferedReader fails
*/
private void processFile(File folder, File file, String newExt) throws IOException {
List<StreamObject> streams = probeFile(ffprobePath, file);
if (streams.size() == 0) {
throw new IllegalArgumentException("The file has no streams");
}
String newPath = fileCollisionPrevention(folder.getAbsolutePath() + File.separator + stripExtension(file) + "." + newExt, newExt);
convertProcess(new ProcessBuilder(builderCommand(ffmpegPath, file.getName(), streams, newPath, folder)), folder);
}
/**
* Generates a command for a ProcessBuilder.
*
* @param executable The executable file for ffmpeg
* @param fileName The input file
* @param streams A list of ffprobe streams
* @param outFile The output file
* @return A list of commands
*/
private String[] builderCommand(String executable, String fileName, List<StreamObject> streams, String outFile, File folder) {
List<String> command = generalFile(executable, fileName);
if (this.debug) {
addDebug(command, 50, 120);
}
List<AudioStream> audioStreams = filterStreamsByType(streams, "audio");
List<VideoStream> videoStreams = filterStreamsByType(streams, "video");
VideoStream videoStream = null;
AudioStream audioStream = null;
if (videoStreams.size() > 0) {
videoStream = videoStreams.get(0);
}
if (audioStreams.size() > 0) {
audioStream = audioStreams.get(0);
}
String ext = hasExternalSubtitle(folder.getAbsolutePath(), fileName);
String ext2 = hasExternalImageSubtitle(folder.getAbsolutePath(), fileName);
if (!ext.equals("")) {
command.add("-vf");
command.add("subtitles=" + stripExtension(fileName) + ext);
} else if (!ext2.equals("")) {
command.add("-i");
command.add(stripExtension(fileName) + ext2);
if (this.debug) {
addDebug(command, 50, 120);
}
//TODO: Scale subtitles to video
command.add("-filter_complex");
command.add("[1:s]scale=width=1920:height=800,crop=w=1920:h=800:x=0:y=out_h[sub];[" + videoStream + ":v][sub]overlay");
command.add("-profile:v");
command.add("baseline");
}
if (ext2.equals("") || !ext.equals("")) {
if (videoStreams.size() > 0) {
command.add("-map");
command.add("0:" + videoStream);
}
if (audioStreams.size() > 0) {
command.add("-map");
command.add("0:" + audioStream);
}
}
command.add("-af");
command.add("pan=stereo|FL < 1.0*FL + 0.707*FC + 0.707*BL|FR < 1.0*FR + 0.707*FC + 0.707*BR");
command.add(outFile);
return command.toArray(new String[0]);
}
private String hasExternalImageSubtitle(String directory, String file) {
String path = stripExtension(file);
for (String s : new String[] {".idx", ".sub"}) {
if (new File(directory + File.separator + path + s).exists()) {
return s;
}
}
return "";
}
private String hasExternalSubtitle(String directory, String file) {
String path = stripExtension(file);
for (String s : new String[] {".srt", ".ass"}) {
if (new File(directory + File.separator + path + s).exists()) {
return s;
}
}
return "";
}
@Override
public String[] getValidFormats() {
return VIDEO_FORMATS;
}
@Override
public void convert(File file) throws IOException {
processFile(file.getParentFile(), file, newExt);
}
}

View File

@ -1,29 +0,0 @@
package ffmpegconverter.streams;
public class AudioStream extends StreamObject {
private String language; //The audio language
private int channels; //Whether mono, stereo, etc
private String title; //Titles exist
public AudioStream(String codec, int absoluteIndex, int relativeIndex, String language, String title, int channels) {
this.codecType = "audio";
this.codecName = codec;
this.absoluteIndex = absoluteIndex;
this.language = language;
this.title = title;
this.relativeIndex = relativeIndex;
this.channels = channels;
}
public String getLanguage() {
return this.language;
}
public int getChannels() {
return this.channels;
}
public String getTitle() {
return this.title;
}
}

View File

@ -1,43 +0,0 @@
package ffmpegconverter.streams;
/**
* An object representation of a stream in a media file
*/
public abstract class StreamObject {
int absoluteIndex;
int relativeIndex;
String codecName;
String codecType;
/**
* Gets the type of the stream codec (video/audio/subtitle)
* @return codec type
*/
public String getCodecType() {
return this.codecType;
}
/**
* Gets the name of the stream codec
* @return codec name
*/
public String getCodecName() {
return this.codecName;
}
/**
* Gets the absolute index of a stream object
* @return absolute index
*/
public int getAbsoluteIndex() {
return this.absoluteIndex;
}
/**
* Gets the relative index of a stream object (kth element of codec type)
* @return relative index
*/
public int getRelativeIndex() {
return this.relativeIndex;
}
}

View File

@ -1,65 +0,0 @@
package ffmpegconverter.streams;
/**
* An object representation of a subtitle stream in a media file
*/
public class SubtitleStream extends StreamObject {
final private String language;
final private String title; //Title shown
final private boolean isFullSubtitle; //Songs and signs will be false
final private boolean isImageSubtitle;
public SubtitleStream(String codecName, int absoluteIndex, int relativeIndex, String language, String title) {
this.codecType = "subtitle";
this.codecName = codecName;
this.absoluteIndex = absoluteIndex;
this.language = language;
this.title = title;
this.isFullSubtitle = isFullSubtitle();
this.relativeIndex = relativeIndex;
this.isImageSubtitle = isImageSubtitle();
}
/**
* Checks whether a subtitle is image based (as opposed to text based)
* @return True if the subtitle is image based
*/
private boolean isImageSubtitle() {
return codecName != null && getCodecName().equals("hdmv_pgs_subtitle");
}
/**
* Checks whether translates everything (as opposed to just songs and signs)
* @return True if the subtitles translate everything
*/
private boolean isFullSubtitle() {
if (getTitle() == null) {
return false;
}
String titleLowercase = getTitle().toLowerCase();
return !(titleLowercase.contains("songs and signs") ||
titleLowercase.contains("signs and songs") ||
titleLowercase.contains("songs & signs") ||
titleLowercase.contains("signs & songs") ||
titleLowercase.contains("signs/song") ||
titleLowercase.contains("songs/sign") ||
titleLowercase.contains("[forced]") ||
titleLowercase.contains("(forced)"));
}
public String getLanguage() {
return this.language;
}
public String getTitle() {
return this.title;
}
public boolean getIsImageSubtitle() {
return this.isImageSubtitle;
}
public boolean getIsFullSubtitle() {
return this.isFullSubtitle;
}
}

View File

@ -1,13 +0,0 @@
package ffmpegconverter.streams;
/**
* An object representation of a video stream in a media file
*/
public class VideoStream extends StreamObject {
public VideoStream(String codec, int absoluteIndex, int relativeIndex) {
this.codecType = "video";
this.codecName = codec;
this.absoluteIndex = absoluteIndex;
this.relativeIndex = relativeIndex;
}
}

View File

@ -17,7 +17,8 @@ import java.util.function.Predicate;
public class Main {
private static final String FFPROBE_PATH = "ffprobe"; //Can be just ffprobe if it's in the path
private static final String FFMPEG_PATH = "ffmpeg"; //Can be just ffmpeg if it's in the path
private static Scanner in = new Scanner(System.in, "UTF-8");
private static final Scanner READER = new Scanner(System.in, "UTF-8");
private static final BufferedWriter WRITER = new BufferedWriter(new OutputStreamWriter(System.out));
private static Converter con = null;
public static void main(String[] args) throws IOException {
@ -27,7 +28,7 @@ public class Main {
int choice = getChoice("Which converter do you want do use?\n1. Anime to web mp4\n2. Audio converter\n3. VideoStream converter", 1, 3);
System.out.println("Input for this converter:");
printl("Input for this converter:");
switch (choice) {
case 1:
animeConverter();
@ -44,10 +45,10 @@ public class Main {
int recursionSteps = 1;
System.out.println("<Folder/File> [Recursions]");
printl("<Folder/File> [Recursions]: ");
List<String> input = readInput(2);
while (input.size() == 0) {
System.out.print("File path required.");
while (input.isEmpty()) {
print("File path required.");
input = readInput(2);
}
File folder = new File(input.get(0));
@ -55,7 +56,7 @@ public class Main {
try {
recursionSteps = Integer.parseInt(input.get(1));
} catch (NumberFormatException e) {
System.out.println("Recursion steps is invalid and will be ignored.");
printl("Recursion steps is invalid and will be ignored.");
}
}
@ -66,13 +67,35 @@ public class Main {
con.convert(file);
}
} else {
System.out.println("No valid files found in folder.");
printl("No valid files found in folder.");
}
} else if (folder.exists()) {
con.convert(folder);
} else {
System.out.println("Path " + folder.getAbsolutePath() + " does not point to any file or folder.");
}
WRITER.close();
}
/**
* Prints a string
* @param input <p>The string to print.</p>
* @throws IOException <p>If the writer fails to write.</p>
*/
private static void print(String input) throws IOException {
WRITER.write(input);
WRITER.flush();
}
/**
* Prints a string and a line break
* @param input <p>The string to print.</p>
* @throws IOException <p>If the writer fails to write.</p>
*/
private static void printl(String input) throws IOException {
WRITER.write(input);
WRITER.newLine();
WRITER.flush();
}
private enum converterArgumentValueType {
@ -108,7 +131,7 @@ public class Main {
case SINGLE_VALUE:
return !value.contains(" ");
case INT:
Integer.parseInt(value);
int ignored = Integer.parseInt(value);
return true;
}
return false;
@ -142,46 +165,58 @@ public class Main {
}
}
/**
* Tokenizes a string
* @param input <p>A string.</p>
* @return <p>A list of tokens.</p>
*/
private static List<String> tokenizer(String input) {
List<String> tokens = new ArrayList<>();
boolean startedQuote = false;
StringBuilder currentToken = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == ' ') {
if (!startedQuote) {
if (!currentToken.toString().trim().equals("")) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
switch (c) {
case ' ':
if (!startedQuote) {
//If not inside "", a space marks the end of a parameter
if (!currentToken.toString().trim().equals("")) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
} else {
currentToken = new StringBuilder();
}
} else {
currentToken = new StringBuilder();
currentToken.append(c);
}
} else {
break;
case '"':
if (startedQuote) {
if (!currentToken.toString().trim().equals("")) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
}
startedQuote = false;
} else {
startedQuote = true;
currentToken = new StringBuilder();
} break;
default:
currentToken.append(c);
}
} else if (c == '"') {
if (startedQuote) {
if (!currentToken.toString().trim().equals("")) {
if (i == input.length() - 1) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
}
startedQuote = false;
} else {
startedQuote = true;
currentToken = new StringBuilder();
}
} else {
currentToken.append(c);
if (i == input.length() - 1) {
tokens.add(currentToken.toString());
}
} break;
}
}
return tokens;
}
private static void animeConverter() {
System.out.println("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: ");
/**
* Initializes the anime converter
* @throws IOException <p>If reading or writing fails.</p>
*/
private static void animeConverter() throws IOException {
printl("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: ");
List<String> input = readInput(4);
String[] audioLang = new String[]{"jpn", "*"};
String[] subtitleLang = new String[]{"eng", "*"};
@ -202,6 +237,12 @@ public class Main {
con = new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLang, subtitleLang, toStereo, preventSigns);
}
/**
* Gets a list from a comma separated string at index in list
* @param list <p>A list of tokens.</p>
* @param index <p>The index of the token containing comma separated entries.</p>
* @return <p>A string list.</p>
*/
private static String[] getList(List<String> list, int index) {
String[] result = null;
if (list.size() > index) {
@ -214,8 +255,13 @@ public class Main {
return result;
}
/**
* Reads a number of tokens from the user input
* @param max <p>The number of tokens expected.</p>
* @return <p>A list of tokens.</p>
*/
private static List<String> readInput(int max) {
List<String> tokens = tokenizer(in.nextLine());
List<String> tokens = tokenizer(READER.nextLine());
if (max < tokens.size()) {
throw new IllegalArgumentException("Input contains " + tokens.size() +
" arguments, but the input only supports " + max + " arguments.");
@ -223,27 +269,40 @@ public class Main {
return tokens;
}
private static String getChoice(String prompt) {
System.out.println(prompt);
/**
* Gets the user's choice
* @param prompt <p>The prompt shown to the user.</p>
* @return <p>The non-empty choice given by the user.</p>
* @throws IOException <p>If reading or writing fails.</p>
*/
private static String getChoice(String prompt) throws IOException {
printl(prompt);
String choice = "";
while (choice.equals("")) {
System.out.println("Your input: ");
choice = in.nextLine();
printl("Your input: ");
choice = READER.nextLine();
}
return choice;
}
private static int getChoice(String prompt, int min, int max) {
System.out.println(prompt);
/**
* Gets an integer from the user
* @param prompt The prompt to give the user
* @param min The minimum allowed value
* @param max The maximum allowed value
* @return The value given by the user
*/
private static int getChoice(String prompt, int min, int max) throws IOException {
printl(prompt);
int choice = 0;
while (choice < min || choice > max) {
System.out.println("Your input: ");
printl("Your input: ");
try {
choice = Integer.parseInt(in.next());
choice = Integer.parseInt(READER.next());
} catch (NumberFormatException e) {
System.out.println("Invalid choice. Please try again.");
printl("Invalid choice. Please try again.");
} finally {
in.nextLine();
READER.nextLine();
}
}
return choice;

View File

@ -46,11 +46,14 @@ public class AnimeConverter extends Converter {
*/
private void processFile(File folder, File file) throws IOException {
List<StreamObject> streams = probeFile(ffprobePath, file);
if (streams.size() == 0) {
if (streams.isEmpty()) {
throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and is not corrupt.");
}
String newPath = fileCollisionPrevention(folder.getAbsolutePath() + File.separator + stripExtension(file) + ".mp4", "mp4");
convertProcess(new ProcessBuilder(builderCommand(ffmpegPath, file.getName(), streams, newPath)), folder);
printl("Preparing to start process...");
String[] command = builderCommand(ffmpegPath, file.getName(), streams, newPath);
ProcessBuilder processBuilder = new ProcessBuilder(command);
convertProcess(processBuilder, folder);
}
/**

View File

@ -6,9 +6,11 @@ import ffmpegconverter.streams.SubtitleStream;
import ffmpegconverter.streams.VideoStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
@ -22,6 +24,8 @@ public abstract class Converter {
String ffprobePath;
String ffmpegPath;
private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
public abstract String[] getValidFormats();
@ -51,7 +55,8 @@ public abstract class Converter {
"stream_tags=language,title:stream=index,codec_name,codec_type,channels",
file.toString()
);
System.out.println(builderProbe.command());
print("Probe command: ");
printl(builderProbe.command().toString());
builderProbe.redirectErrorStream(true);
Process processProbe = builderProbe.start();
BufferedReader readerProbe = new BufferedReader(new InputStreamReader(processProbe.getInputStream()));
@ -59,7 +64,7 @@ public abstract class Converter {
while (processProbe.isAlive()) {
String read = read(readerProbe, PROBE_SPLIT_CHARACTER);
if (!read.equals("")) {
System.out.print(read);
print(read);
output.append(read);
}
}
@ -82,7 +87,8 @@ public abstract class Converter {
* @throws IOException If the process can't be read
*/
static void convertProcess(ProcessBuilder process, File folder) throws IOException {
System.out.println(process.command());
print("Command to be run: ");
printl(process.command().toString());
process.directory(folder);
process.redirectErrorStream(true);
Process processConvert = process.start();
@ -90,9 +96,10 @@ public abstract class Converter {
while (processConvert.isAlive()) {
String read = read(readerConvert, "\n");
if (!read.equals("")) {
System.out.println(read);
printl(read);
}
}
printl("FFMPEG is finished.");
}
/**
@ -416,4 +423,19 @@ public abstract class Converter {
}
return new SubtitleStream(codecName, absoluteIndex, relativeIndex, language, title);
}
static void print(String input) throws IOException {
if (!input.equals("")) {
writer.write(input);
writer.flush();
}
}
static void printl(String input) throws IOException {
if (!input.equals("")) {
writer.write(input);
}
writer.newLine();
writer.flush();
}
}

View File

@ -4,10 +4,10 @@ package ffmpegconverter.streams;
* An object representation of a subtitle stream in a media file
*/
public class SubtitleStream extends StreamObject {
private String language;
private String title; //Title shown
private boolean isFullSubtitle; //Songs and signs will be false
private boolean isImageSubtitle;
final private String language;
final private String title; //Title shown
final private boolean isFullSubtitle; //Songs and signs will be false
final private boolean isImageSubtitle;
public SubtitleStream(String codecName, int absoluteIndex, int relativeIndex, String language, String title) {
this.codecType = "subtitle";
@ -36,9 +36,15 @@ public class SubtitleStream extends StreamObject {
if (getTitle() == null) {
return false;
}
String title = getTitle().toLowerCase();
return !(title.contains("songs and signs") || title.contains("songs & signs") || title.contains("songs ") ||
title.contains("signs/songs") || title.contains("[forced]") || title.contains("(forced)"));
String titleLowercase = getTitle().toLowerCase();
return !(titleLowercase.contains("songs and signs") ||
titleLowercase.contains("signs and songs") ||
titleLowercase.contains("songs & signs") ||
titleLowercase.contains("signs & songs") ||
titleLowercase.contains("signs/song") ||
titleLowercase.contains("songs/sign") ||
titleLowercase.contains("[forced]") ||
titleLowercase.contains("(forced)"));
}
public String getLanguage() {