Module:
Libavcodec-Codec
Libavdevice-Input support
Libavfilter-Video Audio filter Support
Libavformat-Visual Audio format parsing
Libavutil-Tools Library
Libpostproc-Post effect processing
Libswscale-Image Color, size conversion
1. Main function Analysis:
- Int_tmain (int argc, _tchar* argv[])
- {
- int ret;
- Avpacketpacket;
- Avframe *frame= NULL;
- enum Avmediatype type;
- unsigned intstream_index;
- unsigned int i;
- int got_frame;
- Int (*dec_func) (Avcodeccontext *, Avframe *, int *, const avpacket*);
- if (argc! = 3) {
- Av_log (NULL, Av_log_error, "Usage:%s<input file> <output file>\n", argv[0]);
- return 1;
- }
- Av_register_all ();
- Avfilter_register_all ();
- if (ret = Open_input_file (argv[1)) < 0)
- Goto END;
- if (ret = Open_output_file (argv[2)) < 0)
- Goto END;
- if (ret = Init_filters ()) < 0)
- Goto END;
- / * Read ALL packets * /
- While (1) {
- if ((ret= av_read_frame (Ifmt_ctx, &packet)) < 0)
- Break ;
- Stream_index = Packet.stream_index;
- Type =ifmt_ctx->streams[packet.stream_index]->codec->codec_type;
- Av_log (NULL, Av_log_debug, "Demuxergave frame of Stream_index%u\n",
- Stream_index);
- if (filter_ctx[stream_index].filter_graph) {
- Av_log (NULL, Av_log_debug, "Going toreencode&filter the frame\n");
- Frame =av_frame_alloc ();
- if (!frame) {
- ret = Averror (ENOMEM);
- Break ;
- }
- Packet.dts = Av_rescale_q_rnd (Packet.dts,
- Ifmt_ctx->streams[stream_index]->time_base,
- Ifmt_ctx->streams[stream_index]->codec->time_base,
- (avrounding) (av_round_near_inf| Av_round_pass_minmax));
- packet.pts = Av_rescale_q_rnd (packet.pts,
- Ifmt_ctx->streams[stream_index]->time_base,
- Ifmt_ctx->streams[stream_index]->codec->time_base,
- (avrounding) (av_round_near_inf| Av_round_pass_minmax));
- Dec_func = (Type = = Avmedia_type_video)? Avcodec_decode_video2:
- Avcodec_decode_audio4;
- RET =dec_func (Ifmt_ctx->streams[stream_index]->codec, Frame,
- &got_frame, &packet);
- if (Ret < 0) {
- Av_frame_free (&frame);
- Av_log (NULL, Av_log_error, "decodingfailed\n");
- Break ;
- }
- if (got_frame) {
- Frame->pts = Av_frame_get_best_effort_timestamp (frame);
- Ret= Filter_encode_write_frame (frame, stream_index);
- Av_frame_free (&frame);
- if (ret< 0)
- Goto END;
- } Else {
- Av_frame_free (&frame);
- }
- } Else {
- / * Remux this frame without reencoding * /
- Packet.dts = Av_rescale_q_rnd (Packet.dts,
- Ifmt_ctx->streams[stream_index]->time_base,
- Ofmt_ctx->streams[stream_index]->time_base,
- (avrounding) (av_round_near_inf| Av_round_pass_minmax));
- packet.pts = Av_rescale_q_rnd (packet.pts,
- Ifmt_ctx->streams[stream_index]->time_base,
- Ofmt_ctx->streams[stream_index]->time_base,
- (avrounding) (av_round_near_inf| Av_round_pass_minmax));
- RET =av_interleaved_write_frame (Ofmt_ctx, &packet);
- if (Ret < 0)
- Goto END;
- }
- Av_free_packet (&packet);
- }
- / * Flush Filters and encoders * /
- For (i = 0; i < ifmt_ctx->nb_streams; i++) {
- / * Flush filter * /
- if (!filter_ctx[i].filter_graph)
- continue;
- RET =filter_encode_write_frame (NULL, i);
- if (Ret < 0) {
- Av_log (NULL, Av_log_error, "Flushingfilter failed\n");
- Goto END;
- }
- / * Flush Encoder * /
- ret = Flush_encoder (i);
- if (Ret < 0) {
- Av_log (NULL, Av_log_error, "Flushingencoder failed\n");
- Goto END;
- }
- }
- Av_write_trailer (OFMT_CTX);
- End
- Av_free_packet (&packet);
- Av_frame_free (&frame);
- For (i = 0; i < ifmt_ctx->nb_streams; i++) {
- Avcodec_close (IFMT_CTX->STREAMS[I]->CODEC);
- if (ofmt_ctx && ofmt_ctx->nb_streams >i && ofmt_ctx->streams[i] &&ofmt_ctx-> STREAMS[I]->CODEC)
- Avcodec_close (OFMT_CTX->STREAMS[I]->CODEC);
- if (filter_ctx && filter_ctx[i].filter_graph)
- Avfilter_graph_free (&filter_ctx[i].filter_graph);
- }
- Av_free (FILTER_CTX);
- Avformat_close_input (&IFMT_CTX);
- if (Ofmt_ctx &&! ( Ofmt_ctx->oformat->flags & Avfmt_nofile))
- Avio_close (OFMT_CTX->PB);
- Avformat_free_context (OFMT_CTX);
- if (Ret < 0)
- Av_log (NULL, Av_log_error, "erroroccurred\n");
- return (ret. 1:0);
- }
1.1 int _tmain (int argc, _tchar* argv[])
People who have used C know that every C program will have a main (), but sometimes it is written by someone else to find that the main function is not an int main (), but an int _tmain (), and the header file is not <iostream.h> but <stdafx.h Will you be confused? First of all, this _tmain () is to support Unicode used by the main an alias, since it is an alias, there should be a macro defined, where is defined? In the <stdafx.h> that confused you, there are two lines
#include <stdio.h>
#include <tchar.h>
We can find the macro definition of _tmain in the header file <tchar.h>
#define _tmain Main
So, after pre-compiling, _tmain becomes main.
The _TCHAR type is a wide-character string, unlike the string we commonly use, which is a type used in 32-bit or higher operating systems.
The simplest transcoding program based on FFmpeg [Turn]--analysis