Answers.Body: <p>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 <code>copy</code> mode, ffmpeg has to include all frames before and after the trimmed segment which are needed to decode the segment correctly.</p>
  
  <p>So, you have two options, use copy mode but set a switch which will allow all players to correctly play these files</p>
  
  <pre><code>ffmpeg -ss %2 -t %3 -i %1 -vcodec copy -acodec copy -avoid_negative_ts make_zero %~n1_cut%~x1
  </code></pre>
  
  <p>(this will likely result in output that starts before your cutpoint)</p>
  
  <p>or re-encode the streams</p>
  
  <pre><code>ffmpeg -ss %2 -t %3 -i %1 %~n1_cut%~x1
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-05T06:48:38.043Z
Answers.Text: 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.
Answers.UserDisplayName: totymedli
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T13:34:50.600Z
Answers.Text: @Gyan What does `%` do? I tried searching https://ffmpeg.org/ffmpeg.html but I can't find the usage.
Answers.UserDisplayName: Shayan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T13:36:56.590Z
Answers.Text: 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.
Answers.UserDisplayName: Shayan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-08T02:27:34.520Z
Answers.Text: So, no way to use `-codec copy` but not blank video at start of trimmed video? If I have to, I will, but the trimmed video loses quality. The first option starts before cutpoint and that includes copyright music which I want to cut out.
Answers.UserDisplayName: Sun
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-30T19:16:04.070Z
Answers.LastActivityDate: 2016-04-30T19:16:04.070Z
Answers.UserDisplayName: Gyan
Answers.Body: <p><a href="https://github.com/mifi/lossless-cut/pull/13" rel="nofollow noreferrer">https://github.com/mifi/lossless-cut/pull/13</a></p>
  <p>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?)</p>
  <p>If I change the order to -ss ... -i ... -t ..., then the resulting cut videos play properly.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-08T13:32:19.737Z
Answers.Text: I tried `-ss` before `-i` but it didn't work on my mp4 file.
Answers.UserDisplayName: Shayan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-04T23:11:02.943Z
Answers.Text: Worked for me, thanks. Merely changed the order of parameters. ffmpeg version 3.2.12-1~deb9u1
Answers.UserDisplayName: shukshin.ivan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-05T01:03:54.583Z
Answers.Text: Actually, this just moves the blank duration to the end of the video
Answers.UserDisplayName: Honghao Z
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-13T01:26:57.787Z
Answers.Text: Changing parameter order worked well for me.
Answers.UserDisplayName: Screenack
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-29T02:10:57.790Z
Answers.Text: It works only partially plus it produces much larger chunks. I thinks is really depending on the codec used. I have a thermal camera footage (5min, 27MB) that I want to split into 30 chunks. With the **i-ss-t** order I get 30 pieces I get 15MB with most chunks smaller than 600KB but most containing black frames for several seconds (each chunk is 10sec long). With the **ss-i-t** order I get almost 10MB per chunk with still some seconds of black footage for the first file.
Answers.UserDisplayName: rbaleksandar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-11T23:47:15.490Z
Answers.Text: The changing of the order of input file and `-ss` command worked for me! Very strange!!!
Answers.UserDisplayName: halloleo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-16T09:52:33.300Z
Answers.Text: this is really weird.. changing the order worked for me. But the file size sky rocketed by a few xx.
Answers.UserDisplayName: Code Cooker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-07T11:04:37.997Z
Answers.LastActivityDate: 2023-04-13T17:57:59.793Z
Answers.LastEditDate: 2023-04-13T17:57:59.793Z
Answers.UserDisplayName: Gerard Wensink
Body: <p>i'm using this command to cut a segment from a video from command line</p>
  
  <pre><code>ffmpeg -i %1 -vcodec copy -acodec copy -ss %2 -t %3 %~n1_cut%~x1
  </code></pre>
  
  <p>and i call it like</p>
  
  <pre><code>cut.bat video.mp4 001:23:45:678 10
  </code></pre>
  
  <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-06T23:38:43.107Z
Comments.Text: %~n1_cut%~x1 what does this part of the command mean?
Comments.UserDisplayName: ScipioAfricanus
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-30T12:39:54.230Z
Comments.Text: @ScipioAfricanus `%~n1` expands %1 to a file Name, or if only a path is present (with no trailing backslash) - the last folder in that path and `%~x1` expands %1 to a file eXtension only - .txt source:https://superuser.com/questions/224416/what-do-df0-and-df1-mean-in-a-batch-file
Comments.UserDisplayName: Shayan
Tags: <ffmpeg>
Title: cutting with ffmpeg results in few seconds of black screen, how do i fix this?
UserDisplayName: some guy
ThreadText: # cutting with ffmpeg results in few seconds of black screen, how do i fix this?
  
  (Asked by: username_0 on 2016-04-30)
  
  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?
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: %~n1_cut%~x1 what does this part of the command mean?  
  > **username_2**: @username_1 `%~n1` expands %1 to a file Name, or if only a path is present (with no trailing backslash) - the last folder in that path and `%~x1` expands %1 to a file eXtension only - .txt source:https://superuser.com/questions/224416/what-do-df0-and-df1-mean-in-a-batch-file  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2016-04-30. Score: 16
  
  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
  
  ```
  
  > **Comments:**
  > **username_4**: 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.  
  > **username_2**: @username_3 What does `%` do? I tried searching https://ffmpeg.org/ffmpeg.html but I can't find the usage.  
  > **username_2**: 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.  
  > **username_5**: So, no way to use `-codec copy` but not blank video at start of trimmed video? If I have to, I will, but the trimmed video loses quality. The first option starts before cutpoint and that includes copyright music which I want to cut out.  
  
  ---
  
  ### Answer by username_6 on 2019-01-07. Score: 12
  
  <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.
  
  > **Comments:**
  > **username_2**: I tried `-ss` before `-i` but it didn't work on my mp4 file.  
  > **username_7**: Worked for me, thanks. Merely changed the order of parameters. ffmpeg version 3.2.12-1~deb9u1  
  > **username_8**: Actually, this just moves the blank duration to the end of the video  
  > **username_9**: Changing parameter order worked well for me.  
  > **username_10**: It works only partially plus it produces much larger chunks. I thinks is really depending on the codec used. I have a thermal camera footage (5min, 27MB) that I want to split into 30 chunks. With the **i-ss-t** order I get 30 pieces I get 15MB with most chunks smaller than 600KB but most containing black frames for several seconds (each chunk is 10sec long). With the **ss-i-t** order I get almost 10MB per chunk with still username_0 seconds of black footage for the first file.  
  > **username_11**: The changing of the order of input file and `-ss` command worked for me! Very strange!!!  
  > **username_12**: this is really weird.. changing the order worked for me. But the file size sky rocketed by a few xx.  
  
  ---
  
  