当前位置:网站首页>Ffmpeg audio and video unpacking
Ffmpeg audio and video unpacking
2022-07-18 06:41:00 【Mr.codeee】
1. brief introduction
decapsulation : As shown in the figure below , Will be FLV、MKV、MP4 Wait for the file to be unpacked into video H.264 or H.265 compressed data , Audio MP3 or AAC Of compressed data , The following figure shows the common basic operations .

2. technological process
The following figure is the basic flow chart of unpacking .

2.1 In the use of FFmpeg API Before , Need to register first API, And then you can use it API. Of course , The new version of the library does not need to call the following methods .
av_register_all()2.2 structure AVFormatContext
Declare the input encapsulation structure , Use the input file or stream address as the handle of the encapsulation structure . Streaming address of Korean TV station rtmp://mobliestream.c3tv.com:554/live/goodtv.sdp.
AVFormatContext* inputFmtCtx = nullptr;
const char* inputUrl = "rtmp://mobliestream.c3tv.com:554/live/goodtv.sdp";
/// Open the input stream , get data begin
int ret = avformat_open_input(&inputFmtCtx, inputUrl, NULL, NULL);2.3 Find audio and video stream information , Through the following interface with AVFormatContext Create the stream information corresponding to the input file .
// lookup ;
if (avformat_find_stream_info(inputFmtCtx, NULL) < 0)
{
printf("Couldn't find stream information.\n");
return false;
}2.4 Read audio and video stream , use av_read_frame To read packets , The read data is stored in AVPacket in , Make sure it's audio 、 video 、 Subtitling Data , Finally decode , Or store .
AVPacket* pkt = NULL;
pkt = av_packet_alloc();
while (av_read_frame(inputFmtCtx, pkt) >= 0)
{
// Get packets
//..... Decode or store
// Reset
av_packet_unref(pkt);
}
The above code shows , Call... Through a loop av_read_frame() Read pkt package , Then you can decode or store data , If the read data ends , Then exit the loop , Start point to end operation .
2.5 Close the input file after execution , Release resources .
// close
avformat_close_input(&inputFmtCtx);
// Release resources
av_packet_free(&pkt);3. Source code
int main()
{
//av_register_all();
avformat_network_init();
AVDictionary* options = NULL;
av_dict_set(&options, "buffer_size", "1024000", 0);
av_dict_set(&options, "max_delay", "500000", 0);
av_dict_set(&options, "stimeout", "2000000", 0);
av_dict_set(&options, "rtsp_transport", "tcp", 0);
AVFormatContext* inputFmtCtx = nullptr;
const char* inputUrl = "rtmp://mobliestream.c3tv.com:554/live/goodtv.sdp";
/// Open the input stream , get data begin
int ret = avformat_open_input(&inputFmtCtx, inputUrl, NULL, NULL);
if (ret != 0)
{
printf("Couldn't open input stream.\n");
return -1;
}
int vIndex = -1;
int aIndex = -1;
// lookup ;
if (avformat_find_stream_info(inputFmtCtx, NULL) < 0)
{
printf("Couldn't find stream information.\n");
return false;
}
AVPacket* pkt = NULL;
pkt = av_packet_alloc();
while (av_read_frame(inputFmtCtx, pkt) >= 0)
{
// Get packets
//..... Decode or store
// Reset
av_packet_unref(pkt);
}
// close
avformat_close_input(&inputFmtCtx);
// Release resources
av_packet_free(&pkt);
return 0;
}
边栏推荐
- 【森城市】GIS数据漫谈(四)— 坐标系统
- 医疗单据OCR识别+知识库校验,赋能保险智能理赔
- Functions and arrow functions
- 企业在创建产品帮助中心时需要注意的问题!
- Jerry opened the key pairing, and after the first pairing TWS, it is difficult to pair successfully by cross pairing [article]
- Excerpts of good articles and sentences in the thesis
- 2pc and 3pc of consistency agreement
- fink.15 DataSet模块 算子大全
- Diwen serial port screen tutorial (1)
- QT ui设计师界面常用操作记录(QTableWidget)
猜你喜欢

Hongke case | nanogue uses Onyx system to realize nondestructive characterization of graphene electrical properties

External interrupt of stm32f4

网络套接字编程

Symbol data type

Among the top 50 intelligent operation and maintenance enterprises in 2022, Borui data strength was selected

How to break the magic spell with a good hand in the strong B & B industry?

Redis (II) three special types of redis

Together with Alibaba cloud, grafana labs will provide the first grafana hosting service in China

【专有名词】

Matlab-mex
随机推荐
Functions and symbols
Domain Driven Design Fundamentals
网络套接字编程
forEach、for in、for of三者区别
MySQL CREATE TABLE statement error: 1103 incorrect table name
2、Deep Learning in Higher Dimensions
软件研发效能需求价值流分析专题
@Use of equalsandhashcode annotation
Differences among foreach, for in and for of
Practice of online problem feedback module (II): automatic generation of class file by encapsulating code
G1 is so strong, are you sure you don't know?
Hongke case | nanogue uses Onyx system to realize nondestructive characterization of graphene electrical properties
[Mori city] random talk on GIS data (IV) - coordinate system
What is the difference between reject and catch processing in promise
Together with Alibaba cloud, grafana labs will provide the first grafana hosting service in China
The difference between set and map
Practice of online problem feedback module (III): automatically generate all controller, service, mapper and other files
圖撲 Web 可視化引擎在仿真分析領域的應用
How to break the magic spell with a good hand in the strong B & B industry?
@RequestBody