FFMPEG Video Concat and Overlay

7,204

You can do this in one command with the concat filter:

ffmpeg -i input0.ts -i input1.ts -i input2.ts -i overlay.png -filter_complex \
"[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[vv][a]; \
 [vv][3:v]overlay=W-w-10:10[v]" \
-map "[v]" -map "[a]" output.mp4
Share:
7,204

Related videos on Youtube

Ashish Dudeja
Author by

Ashish Dudeja

Updated on September 18, 2022

Comments

  • Ashish Dudeja
    Ashish Dudeja almost 2 years

    I want to combine two ffmpeg commands to a single command. I am using ready made ffmpeg binary in my Android application. I want to concat .ts files and overlay an image.

    I am using following commands:

    1. To concat .ts files:

      String[] ffmpegcommand = {"ffmpeg", "-i","concat:"+input_file_path+"|"+input_file_path1, "-c", "copy", "-bsf:a", "aac_adtstoasc", output_file_path};
      
    2. Apply image overlay effect:

      String[] ffmpegcommand = {"ffmpeg","-y" ,"-i", input_file_path,"-strict","experimental", "-vf","movie="+AppStaticData.BASE_FOLDER_PATH + File.separator + "watermarklogo.png"+" [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]", AppStaticData.BASE_FOLDER_PATH+"/" + output_file_path};
      
    • Rajib
      Rajib over 9 years
      I am not familiar with android. But to concat .ts files on linux you can simply "cat" them like text files. In linux i would pipe the catted file to the ffmpeg command.
  • slhck
    slhck over 9 years
    Whenever I used the concat filter, I never had to use the setpts filter to reset the timestamps. Let's say you're segmenting into .ts files using the segment muxer, then the TS files will have non-zero start times, e.g. the first frame in the second TS file may have a PTS of 12.4, but the concatenation will still work. Wondering in which cases it's strictly required. We may need to update the wiki entry, too.
  • fixer1234
    fixer1234 almost 7 years
    The intention is for each answer to provide a complete solution that is different from what has already been contributed. This is really, commentary or suggested improvement to another post. You're a little short of the rep needed to comment, but you could suggest this as an edit to the other answer.
  • Areeb Soo Yasir
    Areeb Soo Yasir almost 7 years
    Hi there fixer yes good point if LordNeckBeard can update his I am happy to remove this answer. It is just that as silly as it sounds I think it's a bit unusable as he has posted it and produces errors from ffmpeg which led me to initially believe the answer was not working, thus the actual full working command above.
  • fixer1234
    fixer1234 almost 7 years
    @LordNeckbeard, I added the suggestion from Areeb Soo Yasir. It looks like the same command, but you might want to verify.
  • fixer1234
    fixer1234 almost 7 years
    I added it to LordNeckbeard's answer. You might want to wait a day or two to see if he agrees with the edit before deleting your answer.
  • Elisa Cha Cha
    Elisa Cha Cha almost 7 years
    @fixer1234 Thanks, but I think the actual issue is that I forgot to add a backslash to some of the lines in my command. Either that or he is using Windows which I believe would require a ^ instead, or more typically Windows users make it into one line. The line breaks are just for readability. I'll fix it and it should work fine as is (for Linux and macOS).
  • Elisa Cha Cha
    Elisa Cha Cha almost 7 years
    @AreebSooYasir I forgot to add some missing backslashes in my answer. I often break up the command into multiple lines for readability and so users can more easily understand how the FFmpeg filtergraphs are constructed. Users can re-construct it into a single line if desired (and Windows users will be required to do so, or I think they can replace the backslash with a caret [^]).