FFmpeg video/audio coding/decoding zero-Basic Learning Method

Source: Internet
Author: User
Tags coding standards

During this period of time on csdn, many people in the same industry, especially those who use FFMPEG for video/audio encoding/decoding, some of which have many years of experience ", some are just beginners. During my discussion with you, I suddenly found a problem: There seems to be an insurmountable gap between the "Great God" and beginners. The "Great gods" are superb, exploring profound issues, while beginners are still at the entry stage. What is the reason for this polarization? Finally, I found the key to the problem: FFmpeg is difficult, but there is no step-by-step tutorial from simple to complex. Currently, most of the tutorials on FFMPEG on the Internet are difficult, and they are not suitable for those who are new to FFMPEG. In addition, many examples of program compilation and translation fail, which greatly dispels their enthusiasm for learning. I also encountered a lot of difficulties when I first started to learn FFMPEG. To help more people quickly become "Great gods", I would like to summarize a method to learn FFMPEG, so that you can learn FFMPEG step by step.

0. Background Knowledge

This chapter mainly introduces where FFmpeg is used (only a few of what I know here is actually far more than this ). To put it bluntly, FFmpeg is very important.

Use FFMPEG as the kernel Video Player:

Mplayer, ffplay, shooter player, storm video, kmplayer, QQ video...

Use FFMPEG as the DirectShow filter of the kernel:

Ffdshow, LAV filters...

Use FFMPEG as the kernel transcoding tool:

FFmpeg, format factory...

As a matter of fact, FFMPEG's video/audio encoding/decoding function is indeed too powerful and covers almost all existing video/audio coding standards. Therefore, as long as you develop video/audio, it is almost impossible to do it.

 

1. Use ffmpegprogram (ffmpeg.exe,ffplay.exe,ffprobe.exe)

This chapter describes how to use three EXE files in the FFMPEG project.

FFmpeg official website is: http://ffmpeg.org/

Compiled windows available version (the official website can be connected to this site, and the official site to maintain synchronization): http://ffmpeg.zeranoe.com/builds/

The FFMPEG in this website is divided into three versions: static, shared, and Dev.

The first two versions can be used directly in the command line. The difference is that there are only three applications in static: ffmpeg.exe,ffplay.exe,ffprobe.exe. Each EXE has a large volume, related dll has been compiled into exe. In addition to three applications: ffmpeg.exe, ffplay.exe, ffprobe.exe, there are some DLL, such as avcodec-54.dll. The EXE in shared is very small. When they are running, they call the function in the corresponding DLL.

The Dev version is used for development. It contains the library file XXX. lib and the header file XXX. H. This version does not contain the EXE file.

Open the system command line interface and switch to the directory where FFmpeg is located to use the three applications.

1.1 ffmpeg.exe

FFmpeg is an application for transcoding.

A simple transcoding command can be written as follows:

Transcode input. Avi to output. Ts and set the video bit rate to 640 Kbps.

 

[Plain]View plaincopy
  1. FFmpeg-I input. Avi-B: V 640 K output. Ts

For details about how to use FFMPEG, refer to the description of FFMPEG parameters in Chinese.

 

Detailed instructions for use (English): http://ffmpeg.org/ffmpeg.html

1.2 ffplay.exe

Ffplay is an application for playing.

A simple Playback command can be written as follows:

Play test. Avi

 

[Plain]View plaincopy
  1. Ffplay test. Avi

For more information, see ffplay's shortcut keys and options.

 

Detailed instructions for use (English): http://ffmpeg.org/ffplay.html

1.3 ffprobe.exe

Ffprobe is an application used to view file formats.

This is not much to mention.

Detailed instructions for use (English): http://ffmpeg.org/ffprobe.html

 

2. Use of FFMPEG Library: Video Player

This chapter describes how to use the FFMPEG library for development.

2.1 FFMPEG library Configuration

From http://ffmpeg.zeranoe.com/builds/website

1. Download the dev version, which contains the XXX. h header file of FFMPEG and the XXX. Lib library file.

2. Download the shared version, which contains the ffmpeg dll file.

3. Copy these two files to the VC project.

Note: problems may occur. For details, refer to the steps required to port FFMPEG library to VC.

If you do not want to manually configure it, you can download the configured project: the simplest Video Player Based on FFMPEG + SDL

2.2 simplest Video Player

I learned the code in the article "100-line code implementation of the most simple Video Player Based on FFMPEG + SDL", which is the simplest code for video players by FFMPEG and streamlined by myself, it can no longer be simplified. Every line is important.

FFmpeg function Introduction: FFMPEG function Introduction

Note 1: SDL is used to play video or audio data. For more information about SDL, see SDL introduction.

SDL Reference document: Chinese Translation of SDL Guide

NOTE 2: If you want to view the decoded data, you need to use the yuv player: YUV player source code or YUV player deluxe.

2.3 research on relevant struct

For the relationship between FFMPEG struct, refer to the article: Relationship between the most critical struct in FFMPEG.

For the analysis of each variable in the struct, refer to the article:

FFmpeg Structure Analysis: avframe

FFmpeg struct analysis: avformatcontext
FFmpeg struct analysis: avcodeccontext
FFmpeg struct analysis: aviocontext
FFmpeg struct analysis: avcodec
FFmpeg struct analysis: avstream
FFmpeg struct analysis: avpacket

 

 

3. Use of FFMPEG Library: the simplest audio player for audio player 3.1

The code in the article "the simplest Audio Player Based on FFMPEG + SDL" is the same as the simplest video player. This is the simplest audio player, and each line of code is very important.

Note: If you want to view the decoded data (PCM data), you need to use audition.

4. Use of FFMPEG Library: a real player-ffplay4.1 Real Player

The ffplay flowchart is shown in ffplay source code analysis: Overall flowchart. Ffplay code is complex, but its core code is the same as that of FFMPEG + SDL-based video player, which implements the simplest code of Line 1. You can combine two projects for learning.

Ffplay code Introduction: How to Use FFMPEG to compile a simple player

Ffplay instructions: ffplay shortcut keys and options

Ffplay has been transplanted to the VC project: ffplay_vc2005 (others do, the quality is very good)

The project for porting ffplay to MFC contains a simple graphical interface and some control buttons: ffplay player to transplant VC project: ffplay for MFC

 

5. Use of FFMPEG Library: Encoding5.1 Encoding

I have not studied much about FFMPEG encoding. For details, refer to the article: Using FFMPEG class library to encode YUV video sequence as video

The above article uses older class libraries. For more information about using the new class libraries, see the following articles.

For details about image encoding, refer to: the simplest FFMPEG-based image encoder (YUV encoding is JPEG)

Audio Encoding can be referred to: the simplest FFMPEG-Based Audio Encoder (PCM encoding is AAC)

Video Encoding can be referred to: the simplest Video Encoder Based on FFMPEG (YUV encoding is H.264)

5.2 Transcoding

Transcoding is actually decoded first and then encoded.

For programs that only convert encapsulation formats without transcoding, see: the simplest FFMPEG-based Encapsulation Format converter (without coding/decoding)

For more information about transcoding programs, see: the simplest FFMPEG-based transcoding program.

For more complex transcoding programs, see FFMPEG. C. It is transplanted to the project of MFC: FFMPEG Transcoder transplanted VC project: FFMPEG for MFC

6. FFMPEG source code analysis

After understanding how to use the FFMPEG library, you can take a look at the FFMPEG source code. Note that the source code of FFMPEG can be compiled only in Linux, and mingw can be used in windows. We recommend that you use eclipse to view the FFMPEG source code.

There is a complete FFMPEG source code analysis document: ffdoc

The following is a list of FFMPEG source code analysis articles.

Library Function Analysis:

Illustration: The function avformat_open_input of FFMPEG to open the media

Simple Analysis of FFMPEG source code: av_register_all ()
Simple Analysis of FFMPEG source code: avcodec_register_all ()
Simple Analysis of FFMPEG source code: av_read_frame ()
Simple Analysis of FFMPEG source code: avcodec_decode_video2 ()
FFmpeg source code analysis: avformat_open_input () (Media OPEN function)

 

Ffmpeg.exe source code analysis:

FFmpeg source code analysis: transcode_init () function
FFmpeg source code analysis: transcode () function

7. FFMPEG-related engineering Learning

After learning FFMPEG, you can also learn about FFMPEG-based multimedia open source projects. Here we recommend the following:

7.1 ffdshow

Ffdshow is the DirectShow Filter Based on the FFMPEG decoder class library libavcodec. Widely installed on PCs.

Source code analysis article about ffdshow (updated ):

Ffdshow Source Code Analysis 1: Overall Structure
Ffdshow Source Code Analysis 2: bitmap overwrite filter (dialog in the dialog box)

Ffdshow Source Code Analysis 3: bitmap overwrite filter (settings)
Ffdshow source code analysis 4: bitmap overwrite filter (filter part)
Ffdshow source code analysis 5: bitmap overwrite filter (Summary)
Ffdshow source code analysis 6: Package the decoder DLL (libavcodec)
Ffdshow source code analysis 7: libavcodec Video Decoder class (tvideocodeclibavcodec)
Ffdshow source code analysis 8: Video Decoder class (tvideocodecdec)
Ffdshow source code analysis 9: Summary of classes related to codecs

 

7.2 LAV Filters

LAV filter is the FFMPEG-based decoder class library libavcodec and The DirectShow filter for the unpacker class library libavformat. Widely installed on PCs.

Source code analysis of LAV filter:

LAV filter source code Analysis 1: Overall Structure

LAV filter source code Analysis 2: LAV Splitter

LAV filter source code Analysis 3: LAV video (1)

LAV filter source code analysis 4: LAV video (2)

 

7.3 mplayer

Mplayer is the most widely used player in Linux, and also has the Windows version. FFmpeg is used.

Source code analysis for mplayer:

Mplayer source code analysis

7.4 Media Player classic-HC

Nowadays, many players are widely used on the basis of Media Player classic-HC.

Source code analysis of Media Player classic-HC:

Media Player classic-HC Source Code Analysis 1: Overall Structure
Media Player classic-HC Source Code Analysis 2: Core class (cmainframe) (1)
Media Player classic-HC Source Code Analysis 3: Core class (cmainframe) (2)
Media Player classic-HC source code analysis 4: Core class (cmainframe) (3)
Media Player classic-HC source code analysis 5: About the dialog box (caboutdlg)
Media Player classic-HC source code analysis 6: mediainfo tab (cppagefilemediainfo)
Media Player classic-HC source code analysis 7: Details tab (cppagefileinfodetails)

 

 

From: http://blog.csdn.net/leixiaohua1020/article/details/15811977

7.5 xbmc

Xbmc is an excellent Free and Open Source (GPL) Media Center Software.

For xbmc source code analysis articles:

Xbmc Source Code Analysis 1: Overall Structure and Compilation Method

Xbmc Source Code Analysis 2: Addons (skin Skin)

Xbmc Source Code Analysis 3: Core-Overview

Xbmc source code analysis 4: Video Player (dvdplayer)-decoder (taking FFMPEG as an example)

Xbmc source code analysis 5: Video Player (dvdplayer)-demultiplexing (taking FFMPEG as an example)

Xbmc source code analysis 6: Video Player (dvdplayer)-File Header (taking FFMPEG as an example)

Xbmc source code analysis 7: Video Player (dvdplayer)-input stream (using librtmp as an example)

 

8. Other FFMPEG Functions

Here we will introduce the use of avfilter in FFMPEG. Avfilter can be used to add various processing effects to the drinks. A simple example is to add a watermark to a video:

The simplest example of avfilter Based on FFMPEG (watermark superposition)

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.