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
Use
-filter_complex
instead of-vf
. See the documentation for an explanation of the difference. Also, you don't need themovie
source filter.This will place the overlay in the top right with 10px padding. See examples of other placement locations and read the overlay filter documentation for more info.
Related videos on Youtube
![Ashish Dudeja](https://lh5.googleusercontent.com/-S7gXVsElWzA/AAAAAAAAAAI/AAAAAAAAABc/bbH6oowaur8/photo.jpg?sz=256)
Author by
Ashish Dudeja
Updated on September 18, 2022Comments
-
Ashish Dudeja almost 2 years
I want to combine two
ffmpeg
commands to a single command. I am using ready madeffmpeg
binary in my Android application. I want to concat.ts
files and overlay an image.I am using following commands:
To concat
.ts
files:String[] ffmpegcommand = {"ffmpeg", "-i","concat:"+input_file_path+"|"+input_file_path1, "-c", "copy", "-bsf:a", "aac_adtstoasc", output_file_path};
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 over 9 yearsI 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 over 9 yearsWhenever 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 thesegment
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 of12.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 almost 7 yearsThe 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 almost 7 yearsHi 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 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 almost 7 yearsI 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 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 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 [
^
]).