Answers.Body: <p>End up using filters as this answer guides >> <a href="https://video.stackexchange.com/a/15479/10894">https://video.stackexchange.com/a/15479/10894</a></p>
  
  <pre><code>ffmpeg.StartInfo.Arguments = "/c ffmpeg.exe -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a1.mp4 -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a2.mp4 -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a3.mp4 -filter_complex \"[0:v]setpts=PTS-STARTPTS[v0]; [0:a]asetpts=PTS-STARTPTS[a0]; [1:v]setpts=PTS-STARTPTS[v1]; [1:a]asetpts=PTS-STARTPTS[a1]; [2:v]setpts=PTS-STARTPTS[v2]; [2:a]asetpts=PTS-STARTPTS[a2]; [v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]\" -map \"[v]\" -map \"[a]\" -c:v libx264 -preset slow -crf 20 -c:a aac " + videoOut + " -y -report";
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-27T09:51:06.140Z
Answers.LastActivityDate: 2016-04-27T09:51:06.140Z
Answers.LastEditDate: 2017-04-13T12:46:08.110Z
Answers.UserDisplayName: Eftekhari
Answers.Body: <p>Glad you fixed your problem. For anyone else coming across the question...</p>
  
  <p>The problem is that <code>concat demuxer</code> only works when multimedia streams are the same.</p>
  
  <p>As described <a href="http://ffmpeg.org/ffmpeg-formats.html#concat-1" rel="nofollow">here</a>, all files must have the same streams (same codecs, same time base, etc.).</p>
  
  <p>So you have to use a filter, forcing a re-encode. See <a href="https://www.ffmpeg.org/faq.html#How-can-I-concatenate-video-files_003f" rel="nofollow">this</a> reference.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-08T01:07:11.410Z
Answers.LastActivityDate: 2016-09-30T13:28:36.193Z
Answers.LastEditDate: 2016-09-30T13:28:36.193Z
Answers.UserDisplayName: paulzag
Answers.Body: <p>I was going to comment on paulzag's comment, but I need 50 reputation (what a stupid system).</p>
  <p>For me, the filter and demuxer weren't working at all, but I found out about &quot;Concat protocol&quot; on ffmpeg's site, which worked prefectly for me: <a href="https://trac.ffmpeg.org/wiki/Concatenate#protocol" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Concatenate#protocol</a></p>
  <p>I used the &quot;intermediate files&quot; method, which uses MPEG-2 TS files.</p>
  <p>Previous to this, the video was freezing at the first insertion for about 3 seconds, and then playing the rest of the video at half FPS. I think it was due to the videos being encoded using different settings.</p>
  <p>Now it perfectly combines both videos together with no issue.</p>
  <p>From the site:</p>
  <blockquote>
  <p>While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (MPEG-2 transport streams, possibly others) can be concatenated. This is analogous to using <code>cat</code> on UNIX-like systems or <code>copy</code> on Windows.</p>
  <p><strong>Instructions</strong></p>
  <p>The following command concatenates three MPEG-2 TS files and concatenates them without re-encoding:</p>
  <pre><code>ffmpeg -i &quot;concat:input1.ts|input2.ts|input3.ts&quot; -c copy output.ts
  </code></pre>
  <p><strong>Using intermediate files</strong></p>
  <p>If you have MP4 files, these could be losslessly concatenated by first transcoding them to MPEG-2 transport streams. With H.264 video and AAC audio, the following can be used:</p>
  <pre><code>ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts 
  ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
  ffmpeg -i &quot;concat:intermediate1.ts|intermediate2.ts&quot; -c copy -bsf:a aac_adtstoasc output.mp4
  </code></pre>
  <p><strong>Using named pipes to avoid intermediate files</strong></p>
  <p>If you're using a system that supports named pipes, you can use those to avoid creating intermediate files. This sends stderr (to which ffmpeg sends all the written data) to <code>/dev/null</code>, to avoid cluttering up the command-line:</p>
  <pre><code>mkfifo temp1 temp2 
  ffmpeg -y -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2&gt; /dev/null &amp; \
  ffmpeg -y -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2&gt; /dev/null &amp; \
  ffmpeg -f mpegts -i &quot;concat:temp1|temp2&quot; -c copy -bsf:a aac_adtstoasc output.mp4 
  </code></pre>
  <p>The additional <code>-y</code> switch is needed to force ffmpeg to write to existing files <code>temp1</code> and <code>temp2</code>, which are the named pipes. Without the switch, the first two ffmpeg programs running in the background will not produce any output because they wait for interactive yes/no answers to the questions whether to overwrite existing files.</p>
  <p>All MPEG codecs (MPEG-4 Part 10 / AVC, MPEG-4 Part 2, MPEG-2 Video, MPEG-1 Audio Layer II, MPEG-2 Audio Layer III (MP3), MPEG-4 Part III (AAC)) are supported in the MPEG-TS container format, although the commands above would require some alteration (e.g., the <code>-bsf</code> bitstream filters will have to be changed).</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-12T21:51:56.847Z
Answers.LastActivityDate: 2021-04-01T01:54:34.543Z
Answers.LastEditDate: 2021-04-01T01:54:34.543Z
Answers.UserDisplayName: Dark Swordsman
Body: <p>I have big videos with different types of properties and trying to collect some part of these videos by ffmpeg.</p>
  
  <p>I use this command to cut specific parts:</p>
  
  <p><code>scale video &gt;&gt; scale png &gt;&gt; pad scaled_video &gt;&gt; add icon to padded_scaled_video &gt;&gt; encode.</code></p>
  
  <blockquote>
    <p>ffmpeg.StartInfo.Arguments = @"/c ffmpeg.exe -i " + VideoIn + " -i " +
    imageIn + " -filter_complex \"[0:v]
    scale='if(gt(a,6/4),480,-2)':'if(gt(a,6/4),-2,320)' [scaledv], [1:v]
    scale=iw*.5:ih*.5 [scaledicon], [scaledv]
    pad=480:320:(ow-iw)/2:(oh-ih)/2:black [scaledpaddedv],
    [scaledpaddedv][scaledicon] overlay=25:25,setsar=1:1 [finalv]\" -map
    \"[finalv]\" -map 0:a" + " -ss " + startCut.ToString() + " -c:v
    libx264 -preset slow -crf 20 -c:a aac -t " + duration.ToString() + " "
    + VideoOut + " -y -report";</p>
  </blockquote>
  
  <p>Which works perfectly.</p>
  
  <p>and then try to merge these videos with this command:</p>
  
  <blockquote>
    <p>ffmpeg.StartInfo.Arguments = "/c ffmpeg.exe -f concat -safe 0 -i \"" +
    concatTextDirectory + "\" -c copy -vf \"subtitles=\\'" + videoInSrt +
    "\\':force_style='FontName=DejaVu Serif,FontSize=26'\" -c:v libx264
    -preset slow -crf 20 -c:a aac " + videoOut + " -y -report";</p>
  </blockquote>
  
  <p>Which again works ok if cutted video parts are from the same type of video, and if they aren't there will be no video and only audio or jittery video on non-similar video parts.
  The first cutted video part is dominant on other parts.</p>
  
  <p>Question is most of the time video parts are not from the same video type and output is not playable. How could I cut video parts to be similar in properties to work without problem on concatenation part?</p>
  
  <p>This is <code>-report</code> log output:
  <a href="https://drive.google.com/open?id=0B_kWzdnSIxuQY09QWWZGVTBPdHM" rel="noreferrer">https://drive.google.com/open?id=0B_kWzdnSIxuQY09QWWZGVTBPdHM</a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-26T16:28:49.287Z
Comments.Text: Show the output of ffprobe for each of the input clips.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-26T16:57:13.173Z
Comments.Text: https://drive.google.com/open?id=0B_kWzdnSIxuQTGR1M3BnSzN5ak0 ------  https://drive.google.com/open?id=0B_kWzdnSIxuQT3VWR3cwSDJGbUk ------  https://drive.google.com/open?id=0B_kWzdnSIxuQczFJeV9TTzlOUms
Comments.UserDisplayName: Eftekhari
Tags: <video><ffmpeg>
Title: FFMpeg concat demuxer corrupted output (freezed video on some concatenated parts)
UserDisplayName: Eftekhari
ThreadText: # FFMpeg concat demuxer corrupted output (freezed video on some concatenated parts)
  
  (Asked by: username_0 on 2016-04-26)
  
  I have big videos with different types of properties and trying to collect some part of these videos by ffmpeg.
  
  I use this command to cut specific parts:
  
  `scale video >> scale png >> pad scaled_video >> add icon to padded_scaled_video >> encode.`
  
  > ffmpeg.StartInfo.Arguments = @"/c ffmpeg.exe -i " + VideoIn + " -i " +
  > imageIn + " -filter\_complex \"[0:v]
  > scale='if(gt(a,6/4),480,-2)':'if(gt(a,6/4),-2,320)' [scaledv], [1:v]
  > scale=iw\*.5:ih\*.5 [scaledicon], [scaledv]
  > pad=480:320:(ow-iw)/2:(oh-ih)/2:black [scaledpaddedv],
  > [scaledpaddedv][scaledicon] overlay=25:25,setsar=1:1 [finalv]\" -map
  > \"[finalv]\" -map 0:a" + " -ss " + startCut.ToString() + " -c:v
  > libx264 -preset slow -crf 20 -c:a aac -t " + duration.ToString() + " "
  > + VideoOut + " -y -report";
  
  Which works perfectly.
  
  and then try to merge these videos with this command:
  
  > ffmpeg.StartInfo.Arguments = "/c ffmpeg.exe -f concat -safe 0 -i \"" +
  > concatTextDirectory + "\" -c copy -vf \"subtitles=\\'" + videoInSrt +
  > "\\':force\_style='FontName=DejaVu Serif,FontSize=26'\" -c:v libx264
  > -preset slow -crf 20 -c:a aac " + videoOut + " -y -report";
  
  Which again works ok if cutted video parts are from the same type of video, and if they aren't there will be no video and only audio or jittery video on non-similar video parts.
  The first cutted video part is dominant on other parts.
  
  Question is most of the time video parts are not from the same video type and output is not playable. How could I cut video parts to be similar in properties to work without problem on concatenation part?
  
  This is `-report` log output:
  <https://drive.google.com/open?id=0B_kWzdnSIxuQY09QWWZGVTBPdHM>
  
  **Tags:** video, ffmpeg
  
  > **Comments:**
  > **username_1**: Show the output of ffprobe for each of the input clips.  
  > **username_0**: https://drive.google.com/open?id=0B_kWzdnSIxuQTGR1M3BnSzN5ak0 ------  https://drive.google.com/open?id=0B_kWzdnSIxuQT3VWR3cwSDJGbUk ------  https://drive.google.com/open?id=0B_kWzdnSIxuQczFJeV9TTzlOUms  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2016-04-27. Score: 0 | Accepted answer
  
  End up using filters as this answer guides >> <https://video.stackexchange.com/a/15479/10894>
  
  ```
  ffmpeg.StartInfo.Arguments = "/c ffmpeg.exe -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a1.mp4 -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a2.mp4 -i C:\\Users\\mtst\\Desktop\\Clips\\h\\a3.mp4 -filter_complex \"[0:v]setpts=PTS-STARTPTS[v0]; [0:a]asetpts=PTS-STARTPTS[a0]; [1:v]setpts=PTS-STARTPTS[v1]; [1:a]asetpts=PTS-STARTPTS[a1]; [2:v]setpts=PTS-STARTPTS[v2]; [2:a]asetpts=PTS-STARTPTS[a2]; [v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]\" -map \"[v]\" -map \"[a]\" -c:v libx264 -preset slow -crf 20 -c:a aac " + videoOut + " -y -report";
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2016-08-08. Score: 3
  
  Glad you fixed your problem. For anyone else coming across the question...
  
  The problem is that `concat demuxer` only works when multimedia streams are the same.
  
  As described [here](http://ffmpeg.org/ffmpeg-formats.html#concat-1), all files must have the same streams (same codecs, same time base, etc.).
  
  So you have to use a filter, forcing a re-encode. See [this](https://www.ffmpeg.org/faq.html#How-can-I-concatenate-video-files_003f) reference.
  
  
  ---
  
  ### Answer by username_3 on 2020-10-12. Score: 2
  
  I was going to comment on username_2's comment, but I need 50 reputation (what a stupid system).
  
  For me, the filter and demuxer weren't working at all, but I found out about "Concat protocol" on ffmpeg's site, which worked prefectly for me: <https://trac.ffmpeg.org/wiki/Concatenate#protocol>
  
  I used the "intermediate files" method, which uses MPEG-2 TS files.
  
  Previous to this, the video was freezing at the first insertion for about 3 seconds, and then playing the rest of the video at half FPS. I think it was due to the videos being encoded using different settings.
  
  Now it perfectly combines both videos together with no issue.
  
  From the site:
  
  > While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (MPEG-2 transport streams, possibly others) can be concatenated. This is analogous to using `cat` on UNIX-like systems or `copy` on Windows.
  >
  > **Instructions**
  >
  > The following command concatenates three MPEG-2 TS files and concatenates them without re-encoding:
  >
  > ```
  > ffmpeg -i "concat:input1.ts|input2.ts|input3.ts" -c copy output.ts
  >
  > ```
  >
  > **Using intermediate files**
  >
  > If you have MP4 files, these could be losslessly concatenated by first transcoding them to MPEG-2 transport streams. With H.264 video and AAC audio, the following can be used:
  >
  > ```
  > ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts 
  > ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
  > ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
  >
  > ```
  >
  > **Using named pipes to avoid intermediate files**
  >
  > If you're using a system that supports named pipes, you can use those to avoid creating intermediate files. This sends stderr (to which ffmpeg sends all the written data) to `/dev/null`, to avoid cluttering up the command-line:
  >
  > ```
  > mkfifo temp1 temp2 
  > ffmpeg -y -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \
  > ffmpeg -y -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \
  > ffmpeg -f mpegts -i "concat:temp1|temp2" -c copy -bsf:a aac_adtstoasc output.mp4 
  >
  > ```
  >
  > The additional `-y` switch is needed to force ffmpeg to write to existing files `temp1` and `temp2`, which are the named pipes. Without the switch, the first two ffmpeg programs running in the background will not produce any output because they wait for interactive yes/no answers to the questions whether to overwrite existing files.
  >
  > All MPEG codecs (MPEG-4 Part 10 / AVC, MPEG-4 Part 2, MPEG-2 Video, MPEG-1 Audio Layer II, MPEG-2 Audio Layer III (MP3), MPEG-4 Part III (AAC)) are supported in the MPEG-TS container format, although the commands above would require some alteration (e.g., the `-bsf` bitstream filters will have to be changed).
  
  
  ---
  
  