H
H
HanRus2020-10-07 14:41:27
fmpeg
HanRus, 2020-10-07 14:41:27

ffmpeg - how to cut video from the end?

Hello!
Please tell me how to cut (delete) the last 10 seconds of the video, leaving everything else.
The -ss command cuts the video first, I'm looking for the same command, but to remove it from the end.
-sseof doesn't work because it saves the video from the end and I need to delete it.

An example of a bat script to remove part of the video at the beginning.

@echo on

for %%i in (*.mp4) do (
  echo %%~pi
  ffmpeg -ss 00:00:6.57 -i "%%i" -y "out/%%~ni.mp4"
)


Please help me edit it so that it removes the last 10 seconds from the end.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
HanRus, 2020-10-09
@HanRus

Suggested solution on another resource:

ffmpeg -i %%j -itsoffset 6 -i %%j -c copy -map 0:a:0 -map 1 -shortest -f nut - | ffmpeg -y -i - -c copy -map 0 -map -0:0 -ss 6 -max_muxing_queue_size 9999 "out1/%%~ni.mp4"

A
Alexander, 2021-02-13
@AlexLev59

HanRus, thanks, it works.
There is just a small problem. Ffmpeg displays errors when trimmed. Here are the log snippets:
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Stream #1:1 -> #0:2 (copy)
Press [q] to stop, [?] for help
[nut @ 0000024076f8d0c0] Could not find codec parameters for stream 1 (Video: h264 (avc1 / 0x31637661), none, 492x360): unspecified pixel format
Consider increasing the value for the 'analyzeduration ' and 'probesize' options

...
Metadata:
creation_time : 2018-10-22T19:46:35.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 10/22/2018.
Stream #0:2(und): Audio: aac ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fltp (default)
Metadata:
creation_time : 2018-10-22T19:46: 35.000000Z
handler_name : ISO Media file produced by Google Inc. Created on: 10/22/2018.
[mp4 @ 0000024078c8c4c0] track 1: codec frame size is not set
...
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:2 -> #0:1 (copy)
[nut @000001854beac900] Multiple keyframes with same PTS2.56 bitrate= 409.5kbits/s speed= 796x
Is there any solution to fix it? I'm just starting to learn Ffmpeg, I have to try out a lot of things "at random".

S
Sergey Sokolov, 2021-02-13
@sergiks

Find the duration of the clip, subtract 10 seconds, substitute the resulting desired duration into -t ???:

ffmpeg -i SOURCE
// найти duration 

ffmpeg \
  -i SOURCE \
  -t XXX \
  -codec copy  \
  DESTINATION
In the absence of recoding, because codecs are the same, the process should be very fast.
For some formats, ffmpeg will show an approximate, not exact, duration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question