8

i'm using this command to cut a segment from a video from command line

ffmpeg -i %1 -vcodec copy -acodec copy -ss %2 -t %3 %~n1_cut%~x1

and i call it like

cut.bat video.mp4 001:23:45:678 10

and as expected i get a video_cut.mp4 with 10 seconds of the original video, problem is that few seconds of the resulting file is black screen with audio, why does this happen and how do i fix it?

  • %~n1_cut%~x1 what does this part of the command mean? – ScipioAfricanus Aug 6 at 23:38
8

Most videos use codecs which perform temporal compression, so a specified cutpoint may rely on frames before (and after) that cutpoint to be correctly decoded. So, when you use ffmpeg to trim videos and use copy mode, ffmpeg has to include all frames before and after the trimmed segment which are needed to decode the segment correctly.

So, you have two options, use copy mode but set a switch which will allow all players to correctly play these files

ffmpeg -ss %2 -t %3 -i %1 -vcodec copy -acodec copy -avoid_negative_ts make_zero %~n1_cut%~x1

(this will likely result in output that starts before your cutpoint)

or re-encode the streams

ffmpeg -ss %2 -t %3 -i %1 %~n1_cut%~x1
  • Although re-encoding is slower, it will produce better results, because with the other solution the video might be longer then what was specified in the -t option. – totymedli Jul 5 '18 at 6:48
  • @Gyan What does % do? I tried searching ffmpeg.org/ffmpeg.html but I can't find the usage. – Shayan May 8 at 13:34
  • As your answer suggested I used both -ss and -t before -i and it worked, before, I only put -ss before -i and -t was after it so it didn't work. – Shayan May 8 at 13:36
0

https://github.com/mifi/lossless-cut/pull/13

When I run ffmpeg with the arguments in this order -i ... -ss ... -t ..., it produces a video file that has no video for a few initial seconds. (as far as I can understand this is because it doesn't seek to a keyframe?)

If I change the order to -ss ... -i ... -t ..., then the resulting cut videos play properly.

My ffmpeg -version

  • I tried -ss before -i but it didn't work on my mp4 file. – Shayan May 8 at 13:32
  • Worked for me, thanks. Merely changed the order of parameters. ffmpeg version 3.2.12-1~deb9u1 – shukshin.ivan Aug 4 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.