Answers.Body: <p>The basic method to join videos without re-encoding is to use the concat demuxer. This device requires that the files being joined share certain properties, like codec, framerate, video dimensions, timebase..etc</p>
  
  <p>First step is to create the blank segment, which may be used both at the head and tail.</p>
  
  <pre><code>ffmpeg -i fullvideo.mp4 -vf trim=0:3,geq=0:128:128 -af atrim=0:3,volume=0 -video_track_timescale 600 3sec.mp4
  </code></pre>
  
  <p>Have to do one bookkeeping step for the full video. If not done, the combined video will likely run at the wrong speed.</p>
  
  <pre><code>ffmpeg -i fullvideo.mp4 -c copy -video_track_timescale 600 full600.mp4
  </code></pre>
  
  <p>Next, create a text file.</p>
  
  <pre><code>file 3sec.mp4
  file full600.mp4
  file 3sec.mp4
  </code></pre>
  
  <p>Then run</p>
  
  <pre><code>ffmpeg -f concat -i list.txt -c copy merged.mp4
  </code></pre>
  
  <hr>
  
  <p>My first step assumes that the video stream has the most common pixel format <code>yuv420p</code>. Which should be fine as this is the only pixel format supported by web players and smartphone cameras, consumer camcorders..etc. If it's not, the <code>geq</code> filter may fail.</p>
  
  <p>I also assume, tacitly, that the full video does not use more reference frames than produced by preset <code>medium</code> of x264. It's a safe assumption for 95% of videos.</p>
  
  <p>Finally, I assume the full video has AAC-LC as its audio codec. Expected to be true of most phone/cam/web videos.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-21T03:20:30.683Z
Answers.Text: Where does the 600 come from? Is it possible to look that up from my current input without reencoding the entire video?
Answers.UserDisplayName: donatJ
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-21T05:17:23.383Z
Answers.Text: The 600 is the timescale used. It's the `tbn` value for the video stream. Yes, you can use the existing timescale but the other inputs have to match.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-19T02:53:21.493Z
Answers.Text: Do you know why I'm getting the error `muxing overhead: unknown` at the last step?
Answers.UserDisplayName: crxyz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-19T05:13:08.083Z
Answers.LastActivityDate: 2017-02-19T05:13:08.083Z
Answers.UserDisplayName: Gyan
Body: <p>Let's say I have a video, which can have any dimensions or codec (e.g. mp4), and I want to add 3 seconds of black frames to its head. </p>
  
  <p>I have seen other variants to this question which pertain to adding a single frame, and also answers which specify the width and height of the video. However the video can be of any width and height and I don't want to change those values. Just add the black. In a separate command, I'd also like to add the seconds of black to the tail.</p>
  
  <p>There should be no audio in the black section - the black should just be concatenated to the front and end. Also, I'd like to avoid re-encoding the video if possible, and copy the result to a new file.</p>
  
  <p>Any help would be appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-18T12:30:04.323Z
Comments.Text: Is audio present? And do you want to skip re-encoding the main video?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-18T12:49:28.193Z
Comments.Text: @Mulvya thanks for your input. I've updated my question.
Comments.UserDisplayName: Matt C
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-18T14:56:03.490Z
Comments.Text: @MattC  You can delete the above comment now. This will need multiple commands, unless you re-encode. Is that ok?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-18T15:03:24.843Z
Comments.Text: @Mulvya yes multiple commands is good. Thanks again.
Comments.UserDisplayName: Matt C
Tags: <ffmpeg>
Title: ffmpeg: add 3 seconds of black to video head and tail
UserDisplayName: batmannutjob
ThreadText: # ffmpeg: add 3 seconds of black to video head and tail
  
  (Asked by: username_0 on 2017-02-18)
  
  Let's say I have a video, which can have any dimensions or codec (e.g. mp4), and I want to add 3 seconds of black frames to its head.
  
  I have seen other variants to this question which pertain to adding a single frame, and also answers which specify the width and height of the video. However the video can be of any width and height and I don't want to change those values. Just add the black. In a separate command, I'd also like to add the seconds of black to the tail.
  
  There should be no audio in the black section - the black should just be concatenated to the front and end. Also, I'd like to avoid re-encoding the video if possible, and copy the result to a new file.
  
  Any help would be appreciated.
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: Is audio present? And do you want to skip re-encoding the main video?  
  > **username_2**: @Mulvya thanks for your input. I've updated my question.  
  > **username_1**: @username_2  You can delete the above comment now. This will need multiple commands, unless you re-encode. Is that ok?  
  > **username_2**: @Mulvya yes multiple commands is good. Thanks again.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-19. Score: 16
  
  The basic method to join videos without re-encoding is to use the concat demuxer. This device requires that the files being joined share certain properties, like codec, framerate, video dimensions, timebase..etc
  
  First step is to create the blank segment, which may be used both at the head and tail.
  
  ```
  ffmpeg -i fullvideo.mp4 -vf trim=0:3,geq=0:128:128 -af atrim=0:3,volume=0 -video_track_timescale 600 3sec.mp4
  
  ```
  
  Have to do one bookkeeping step for the full video. If not done, the combined video will likely run at the wrong speed.
  
  ```
  ffmpeg -i fullvideo.mp4 -c copy -video_track_timescale 600 full600.mp4
  
  ```
  
  Next, create a text file.
  
  ```
  file 3sec.mp4
  file full600.mp4
  file 3sec.mp4
  
  ```
  
  Then run
  
  ```
  ffmpeg -f concat -i list.txt -c copy merged.mp4
  
  ```
  
  ---
  
  My first step assumes that the video stream has the most common pixel format `yuv420p`. Which should be fine as this is the only pixel format supported by web players and smartphone cameras, consumer camcorders..etc. If it's not, the `geq` filter may fail.
  
  I also assume, tacitly, that the full video does not use more reference frames than produced by preset `medium` of x264. It's a safe assumption for 95% of videos.
  
  Finally, I assume the full video has AAC-LC as its audio codec. Expected to be true of most phone/cam/web videos.
  
  > **Comments:**
  > **username_3**: Where does the 600 come from? Is it possible to look that up from my current input without reencoding the entire video?  
  > **username_1**: The 600 is the timescale used. It's the `tbn` value for the video stream. Yes, you can use the existing timescale but the other inputs have to match.  
  > **username_4**: Do you know why I'm getting the error `muxing overhead: unknown` at the last step?  
  
  ---
  
  