Home >Web Front-end >Front-end Q&A >Essential for getting started with ffmpeg

Essential for getting started with ffmpeg

咔咔
咔咔Original
2021-06-22 23:29:281272browse

Preface

I recently wanted to play with video watermarking, so I found the ffmpeg script, and then started playing with this tool.

Here are just simple operations, there are more tricks to play, and other functions are waiting for you to discover.

1. Installation

If you want to use it, you must install it first. Next, Kaka will take you step by step to achieve it. Install.

The installation environment is centos7 for linux.

Download address: wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz

Essential for getting started with ffmpeg
Figure 1-1

Figure 1-1 is the compressed package after downloading.

You can see that this compressed package is different from the usually used tar, and the suffix is ​​xz.

Execution: xz -d ffmpeg-git-amd64-static.tar.xz Perform the first step on the downloaded file.

Essential for getting started with ffmpeg
Figure 1-2

Figure 1-2 is the file after executing the above command. At this time, the file suffix is ​​only tar.

Then use tar to further decompress the file.

Essential for getting started with ffmpeg
Figure 1-3

Figure 1-3 is the decompressed file.

After fmpeg is downloaded, it is started.

Go to the file you just decompressed, and then execute ./ffmpeg.

If you can see the information below, it means the installation has been successful.

Essential for getting started with ffmpeg
Figure 1-4

2. Let ffmpeg be used globally

In fact, it is to create a soft link. Links on Linux are divided into soft and hard links. As for the detailed explanation, please check the relevant information yourself!

First enter the bin directory: cd usr/bin

Then execute the following two commands, as shown in Figure Essential for getting started with ffmpeg, click here to facilitate the decompression of the files A name change was made.

Essential for getting started with ffmpeg
Essential for getting started with ffmpeg

3. Everything is ready, start watermarking the video

Execute command: ffmpeg -i test.mp4 -vf "drawtext=fontfile=/SIMHEI.TTF: text='Kaka Chat':x=100:y=10: fontsize=48:fontcolor=red:shadowy=2" new.mp4

Parameter description

  • i is followed by the original video
  • -vf is followed by the font position
  • text Is the watermark name
  • x horizontal axis coordinate
  • y vertical axis coordinate
  • fontsize is the font Size
  • fontcolor is the text color
  • new.mp4 is the new output file

Start executing this command happily. When you click Enter to execute, you will be asked to enter y\n.

Just enter y directly.

Then you will be disappointed to see such an interface, as shown below

Essential for getting started with ffmpeg
Essential for getting started with ffmpeg

According to the error message, you can get I know the font cannot be found.

Since the font cannot be found, this is not very easy to deal with. Just open a window computer and you can choose from a variety of fonts.

Essential for getting started with ffmpeg
Font

Just copy the font you need and then transfer it to the linux server.

Essential for getting started with ffmpeg
Font

Then execute the command again.

You will then be able to see the data, which means that the text watermark has been printed successfully.

Essential for getting started with ffmpeg
Successful Interface

If you look at the renderings, you can see that the four words Kaka Chat have been typed into the video.

Have you ever wondered why watermarked videos are so bad?

Actually, this has nothing to do with ffmpeg. This is compressed when recording gif.

Essential for getting started with ffmpeg
Insert picture description here

Since text watermarks are so successful, the same is true for picture watermarks. Next, let’s take a look at what picture watermarks should be. Do.

4. Add image watermark to the video

Execute the command: ffmpeg -i test.mp4 - vf "movie=mark.png[watermark];[in][watermark] overlay=10:10[out]" new.mp4

Parameter Description

  • -i is the original video name
  • mark.png is the watermark image location
  • overlay is the image location
  • new.mp4 is the name of the new video

It is much easier to use image watermark than text watermark. You don’t need to consider whether the font exists, you only need to have a watermark image.

Essential for getting started with ffmpeg
Success Picture

The picture above is the effect after the picture watermark is successfully set.

Let’s take a look at the effect!

The picture of 51 in the upper left corner is the watermark picture set by Kaka.

Essential for getting started with ffmpeg
Picture Watermark Effect

After looking at the above two operations, it seems very simple, but in fact ffmpeg is very complicated, and there is so much content that it will make you collapse.

But we don’t need to understand everything, as long as it can fulfill our needs.

For example, current video websites basically play in m3u8 mode, so ffmpeg can also convert video files in mp4 format into m3u8 format.

If you are interested, you can give it a try. I won’t go into details here.

Persistence in learning, persistence in writing, and persistence in sharing are the beliefs that Kaka has always adhered to since its beginning. I hope that Kaka’s articles on the huge Internet can bring you a little bit of help. I’m Kaka, see you next time.

The above is the detailed content of Essential for getting started with ffmpeg. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn