Last active
March 4, 2018 17:17
-
-
Save MrSimbax/68712fd63fe85e7842e55edfed66f3dc to your computer and use it in GitHub Desktop.
This script uses ffmpeg to cut a video without losing much quality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
REM This script uses ffmpeg to cut a video without losing much quality | |
SETLOCAL ENABLEEXTENSIONS EnableDelayedExpansion | |
SET me=%~n0 | |
REM Check if necessary parameters were passed | |
SET params=true | |
IF "%~1" EQU "" SET params=false | |
IF "%~2" EQU "" SET params=false | |
IF "%~3" EQU "" SET params=false | |
IF "%params%" EQU "false" ( | |
ECHO Usage: %me% INPUT BEGIN END [OUTPUT=Dropbox] | |
EXIT /B 0 | |
) | |
REM Get parameters | |
SET input=%~1 | |
SET begin=%~2 | |
SET end=%~3 | |
SET output=%~4 | |
REM Set output to Dropbox if not given | |
SET filename=%~nx1 | |
IF "%output%" EQU "" ( | |
REM Get timestamp | |
FOR /F %%a IN ('WMIC OS GET LocalDateTime ^| FIND "."') DO SET timestamp_raw=%%a | |
SET timestamp=!timestamp_raw:~0,4!-!timestamp_raw:~4,2!-!timestamp_raw:~6,2!_!timestamp_raw:~8,2!-!timestamp_raw:~10,2!-!timestamp_raw:~12,2! | |
SET output=%UserProfile%\Dropbox\Public\Videos\!timestamp!_%filename% | |
) | |
REM Create output directory if it doesn't exist | |
FOR %%f IN ("%output%") DO SET output_dir=%%~dpf | |
IF NOT EXIST "%output_dir%" MKDIR "%output_dir%" | |
REM Replace backslashes with slashes (ffmpeg requires that even on Windows) | |
SET input="%input:\=/%" | |
SET output="%output:\=/%" | |
REM Finally, cut the video | |
ffmpeg -hide_banner -ss %begin% -i %input% -codec copy -copyts -to %end% -avoid_negative_ts make_zero %output% | |
REM It would be cool if share link to Dropbox was automatically copied, but it's not that easy | |
REM (Lack of "share" command in Dropbox CLI + authentication required) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment