A few strokes of the Technical House Society FFmpeg

Source: Internet
Author: User

Sometimes, I need to do some simple processing of a video file. Or it is the commission of Relatives and friends (but also embarrassed to refuse, because they think you are engaged in technology, this small matter should be able to easily take care of). But I don't have to install a bulky multimedia software for this. I do not want to go online to find a free gadget, afraid it is not clean. Anyway, I don't want to install software that isn't reputable enough. However, foreign open-source software can still be trusted, such as FFmpeg. Sentimental, huh?

FFmpeg are command-line, it is certainly inconvenient to use. However, this should not be a problem for technology homes. Below, I will list some more practical ways to use it.

Download and installation of FFmpeg

FFmpeg is open source. But we don't have to download its source code. Download the compiled Exe/dll. You can go to http://www.ffmpeg.org/download.html, then click "Windows Builds" and decide which package to download depending on whether your current machine is 32-bit or 64-bit. My machine ran win 7, so I chose "Download FFmpeg git-7c210c4 64-bit gkfx". If your English is not good, you can also go directly to My network download: http://pan.baidu.com/s/1jGgOomy.


After the download is complete, unzip to the hard disk, assuming the path is E:\OPENSRC. Start a console program and then execute the DOS command into the bin directory of the FFmpeg tool, as follows:

Scenario 1: Format conversion

I want to convert the. mov file taken with the iphone into an. avi file. The simplest, you can execute the following command:

Ffmpeg-i D:\Media\IMG_0873.MOV D:\Media\output.avi

This means that the source file under the D:\Media directory is converted to Output.avi (video: Img_0873.mov, Audio: AAC) (the encoding format is automatically selected as: Video MPEG4, audio mp3), and the destination file is still saved to the D:\Media directory. The problem is: I want to specify the encoding format, how to do? One way is to control the target file's extension (. flv,. mpg,. mp4,. wmv, etc.), for example:

Ffmpeg-i D:\Media\IMG_0873.MOV D:\Media\output2. flv

Another way is to control by-C:V parameters, such as I want to output the video format is h.265 (Warning: Encoding time will be longer OH). The command line is as follows:

Ffmpeg-i D:\Media\IMG_0873.MOV -c:v libx265 D:\Media\output265.avi

Note: You can use the Ffmpeg-encoders command to view all the optional encoding formats first.

No more probing, we continue. I found that the source file image frame size is 1920x 1080, I do not need this large-can have 720 x 480 is enough. Therefore, it is necessary to use the-s parameter. In order to ensure the quality of image scaling, it is best to add the code flow parameter-b:v. As follows:

Ffmpeg-i D:\Media\IMG_0873.MOV- s 720x480-b:v 1500k D:\Media\output2.avi

It can also be simpler to use-target parameters to match industry standards, parameter values can be VCD, SVCD, DVD, DV, DV50, etc., may also need to add a TV format as a prefix (pal-, ntsc-or film-). As follows:

Ffmpeg-i D:\Media\IMG_0873.MOV -target pal-dvd D:\Media\output2dvd.avi

Another question: I found that some of the videos I took with my phone were upside down, and I wanted it to rotate 90 degrees clockwise. At this point, you can use the-VF parameter to add a filter, as follows:

Ffmpeg-i D:\Media\IMG_0873.MOV -vf "rotate=90*pi/180" D:\Media\output3.avi

Note: If you want to rotate 90 degrees counterclockwise, 90 the front plus a minus sign is possible.

What if I only need to intercept a small segment from the source video? For example, start at 2 seconds and intercept for 10 seconds. The command line can do this:

FFmpeg -ss 2-t Ten -i D:\Media\IMG_0873.MOV D:\Media\output4.avi

Note: in this case, the-SS and-t parameters must precede-I, indicating that the input file followed by the qualifier is qualified.

Scenario 2: Video compositing

I found that videos taken with mobile phones sometimes have a larger background noise. How do you get rid of the noise and change it into a beautiful piece of music? The use of ffmpeg can also be easily done.

The first step: Remove the audio from the source file and generate a temporary file Tmp.mov

Ffmpeg-i D:\Media\IMG_0873.MOV -vcodec copy-an D:\Media\tmp.mov

Note:-vcodeccopy means that the source video is not decoded and copied directly to the target file;-an means that the audio in the source file is discarded.

Step Two: Synthesize this silent video file (Tmp.mov) with a music file (Music.mp3) and eventually generate Output.mov

Ffmpeg-i D:\Media\tmp.mov -ss 30-t -i D:\Media\music.mp3 -vcodec copy D:\Media\output5.avi

To ensure good compositing, the duration of the music must match the length of the video. Here we know in advance that the video length is 52 seconds, so intercept the Music.mp3 file of the 30th second of the next 52 seconds and video synthesis. In addition, in order to ensure the accuracy of audio time interception, we do not use-acodec copy here, but let the audio re-transcoding.

Another scenario: we want to overlay a picture on a video. This can be achieved simply as follows:

Ffmpeg-i D:\Media\IMG_0873.MOV-i D:\Media\logo.png -filter_complex ' overlay ' D:\Media\output6.avi

Scenario 3: Video Playback

After the format is converted or synthesized, we need to try to play it. There are many options for the player. You can also use the Ffplay tool here:

Ffplay-i D:\Media\output6.avi

Scenario 4: Get video information

Sometimes I just want to see the format information for this video file. You can use the Ffprobe tool:

Ffprobe-i D:\Media\IMG_0873.MOV

Other applications

The FFmpeg feature is very powerful. The key is to understand the meaning of the various parameters, and skillfully collocation. If necessary, read the online documentation in full: http://www.ffmpeg.org/ffmpeg.html

A few strokes of the Technical House Society FFmpeg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.