preface

In fact, FFmpeg is a well-known thing, the well-known iJkPlayer is Bilibili open source player is also based on FFmpeg to make. However, FFmpeg does more than just crop audio and video. It can also do more interesting things, such as video splicing. For an Android developer, FFmpeg C/C ++ is a hard thing to get away with. Downloading the official libraries, compiling them into SO for different platforms, and then integrating them into projects through JNI left many developers baffled at first. One problem is how to compile this so. How to integrate compiled files into your project. I’ll talk more about that in a later post, but I’ll just tell you what’s interesting.

Here I have to say, now each big factory is doing a unified front-end development language and framework, make developers TMD head is big, in fact, not still do some UI pages, through different ways to render it, if you really want to do some customized functions, or leave the original.

Android FFmpeg video splicing

Through the title you may not understand what the meaning, I do a few pictures of this App I made it, by the way put a few dynamic graphs, maybe you can know a general function. In fact, after you see, you may feel that the market has done this effect of the App, but as an Android siege lion, you must know how to make it, it is easy to do this effect on ios, there is a native Api to provide, but the pain of Android that can only be achieved through C/C++, It’s hard to do it native.

This App has the following functions (currently not open source, project address)

  • Video splicing (main)
  • Video width and height cropping
  • Video Duration Cropping
  • Add a video border and change the border color
  • Add video Cover
  • Add video background image
  • Adding a Video Watermark
  • Add background Music

Below are two video GIF images made by the App

If you want to watch a video, click the link below to get a three-in-one video and a two-in-one video

This app already has the following page, but it is not open source yet, there are still many things to change. The function is implemented. But there are a lot of optimizations, so FFmpeg is awesome. I’m going to show you how to do this yourself. So how about we look at the video as it comes out, because it doesn’t seem to have that feature,

How to achieve this effect

In this installment, I’m just going to show you how to use shell commands to make a video splice. Let’s start with the most basic functions. Then expand based on the current functionality. As for the compilation of the FFmpeg library, there is a lot to be said for a while. Parameter configuration is also a hassle, especially for different platforms. So let me show you how to do that in the simplest way possible, okay

The first step

If you want to use a static binary, you can use the FFmpeg library. If you want to use a static binary, you can use the FFmpeg library. Because the official static library has been compiled for us, we can simply go through the shell script.

FFmpeg official website library

So if I open the link, and I’ve selected MAC OS here you can see that the static library is provided at the bottom. We can just download it. Ubuntu is the same as Windows and there are libraries available. You can download it.

This is what it downloads. It’s about 71M on my end. It is quite large, because the official inside has given us most of the basic functions to compile into. So it’s this big, but if we compile it ourselves, it’s a lot smaller. You can disable something you don’t need

The second step

So, of course, open up our terminal, Windows win+R and then CMD ok, and then CD to the ffmpeg static library that we downloaded, run the command, and hopefully, you should see the following page

./ffmpeg
Copy the code

If the following appears, your FFMPEG is now ok

If permissions are insufficient, CD to your static library path to perform this is ok. Add a sudo and change mode to grant 777 privileges

chmod +x  ffmpeg
chmod 777 ffmpeg
Copy the code

At this point the FFMPEG environment is ready. All that’s left is the wind.

The third step

Video splicing, so how to video splicing, don’t worry about FFMPEG has given us the corresponding encapsulation. As long as you understand the corresponding command can complete the most basic video splicing function. Actually, FFMPEG is more than that. It’s so powerful.

Let’s start with a few simple commands to view the video file information

./ffmpeg -i input.mp4
Copy the code

And then we can see the details of the video: FPS, width, height, video quality, a lot of things

-i instruction is into the parameter, and then we directly see how to use the command to put a video together, such as the above two videos together of the little sister, we simply through the computer to synthesize.

./ffmpeg -i input2.mp4  -i input2.mp4  -filter_complex [0][1]vstack -y output.mp4 
Copy the code

If successful, it should be the following page

This MP4 file is a file in the same directory, you can change it to your own file name, as for filter_complex? I’m just going to make it plain, just like a function in Java, where you give it input and in this method body, it gives you the corresponding output. Vstack can be seen on the vstack website like this Stack Input Videos vertically. Is the meaning of vertical splicing video, the same as how to think of horizontal, as long as the Vstack to hstack can be, the old iron are not very simple, very powerful,

The most important thing is that you can complete some basic operations of the video through the command line, what PS, Photoshop, I command line ok. Hahahahahahaha

Just made the video effect, screenshots for you to see

Say good little sister, TMD this is what ghost is very terrible, the blogger changed a video ha ha ha, but this effect of the product to see will scold dead, the next article will give you how to optimize the video effect.

Ending

Hope to bring the old iron is the reserve of knowledge rather than a waste of time. This issue to say here, the simplest way to achieve video splicing, the next issue will bring you more content. You can also say in the comments which aspect of the content more want to know. I’m going to write it based on people’s opinions,

FFmpeg is so interesting (part 2)