- 论坛徽章:
- 0
|
下面的代码借鉴了论坛里朋友写的程序,如下所示:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "ffmpeg/avformat.h"
#include "ffmpeg/swscale.h"
int KEY=0xDF;
int main(int argc, char **argv)
{
char *filename;
AVFormatContext *ic;
AVPacket *pkt;
av_register_all();
if (argc != 2) {
printf("usage: %s output_file\n"
"API example program to output a media file with libavformat.\n"
"The output format is automatically guessed according to the file extension.\n"
"Raw images can also be output by using '%%d' in the filename\n"
"\n", argv[0]);
exit(1);
}
filename = argv[1];
ic=av_alloc_format_context();
if(av_open_input_file(&ic,filename,NULL,0,NULL)!=0)
{ printf("cannot open the file %s\n",filename);
exit(1);
}
if (av_find_stream_info(ic)<0)
{
printf("can't find suitable codec parameters\n");
exit(1);
}
dump_format(ic,0,filename,0);
int i;
int videoindex=-1;
for(i=0;i<ic->nb_streams;i++)
{ if (ic->streams->codec->codec_type==CODEC_TYPE_VIDEO)
{
videoindex=i;
break;
}
}
if (videoindex==-1)
{ printf("cna't find video stream\n");
exit(1);
}
AVCodecContext *vCodecCtx;
vCodecCtx=ic->streams[videoindex]->codec;
AVCodec *vCodec;
vCodec=avcodec_find_decoder(vCodecCtx->codec_id);
if(vCodec==NULL)
{
printf("can't find suitable video decoder\n");
exit(1);
}
if(avcodec_open(vCodecCtx,vCodec)<0)
{
printf("can't open the video decoder\n");
exit(1);
}
int flag_endfile=1;
while(flag_endfile)
{
if (av_read_frame(ic,pkt)<0)
{flag_endfile=0;}
else {
int i=0;
for(i=0;i<4;i++)
pkt->data=pkt->data^KEY;
}
}
printf("Success!\n");
}
[ |
|