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};
  • 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.
    – Rajib
    Mar 19 '15 at 12:42

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
  • 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.
    – slhck
    Apr 7 '15 at 7:45
  • @LordNeckbeard, I added the suggestion from Areeb Soo Yasir. It looks like the same command, but you might want to verify.
    – fixer1234
    Jul 26 '17 at 16:47
  • @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).
    – llogan
    Jul 26 '17 at 17:11

Many thanks to LordNeckbeard just one thing is that you may think his solution doesn't work because if you copy and paste everything will not work. Just put it all as one line and it will work like so:

ffmpeg -i file1.mp4 -i file2.mp4 -i file3.mp4 -i watermark.png -filter_complex "[0:v]setpts=PTS-STARTPTS[v0]; [1:v]setpts=PTS-STARTPTS[v1]; [2:v]setpts=PTS-STARTPTS[v2]; [v0][0:a][v1][1:a][v2][2:a]concat=n=3:v=1:a=1[v][aout]; [v][3:v]overlay=W-w-10:10[vout]" -map "[vout]" -map "[aout]" output.mp4
  • 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.
    – fixer1234
    Jul 25 '17 at 20:48
  • 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. Jul 26 '17 at 7:43
  • 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.
    – fixer1234
    Jul 26 '17 at 16:50
  • @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 [^]).
    – llogan
    Jul 26 '17 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.