Jump to content

Cutting to video length


arrbee99

Recommended Posts

Try this,  I missed something

@echo off

:: Set file specification
set FileSpec="m:\Films\*.mkv"

:: Set location of MediaInfo CLI executable (directory where mediainfo.exe CLI version is located)
set MICLI="C:\bin\mediainfo"

SETLOCAL
SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION
if not exist "%MICLI:"=%\mediainfo.exe" goto :PNF
if not exist "%FileSpec:"=%" goto :FNF

FOR /F "delims=" %%m in ('dir /a-s /b /s "%FileSpec:"=%"') do ( 
  "%MICLI%\mediainfo" --Inform="Video;%%Duration/String3%%" "%%m" > %TEMP%\Duration.tmp
  call :runff "%%m"
  echo ====================================================
)
goto :cleanup
:runff
  set /p Duration= < %TEMP%\Duration.tmp
  echo ffmpeg -y -hide_banner -v info -i %1 -to %Duration% -map 0:a? -map 0:s? -map 0:v -c copy "%~dpn1_length.mkv"
goto :eof

:cleanup
  if exist %TEMP%\Duration.tmp DEL %TEMP%\Duration.tmp
  Pause
  exit /b
:FNF
  echo file not found %FileSpec%
  pause
  exit /b
:PNF
  echo mediainfo.exe not found in directory %MICLI%
  pause 

 

Link to comment
Share on other sites

arrbee99

looks promising (displays this) -

ffmpeg -y -hide_banner -v info -i "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E01 Pilot.mkv" -to 00:44:38.676 -map 0:a? -map 0:s? -map 0:v -c copy "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E01 Pilot_length.mkv"
====================================================
ffmpeg -y -hide_banner -v info -i "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E02 'Ohana (Family).mkv" -to 00:42:33.551 -map 0:a? -map 0:s? -map 0:v -c copy "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E02 'Ohana (Family)_length.mkv"
====================================================
ffmpeg -y -hide_banner -v info -i "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E03  Malama Ka Aina (Respect the Land).mkv" -to 00:40:58.456 -map 0:a? -map 0:s? -map 0:v -c copy "Y:\Ripping\Post Handbrake\Hawaii Five-0 Season 1\Hawaii Five-0 Season 1 Disc 1\S01E03  Malama Ka Aina (Respect the Land)_length.mkv"
====================================================
Press any key to continue . . .

then it exits.

Is this as desired ?

Edited by arrbee99
Link to comment
Share on other sites

Yes, you are now up to step 6:

if the time(s) indicated after the -to are correct remove the “echo” before “ffmpeg...”

then run it again.

Link to comment
Share on other sites

arrbee99

That seems to work rather excellently, thank you.

One thing (so far...) it does just copy the video, audio and subtitles (everything) to the new file ?

Link to comment
Share on other sites

The -map parameters control what gets copied your settings will only copy the main stream Video/Audio/Subtitles.

If you want everything then simply remove the "-map 0:a? -map 0:s? -map 0:v" from the ffmpeg line.   

Link to comment
Share on other sites

arrbee99

Seems a bit the other way round to me, for instance for the first episode with 4 audio tracks and leaving the map bits in, the output had 4 audio tracks, but remove the map bit and it only had one track.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...