How to trim last N seconds from TS video

Is there a way to trim the last N seconds from a video? The format in this case is "MPEG-TS".

With FFMPEG, I know that there is an option for the start time and duration, but none of them are used in this use case. A video can be of any possible length, so the duration cannot be fixed.

In addition, the solution must be run on the Windows command line and can be automated.

+1
ffmpeg video mpeg2-ts
Dec 10 '13 at 18:20
source share
1 answer

The desired functionality can be achieved using the following steps:

  • Use ffmpeg to determine the length of the video. Use for example. cmd script:

    set input=video.ts ffmpeg -i "%input%" 2> output.tmp rem search " Duration: HH:MM:SS.mm, start: NNNN.NNNN, bitrate: xxxx kb/s" for /F "tokens=1,2,3,4,5,6 delims=:., " %%i in (output.tmp) do ( if "%%i"=="Duration" call :calcLength %%j %%k %%l %%m ) goto :EOF :calcLength set /A s=%3 set /A s=s+%2*60 set /A s=s+%1*60*60 set /A VIDEO_LENGTH_S = s set /A VIDEO_LENGTH_MS = s*1000 + %4 echo Video duration %1:%2:%3.%4 = %VIDEO_LENGTH_MS%ms = %VIDEO_LENGTH_S%s 
  • Calculate start and end points for clip operation

     rem ** 2:00 for the start, 4:00 from the end set /A starttime = 120 set /A stoptime = VIDEO_LENGTH_S - 4*60 set /A duration = stoptime - starttime 
  • Pin the video. As a bonus, convert the TS file to a more optimal format, for example, H.264

     set output=video.mp4 vlc -vvv --start-time %starttime% --stop-time %stoptime% "%input%" --sout=#transcode{vcodec=h264,vb=1200,acodec=mp3, ab=128}:standard{access=file,dst=%output%} vlc://quit rem ** Handbrake has much better quality ** handbrakeCLI -i %input% -o %output% -e x264 -B 128 -q 25 --start-at duration:%starttime% --stop-at duration:%duration% 
+1
Dec 12 '13 at 18:54
source share
β€” -



All Articles