91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

FFMPEG工程浩大,可以參考的書籍又不是很多,因此很多剛學習FFMPEG的人常常感覺到無從下手。因此特地分離出了一個簡單的視頻編碼器供學習之用。 該視頻編碼器實現了YUV420P像素數據編碼為H.264碼流 盡管該視頻編碼器的代碼十分簡單,但是幾乎包含了使用FFMPEG編碼一個視頻所有必備的API。十分適合FFmpeg的初學者。 工程基于VC2010。 使用了2014.5.6版本的FFmpeg類庫。 注:這是修正版,增加了flush_encoder()函數

資源截圖

代碼片段和文件信息

/*?
?*最簡單的基于FFmpeg的視頻編碼器
?*Simplest?FFmpeg?Video?Encoder
?*
?*雷霄驊?Lei?Xiaohua
?*leixiaohua1020@126.com
?*中國傳媒大學/數字電視技術
?*Communication?University?of?China?/?Digital?TV?Technology
?*http://blog.csdn.net/leixiaohua1020
?*
?*本程序實現了YUV像素數據編碼為視頻碼流(H264,MPEG2,VP8等等)。
?*是最簡單的FFmpeg視頻編碼方面的教程。
?*通過學習本例子可以了解FFmpeg的編碼流程。
?*This?software?encode?YUV420P?data?to?H.264?bitstream.
?*It‘s?the?simplest?video?encoding?software?based?on?FFmpeg.?
?*Suitable?for?beginner?of?FFmpeg?
?*/

#include?“stdafx.h“

extern?“C“
{
#include?“libavcodec\avcodec.h“
#include?“libavformat\avformat.h“
#include?“libswscale\swscale.h“
};


int?flush_encoder(AVFormatContext?*fmt_ctxunsigned?int?stream_index)
{
int?ret;
int?got_frame;
AVPacket?enc_pkt;
if?(!(fmt_ctx->streams[stream_index]->codec->codec->capabilities?&
CODEC_CAP_DELAY))
return?0;
while?(1)?{
printf(“Flushing?stream?#%u?encoder\n“?stream_index);
//ret?=?encode_write_frame(NULL?stream_index?&got_frame);
enc_pkt.data?=?NULL;
enc_pkt.size?=?0;
av_init_packet(&enc_pkt);
ret?=?avcodec_encode_video2?(fmt_ctx->streams[stream_index]->codec?&enc_pkt
NULL?&got_frame);
av_frame_free(NULL);
if?(ret? break;
if?(!got_frame)
{ret=0;break;}
printf(“編碼成功1幀!\n“);
/*?mux?encoded?frame?*/
ret?=?av_write_frame(fmt_ctx?&enc_pkt);
if?(ret? break;
}
return?ret;
}

int?_tmain(int?argc?_TCHAR*?argv[])
{
AVFormatContext*?pFormatCtx;
AVOutputFormat*?fmt;
AVStream*?video_st;
AVCodecContext*?pCodecCtx;
AVCodec*?pCodec;

uint8_t*?picture_buf;
AVframe*?picture;
int?size;

FILE?*in_file?=?fopen(“src01_480x272.yuv“?“rb“); //視頻YUV源文件?
int?in_w=480in_h=272;//寬高
int?framenum=50;
const?char*?out_file?=?“src01.h264“; //輸出文件路徑

av_register_all();
//方法1.組合使用幾個函數
pFormatCtx?=?avformat_alloc_context();
//猜格式
fmt?=?av_guess_format(NULL?out_file?NULL);
pFormatCtx->oformat?=?fmt;

//方法2.更加自動化一些
//avformat_alloc_output_context2(&pFormatCtx?NULL?NULL?out_file);
//fmt?=?pFormatCtx->oformat;


//注意輸出路徑
if?(avio_open(&pFormatCtx->pbout_file?AVIO_FLAG_READ_WRITE)? {
printf(“輸出文件打開失敗“);
return?-1;
}

video_st?=?av_new_stream(pFormatCtx?0);
if?(video_st==NULL)
{
return?-1;
}
pCodecCtx?=?video_st->codec;
pCodecCtx->codec_id?=?fmt->video_codec;
pCodecCtx->codec_type?=?AVMEDIA_TYPE_VIDEO;
pCodecCtx->pix_fmt?=?PIX_FMT_YUV420P;
pCodecCtx->width?=?in_w;??
pCodecCtx->height?=?in_h;
pCodecCtx->time_base.num?=?1;??
pCodecCtx->time_base.den?=?25;??
pCodecCtx->bit_rate?=?400000;??
pCodecCtx->gop_size=250;
//H264
//pCodecCtx->me_range?=?16;
//pCodecCtx->max_qdiff?=?4;
pCodecCtx->qmin?=?10;
pCodecCtx->qmax?=?51;
//pCodecCtx->qcompress?=?0.6;
//輸出格式信息
av_dump_format(pFormatCtx?0?out_file?1);

pCodec?=?avcodec_find_encoder(pCodecCtx->codec_id);
if?(!pCodec)
{
printf(“沒有找到合適的編碼器!\n“);
return?-1;
}
if?(avcodec_open2(pCodecCt

評論

共有 條評論