-
大小: 1.36MB文件類型: .gz金幣: 1下載: 0 次發布日期: 2023-09-27
- 語言: 其他
- 標簽: ffmpeg??decode??VideoDecode??視頻解碼??
資源簡介
基于ffmpeg源碼中example稍作修改,可以保存完整YUV數據。添加Makefile,便于編譯。解碼MPEG視頻,并將解碼后的數據保存成一幀幀的圖片。包含演示使用的視頻文件。
代碼片段和文件信息
/*
?*?Copyright?(c)?2001?Fabrice?Bellard
?*
?*?Permission?is?hereby?granted?free?of?charge?to?any?person?obtaining?a?copy
?*?of?this?software?and?associated?documentation?files?(the?“Software“)?to?deal
?*?in?the?Software?without?restriction?including?without?limitation?the?rights
?*?to?use?copy?modify?merge?publish?distribute?sublicense?and/or?sell
?*?copies?of?the?Software?and?to?permit?persons?to?whom?the?Software?is
?*?furnished?to?do?so?subject?to?the?following?conditions:
?*
?*?The?above?copyright?notice?and?this?permission?notice?shall?be?included?in
?*?all?copies?or?substantial?portions?of?the?Software.
?*
?*?THE?SOFTWARE?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF?ANY?KIND?EXPRESS?OR
?*?IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO?THE?WARRANTIES?OF?MERCHANTABILITY
?*?FITNESS?FOR?A?PARTICULAR?PURPOSE?AND?NONINFRINGEMENT.?IN?NO?EVENT?SHALL
?*?THE?AUTHORS?OR?COPYRIGHT?HOLDERS?BE?LIABLE?FOR?ANY?CLAIM?DAMAGES?OR?OTHER
?*?LIABILITY?WHETHER?IN?AN?ACTION?OF?CONTRACT?TORT?OR?OTHERWISE?ARISING?FROM
?*?OUT?OF?OR?IN?CONNECTION?WITH?THE?SOFTWARE?OR?THE?USE?OR?OTHER?DEALINGS?IN
?*?THE?SOFTWARE.
?*/
/**
?*?@file
?*?video?decoding?with?libavcodec?API?example
?*
?*?@example?decode_video.c
?*/
#include?
#include?
#include?
#include?
#define?INBUF_SIZE?4096
static?void?pgm_save(unsigned?char?*buf[]?int?wrap[]?int?xsize?int?ysize
?????????????????????char?*filename)
{
????FILE?*f;
????int?i;
????f?=?fopen(filename“w“);
????fprintf(f?“P5\n%d?%d\n%d\n“?xsize?ysize?255);
/*?Save?Y?data?*/
????for?(i?=?0;?(wrap[0])?&&?(i?????????fwrite(buf[0]?+?i?*?wrap[0]?1?xsize?f);
/*?Save?U(Cb)?data?*/
????for?(i?=?0;?(wrap[1])?&&?(i?????????fwrite(buf[1]?+?i?*?wrap[1]?1?xsize?/?2?f);
/*?Save?V(Cr)?data?*/
????for?(i?=?0;?(wrap[2])?&&?(i?????????fwrite(buf[2]?+?i?*?wrap[2]?1?xsize?/?2?f);
????fclose(f);
}
static?void?decode(AVCodecContext?*dec_ctx?AVframe?*frame?AVPacket?*pkt
???????????????????const?char?*filename)
{
????char?buf[1024];
????int?ret;
????ret?=?avcodec_send_packet(dec_ctx?pkt);
????if?(ret?0)?{
????????fprintf(stderr?“Error?sending?a?packet?for?decoding\n“);
????????exit(1);
????}
????while?(ret?>=?0)?{
????????ret?=?avcodec_receive_frame(dec_ctx?frame);
????????if?(ret?==?AVERROR(EAGAIN)?||?ret?==?AVERROR_EOF)
????????????return;
????????else?if?(ret?0)?{
????????????fprintf(stderr?“Error?during?decoding\n“);
????????????exit(1);
????????}
????????printf(“saving?frame?%3d\n“?dec_ctx->frame_number);
????????fflush(stdout);
printf(“+++++?FLC-DBG:?format:%d?linesize[0]:%d?linesize[1]:%d?linesize[2]:%d?+++++\n\n“
frame->format?frame->linesize[0]?frame->linesize[1]?frame->linesize[2]);
????????/*?the?picture?is?allocated?by?the?decoder.?no?need?to
???????????free?it?*/
????????snprintf(buf?sizeof(buf)?“%s-%d“?filename?dec_ctx->frame_number);
????????pgm_save(frame->data?frame->linesize
???
- 上一篇:select_course.rar
- 下一篇:VERILOG-邊緣檢測
評論
共有 條評論