[링크 : https://github.com/mpenkov/ffmpeg-tutorial/blob/master/tutorial01.c]
사용된 헤더별 구조체
libavcodec/avcodec.h - AVCodecContext - AVCodec - AVPacket
libavformat/avformat.h - AVFormatContext
libswscale/swscale_internal.h ?? - SwsContext
libavutil/frame.h from libavcodec/avcodec.h - AVFrame
libavutil/dict.h - AVDictionary |
av_register_all() // Initialize libavformat and register all the muxers, demuxers and protocols.
avformat_open_input() avformat_find_stream_info() av_dump_format() avcodec_find_decoder() avcodec_open2() av_frame_alloc() avpicture_get_size()
av_malloc() sws_getContext()
avpicture_fill() while(av_read_frame()) avcodec_decode_video2() sws_scale() av_free_packet()
av_free() avcodec_close() avformat_close_input() |
AVFormatContext *pFormatCtx = NULL; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVFrame *pFrame = NULL; AVFrame *pFrameRGB = NULL; AVPacket packet; AVDictionary *optionsDict = NULL; struct SwsContext *sws_ctx = NULL;
av_register_all(); avformat_open_input(&pFormatCtx, argv[1], NULL, NULL); avformat_find_stream_info(pFormatCtx, NULL); av_dump_format(pFormatCtx, 0, argv[1], 0);
pCodecCtx=pFormatCtx->streams[videoStream]->codec; pCodec=avcodec_find_decoder(pCodecCtx->codec_id); avcodec_open2(pCodecCtx, pCodec, &optionsDict) pFrame=av_frame_alloc(); pFrameRGB=av_frame_alloc(); numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
sws_ctx = sws_getContext( pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL ); avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
while(av_read_frame(pFormatCtx, &packet)>=0) { avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); av_free_packet(&packet); } av_free(buffer); av_free(pFrameRGB); av_free(pFrame); avcodec_close(pCodecCtx); avformat_close_input(&pFormatCtx); |
void av_register_all (void)
// Initialize libavformat and register all the muxers, demuxers and protocols.
[링크 : https://www.ffmpeg.org/.../group__lavf__core.html#ga917265caec45ef5a0646356ed1a507e3]
int avformat_open_input (AVFormatContext ** ps,
const char * url,
AVInputFormat * fmt,
AVDictionary ** options
)
[링크 : https://www.ffmpeg.org/.../group__lavf__decoding.html#ga31d601155e9035d5b0e7efedc894ee49]
void avformat_close_input (AVFormatContext ** s)
[링크 : https://www.ffmpeg.org/.../group__lavf__decoding.html#gae804b99aec044690162b8b9b110236a4]
int avformat_find_stream_info ( AVFormatContext * ic, AVDictionary ** options )
// Read packets of a media file to get stream information.
[링크 : https://www.ffmpeg.org/.../group__lavf__decoding.html#gad42172e27cddafb81096939783b157bb]
void av_dump_format ( AVFormatContext * ic,
int index,
const char * url,
int is_output
)
//Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
[링크 : https://www.ffmpeg.org/.../group__lavf__misc.html#gae2645941f2dc779c307eb6314fd39f10]
AVCodec* avcodec_find_decoder ( enum AVCodecID id )
// Find a registered decoder with a matching codec ID.
[링크 : https://www.ffmpeg.org/.../group__lavc__decoding.html#ga19a0ca553277f019dd5b0fec6e1f9dca]
int avcodec_open2 ( AVCodecContext * avctx,
const AVCodec * codec,
AVDictionary ** options
)
// Initialize the AVCodecContext to use the given AVCodec.
// Warning - This function is not thread safe!
[링크 : https://www.ffmpeg.org/.../group__lavc__core.html#ga11f785a188d7d9df71621001465b0f1d]
AVFrame* av_frame_alloc ( void )
// Allocate an AVFrame and set its fields to default values.
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavu__frame.html#gac700017c5270c79c1e1befdeeb008b2f]
attribute_deprecated int avpicture_get_size ( enum AVPixelFormat pix_fmt,
int width,
int height
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavc__picture.html#gad2eba60171ee81107d2ca3a6957f4f2d]
int av_image_get_buffer_size ( enum AVPixelFormat pix_fmt,
int width,
int height,
int align
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavu__picture.html#ga24a67963c3ae0054a2a4bab35930e694]
void* av_malloc ( size_t size )
[링크 : https://www.ffmpeg.org/.../group__lavu__mem__funcs.html#ga9722446c5e310ffedfaac9489864796d]
struct SwsContext* sws_getContext ( int srcW,
int srcH,
enum AVPixelFormat srcFormat,
int dstW,
int dstH,
enum AVPixelFormat dstFormat,
int flags,
SwsFilter * srcFilter,
SwsFilter * dstFilter,
const double * param
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__libsws.html#gaf360d1a9e0e60f906f74d7d44f9abfdd]
attribute_deprecated int avpicture_fill ( AVPicture * picture,
const uint8_t * ptr,
enum AVPixelFormat pix_fmt,
int width,
int height
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavc__picture.html#gab740f592342cbbe872adf3e85c52e40c]
int av_image_fill_arrays ( uint8_t * dst_data[4],
int dst_linesize[4],
const uint8_t * src,
enum AVPixelFormat pix_fmt,
int width,
int height,
int align
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavu__picture.html#ga5b6ead346a70342ae8a303c16d2b3629]
int av_read_frame ( AVFormatContext * s,
AVPacket * pkt
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavf__decoding.html#ga4fdb3084415a82e3810de6ee60e46a61]
attribute_deprecated int avcodec_decode_video2 ( AVCodecContext * avctx,
AVFrame * picture,
int * got_picture_ptr,
const AVPacket * avpkt
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavc__decoding.html#ga3ac51525b7ad8bca4ced9f3446e96532]
int avcodec_receive_frame ( AVCodecContext * avctx,
AVFrame * frame
)
[링크 : https://www.ffmpeg.org/doxygen/3.2/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c]
+
2017.03.06
avcodec_register_all();
av_register_all();
avformat_network_init();
[링크 : http://laconicd.blogspot.com/2014/01/ffmpeg.html]
[링크 : http://egloos.zum.com/aslike/v/3083403]
+
2017.03.08
[링크 : https://www.codeproject.com/Tips/111468/FFmpeg-Tutorial]
[링크 : http://dranger.com/ffmpeg/tutorial01.html]
[링크 : https://ffmpeg.org/doxygen/trunk/doc_2examples_2decoding_encoding_8c-example.html]