Answers.Body: <p>Use the <a href="https://ffmpeg.org/ffmpeg-filters.html#concat" rel="nofollow noreferrer">concat</a> filter:</p>
  
  <pre><code>ffmpeg -y -i a.mp4 -ss 2 -t 22 -i x.wma -ss 00:01:22 -t 19 -i y.mp3 -ss 29 -t 124 -i z.mp3 -filter_complex "[1:a][2:a][3:a]concat=n=3:v=0:a=1[a]" -map 0:v -map "[a]" -shortest output.mp4
  </code></pre>
  
  <p>Alternatively, instead of <code>-ss</code>/<code>-t</code> you can use the atrim and asetpts filters.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-19T08:52:29.637Z
Answers.Text: Is this a command for the first method? It doesn't seem to use b.mkv at all. But I think i get what you were trying to explain. Thank you Ilogan!
Answers.UserDisplayName: helming
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-21T22:43:45.483Z
Answers.Text: @helming `b.mkv` was not used because the sum of the audio durations was shorter than the duration of `a.mp4`.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-06T18:40:38.367Z
Answers.Text: @llogan, Any chance you have a look at https://video.stackexchange.com/questions/35053?
Answers.UserDisplayName: Royi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-13T21:25:15.940Z
Answers.LastActivityDate: 2020-01-13T21:25:15.940Z
Answers.UserDisplayName: llogan
Body: <p>I started to learn FFmpeg syntax a couple of days ago.<br>
  I'm trying to read the official docs, it's not easy.</p>
  
  <p>So I want to build up a video files which consists of different videos, and audios.
  Let's say I have files below.</p>
  
  <p>Video files:</p>
  
  <ul>
  <li><p><code>a.mp4</code></p></li>
  <li><p><code>b.mkv</code></p></li>
  </ul>
  
  <p>Audio files:</p>
  
  <ul>
  <li><p><code>x.wma</code></p></li>
  <li><p><code>y.mp3</code></p></li>
  <li><p><code>z.mp3</code></p></li>
  </ul>
  
  <p>I'd like to use specific parts of audio files.<br>
  Let's say, </p>
  
  <ul>
  <li>2s ~ 24 sec from <code>x.wma</code></li>
  <li>1m 22s ~ 1m 41s from <code>y.mp3</code></li>
  <li>29s ~ 2m 33s from <code>z.mp3</code></li>
  </ul>
  
  <p>Concatenate the selected audio streams into an audio stream.</p>
  
  <p>I'll take the video stream of 2m ~ 2m 32s from <code>a.mp4</code>.</p>
  
  <p>Then video stream is a lot shorter than audio.<br>
  (I don't know how much exactly, hopefully FFmpeg can do that for me)</p>
  
  <p>Can FFmpeg do any of the below?</p>
  
  <ol>
  <li>Take the video streams from <code>b.mkv</code> and concatenate it with the video streams from a.mp4, so that resulted video stream is as long as the audio. After that mux the audio and video.</li>
  <li><p>Change the duration of the video stream from <code>a.mp4</code> so that duration of the video and audio are equal.(by changing playback speed of video stream) then mux the audio and video.</p></li>
  <li><p>Just insert an image file after video streams ends while audio is being played.</p></li>
  </ol>
  
  <p>P.S.: I tried to express things clearly, but I'm not so good at English. If there is anything you can't understand clearly, please tell me.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-09T20:07:51.907Z
Comments.Text: "Can FFmpeg do any of the below?" Yes. Which method do you prefer? I will give an example for one.
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-10T04:50:24.300Z
Comments.Text: so, FFmpeg can do all of them? Wow that's great! I prefer first method.
Comments.UserDisplayName: helming
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-10T19:25:10.950Z
Comments.Text: Show the complete output of `ffmpeg -i a.mp4 -i b.mkv -i x.wma -i y.mp3 -i z.mp3`
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-11T01:55:46.567Z
Comments.Text: Uploaded the output at https://pastebin.com/ABF5nFJR
Comments.UserDisplayName: helming
Tags: <ffmpeg>
Title: Concatenate multiple files using FFmpeg
UserDisplayName: helming
ThreadText: # Concatenate multiple files using FFmpeg
  
  (Asked by: username_0 on 2020-01-09)
  
  I started to learn FFmpeg syntax a couple of days ago.  
  I'm trying to read the official docs, it's not easy.
  
  So I want to build up a video files which consists of different videos, and audios.
  Let's say I have files below.
  
  Video files:
  
  * `a.mp4`
  * `b.mkv`
  
  Audio files:
  
  * `x.wma`
  * `y.mp3`
  * `z.mp3`
  
  I'd like to use specific parts of audio files.  
  Let's say,
  
  * 2s ~ 24 sec from `x.wma`
  * 1m 22s ~ 1m 41s from `y.mp3`
  * 29s ~ 2m 33s from `z.mp3`
  
  Concatenate the selected audio streams into an audio stream.
  
  I'll take the video stream of 2m ~ 2m 32s from `a.mp4`.
  
  Then video stream is a lot shorter than audio.  
  (I don't know how much exactly, hopefully FFmpeg can do that for me)
  
  Can FFmpeg do any of the below?
  
  1. Take the video streams from `b.mkv` and concatenate it with the video streams from a.mp4, so that resulted video stream is as long as the audio. After that mux the audio and video.
  2. Change the duration of the video stream from `a.mp4` so that duration of the video and audio are equal.(by changing playback speed of video stream) then mux the audio and video.
  3. Just insert an image file after video streams ends while audio is being played.
  
  P.S.: I tried to express things clearly, but I'm not so good at English. If there is anything you can't understand clearly, please tell me.
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: "Can FFmpeg do any of the below?" Yes. Which method do you prefer? I will give an example for one.  
  > **username_0**: so, FFmpeg can do all of them? Wow that's great! I prefer first method.  
  > **username_1**: Show the complete output of `ffmpeg -i a.mp4 -i b.mkv -i x.wma -i y.mp3 -i z.mp3`  
  > **username_0**: Uploaded the output at https://pastebin.com/ABF5nFJR  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-13. Score: 0
  
  Use the [concat](https://ffmpeg.org/ffmpeg-filters.html#concat) filter:
  
  ```
  ffmpeg -y -i a.mp4 -ss 2 -t 22 -i x.wma -ss 00:01:22 -t 19 -i y.mp3 -ss 29 -t 124 -i z.mp3 -filter_complex "[1:a][2:a][3:a]concat=n=3:v=0:a=1[a]" -map 0:v -map "[a]" -shortest output.mp4
  
  ```
  
  Alternatively, instead of `-ss`/`-t` you can use the atrim and asetpts filters.
  
  > **Comments:**
  > **username_0**: Is this a command for the first method? It doesn't seem to use b.mkv at all. But I think i get what you were trying to explain. Thank you Ilogan!  
  > **username_1**: @username_0 `b.mkv` was not used because the sum of the audio durations was shorter than the duration of `a.mp4`.  
  > **username_2**: @username_1, Any chance you have a look at https://video.stackexchange.com/questions/35053?  
  
  ---
  
  