Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- REM FF Command Line Editor 1.1
- REM Open a command prompt to run ffmpeg/ffplay/ffprobe
- REM Copyright (C) 2020 Chaddo
- TITLE FF Command Line Editor
- cls
- setlocal enabledelayedexpansion
- REM user input to get video file
- ECHO.
- ECHO Type in video file location
- set /p video=""
- REM === start the processing ====
- REM les use ffprobe to get video length
- for /F "delims=" %%I in ('bin\ffprobe -v error -show_entries format^=duration -of default^=noprint_wrappers^=1:nokey^=1 "%video%" 2^>^&1') do SET "vid=%%I"
- REM lets strip anything that has a decimal
- FOR %%i IN ("%vid%") DO (
- set /A duration=%%~ni
- GOTO check_duration
- )
- :check_duration
- IF %duration% lss 32 (
- ECHO.
- echo Video duration is: %duration%s
- echo.
- GOTO less_than_30
- ) ELSE (
- ECHO.
- echo Video duration is: %duration%s
- echo.
- GOTO greater_than_30
- )
- :less_than_30
- echo Segments must be between 4 and 10 seconds
- ECHO How many seconds per segment do you want to cut up this video?
- set /p segment_cut_time=""
- SET /A segment_cut_time=%segment_cut_time%
- IF %segment_cut_time% lss 4 (
- echo you have to select a number between 4 and 10
- ECHO.
- Goto :less_than_30
- ) ELSE (
- IF %segment_cut_time% gtr 10 (
- echo you have to select a number between 4 and 10
- ECHO.
- Goto :less_than_30
- ) ELSE (
- Goto :cut_times
- )
- )
- :greater_than_30
- ECHO How many seconds per segment do you want to cut up this video?
- set /p segment_cut_time=""
- SET /A segment_cut_time=%segment_cut_time%
- GOTO cut_times
- :cut_times
- ECHO.
- ECHO Video will be cut into %segment_cut_time% second segments
- REM ===== need to set this frames per second====
- SET /A fps=30
- REM ====== Video Fade ===========
- SET /A segment_fade_duration=1
- SET /A segment_time=%segment_cut_time%+%segment_fade_duration%
- SET /A segment_fade_In=0
- SET /A segment_fade_out=%segment_cut_time%
- REM will start overall timer
- set start=%time%
- REM ==== Editing starts here ============
- echo.
- echo We will start by cutting the video into %segment_cut_time% second segments
- REM == FFMpeg ==>
- bin\ffmpeg -hide_banner -loglevel 0 -i "%video%" -c copy -map 0 -f segment -segment_time %segment_time% -reset_timestamps 1 -segment_format_options movflags=+faststart out%%03d.mp4
- echo.
- echo Cutting the video has finished...
- :: ================== cut the the fade in - segement one =========
- echo.
- echo Lets cut the the first 2 seconds off each segment to create the fade in
- :: lets cut the 1st 2 seconds to create the fade in
- for %%a in (out*.mp4) DO bin\ffmpeg -hide_banner -loglevel 0 -t 2 -i "%%a" -c copy a_%%~na.mp4
- echo.
- echo Now lets create the fade in for those segments
- :: now lets add the fade in for audio and video
- for %%a in (a_out*.mp4) DO bin\ffmpeg -hide_banner -loglevel 0 -i "%%a" -vf "fade=t=in:st=0:d=1" -af "afade=t=in:st=0:d=1" -async 1 b_%%~na.mp4
- :: creates b_a_out
- :: delete the pre fades
- del a_out*.mp4
- :: ================== Create the fade out - segement one =========
- echo.
- echo Now lets create 2 seconds off each end of the file
- :: middle section
- for %%a in (out*.mp4) DO bin\ffmpeg -hide_banner -loglevel 0 -ss 2 -i "%%a" -ss 4 -i "%%a" -c copy -map 1:0 -map 0 -shortest -f nut - | bin\ffmpeg -hide_banner -loglevel 0 -f nut -i - -map 0 -map -0:0 -c copy 2b_%%~na.mp4
- :: creates 2b_out
- :: ================== Create the main content bewtween fades =========
- echo.
- echo OK, now lets cut the the last 2 seconds off the end of each segment to create the fade out
- :: lets cut the last 2 seconds to create the fade out
- for %%a in (out*.mp4) DO bin\ffmpeg -hide_banner -loglevel 0 -sseof -2 -i "%%a" -c copy c_%%~na.mp4
- echo.
- echo Now lets create the fade out for those segments
- :: now lets add the fade in for audio and video
- for %%a in (c_out*.mp4) DO bin\ffmpeg -hide_banner -loglevel 0 -i "%%a" -vf "fade=t=out:st=1:d=1" -af "afade=t=out:st=1:d=1" -async 1 2b_%%~na.mp4
- :: creates 2b_c_out
- :: delete the pre fades
- del c_out*.mp4
- :: ================== Combine all the segments =========
- :: create text file with fade ins =====
- for %%c in (b_a_out*mp4) do (
- echo %%c >> list.tmp
- )
- >fade_in.tmp (
- for /F "delims=;" %%F in (list.tmp) do (
- for %%F in (^"%%F^") do (
- for /f "tokens=2-5 delims=:., " %%a in (
- 'bin\ffmpeg -i "%%F" 2^>^&1 ^| find "Duration:"'
- ) do (
- set /a full=%%a * 60 * 60 + %%b * 60 + %%c
- )
- echo %%~nxF^|!full!
- )
- )
- )
- del list.tmp
- :: ===== create text file with fade ins =====
- for %%c in (2b_out*mp4) do (
- echo %%c >> list.tmp
- )
- >middle.tmp (
- for /F "delims=;" %%F in (list.tmp) do (
- for %%F in (^"%%F^") do (
- for /f "tokens=2-5 delims=:., " %%a in (
- 'bin\ffmpeg -i "%%F" 2^>^&1 ^| find "Duration:"'
- ) do (
- set /a full=%%a * 60 * 60 + %%b * 60 + %%c
- )
- echo %%~nxF^|!full!
- )
- )
- )
- del list.tmp
- >fades.tmp (
- 3< middle.tmp (for /F "delims=" %%a in (fade_in.tmp) do (
- set /P line2=<&3
- echo %%a^|!line2!
- ))
- )
- del middle.tmp
- del fade_in.tmp
- ::create text file with fade outs
- for %%c in (2b_c_out*mp4) do (
- echo %%c >> list.tmp
- )
- >fade_out.tmp (
- for /F "delims=;" %%F in (list.tmp) do (
- for %%F in (^"%%F^") do (
- for /f "tokens=2-5 delims=:., " %%a in (
- 'bin\ffmpeg -i "%%F" 2^>^&1 ^| find "Duration:"'
- ) do (
- set /a full=%%a * 60 * 60 + %%b * 60 + %%c
- )
- echo %%~nxF^|!full!
- )
- )
- )
- del list.tmp
- :: combine the segments and fade in tmp files
- >concat.tmp (
- 3< fade_out.tmp (for /F "delims=" %%a in (fades.tmp) do (
- set /P line2=<&3
- echo %%a^|!line2!
- ))
- )
- :: ===== read the fades file to make main content splits =====
- for /f "tokens=1-6 delims=|" %%a in (concat.tmp) do (
- IF %%d lss 2 (
- bin\ffmpeg -hide_banner -loglevel 0 -i %%e -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1_%%~na.ts
- bin\ffmpeg -hide_banner -loglevel 0 -i intermediate1_%%~na.ts -c copy -bsf:a aac_adtstoasc mid_2_q%%~na.mp4
- ) ELSE (
- bin\ffmpeg -hide_banner -loglevel 0 -i %%a -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1_%%~na.ts
- bin\ffmpeg -hide_banner -loglevel 0 -i %%c -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2_%%~na.ts
- bin\ffmpeg -hide_banner -loglevel 0 -i %%e -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate3_%%~na.ts
- bin\ffmpeg -hide_banner -loglevel 0 -i "concat:intermediate1_%%~na.ts|intermediate2_%%~na.ts|intermediate3_%%~na.ts" -c copy -bsf:a aac_adtstoasc mid_2_q%%~na.mp4
- )
- )
- ::Rename the files
- for /F "eol=| delims=" %%I in ('dir /A-D /B mid_2_qb_a_*mp4') do (
- for /F "eol=| tokens=2 delims=t " %%J in ("%%~nI") do ren "%%I" "final_%%J%%~xI"
- )
- :: clean up all the temp files
- del b_a_out*.mp4
- del 2b_out*.mp4
- del 2b_c_out*.mp4
- del concat.tmp
- del fades.tmp
- del fade_out.tmp
- del *.ts
- del out*.mp4
- REM == FFMpeg ==>
- for %%c in (final_*.mp4) do (
- echo file %%c >> list.txt
- )
- bin\ffmpeg -hide_banner -loglevel 0 -f concat -safe 0 -i list.txt -c copy combined.mp4
- REM ======== End the ffmpeg timer ===============
- :ffmpeg_finished
- set end=%time%
- set options="tokens=1-4 delims=:.,"
- for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
- for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
- set /a hours=%end_h%-%start_h%
- set /a mins=%end_m%-%start_m%
- set /a secs=%end_s%-%start_s%
- set /a ms=%end_ms%-%start_ms%
- if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
- if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
- if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
- if %hours% lss 0 set /a hours = 24%hours%
- if 1%ms% lss 100 set ms=0%ms%
- :: Mission accomplished
- set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
- ECHO.
- ECHO The whole editing process took :
- ECHO %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
- ECHO.
- ECHO Now lets Preview it...
- bin\ffplay -autoexit -hide_banner -loglevel 0 -i "combined.mp4" -x 640 -y 480
- del list.txt
- :delete_preview
- ECHO.
- SET choice=
- ECHO Do you want to delete the combined video you just previewed before exiting?
- SET /p choice=PLEASE NOTE: This can't be redone [Y/N]:
- IF NOT '%choice%'=='' SET choice=%choice:~0,1%
- IF '%choice%'=='Y' GOTO do_delete_preview
- IF '%choice%'=='y' GOTO do_delete_preview
- IF '%choice%'=='N' GOTO change_vid_name
- IF '%choice%'=='n' GOTO change_vid_name
- IF '%choice%'=='' GOTO delete_preview_must_make_choice
- ECHO "%choice%" is not valid
- :delete_preview_must_make_choice
- ECHO.
- ECHO You have to type Y or N to delete the video segments or not
- GOTO delete_preview
- ECHO.
- GOTO delete_preview
- :do_preview_segments
- REM delete the preview we made
- if NOT EXIST list.txt goto :out
- del list.txt
- :do_delete_preview
- if NOT EXIST combined*.mp4 GOTO :change_vid_name
- del combined*.mp4 GOTO :delete_segments
- :change_vid_name
- ECHO.
- ECHO The current name of the video you previwed is : combined.mp4
- SET choice=
- ECHO Do you want to change the name from 'combined.mp4' before exiting?
- SET /p choice=PLEASE NOTE: This can't be redone [Y/N]:
- IF NOT '%choice%'=='' SET choice=%choice:~0,1%
- IF '%choice%'=='Y' GOTO do_change
- IF '%choice%'=='y' GOTO do_change
- IF '%choice%'=='N' GOTO delete_segments
- IF '%choice%'=='n' GOTO delete_segments
- IF '%choice%'=='' GOTO change_must_make_choice
- ECHO "%choice%" is not valid
- :change_must_make_choice
- ECHO.
- ECHO You have to type Y or N to change the name of the video or not
- GOTO change_vid_name
- ECHO.
- GOTO change_vid_name
- REM user input to get video file
- :do_change
- ECHO.
- ECHO Please type in new video name only, do not add extension.
- set /p new_name=""
- bin\ffmpeg -hide_banner -loglevel 0 -i "combined.mp4" -c copy "%new_name%".mp4
- del "combined.mp4"
- :delete_segments
- ECHO.
- SET choice=
- ECHO Do you want to delete segments in the preview video before exiting?
- SET /p choice=PLEASE NOTE: This can't be redone [Y/N]:
- IF NOT '%choice%'=='' SET choice=%choice:~0,1%
- IF '%choice%'=='Y' GOTO do_delete_segments
- IF '%choice%'=='y' GOTO do_delete_segments
- IF '%choice%'=='N' GOTO no
- IF '%choice%'=='n' GOTO no
- IF '%choice%'=='' GOTO delete_segments_must_make_choice
- ECHO "%choice%" is not valid
- :delete_segments_must_make_choice
- ECHO.
- ECHO You have to type Y or N to delete the video segments or not
- GOTO delete_segments
- ECHO.
- GOTO delete_segments
- :do_delete_segments
- REM delete the last of the segments we made
- if NOT EXIST list.txt goto :out
- del list.txt
- :out
- if NOT EXIST final_*.mp4 goto :cleanedup
- del final_*.mp4
- echo.
- echo cleaning up is now complete...
- :no
- echo.
- echo Good bye now go and enjoy your edited video!!!
- pause
- EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement