AVCODEC_OPEN and AVCODEC_ENCODE_VIDEO fails...
-
Hi all, I am working on transcoding using ffmeg.Im having the mpeg4 video and alaw audio which should be converted to the desired video and audio format.Im reading the frame by frame conversion from my media stream using av_read_frame(...)
int main(int argc, char **argv)
{
const char *filename;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVFormatContext *ic;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVStream *audio_st, *video_st;
int i,frame,video_stream;// initialize libavcodec, and register all codecs and formats av\_register\_all(); filename = "test.mp4"; if(av\_open\_input\_file(&ic, filename, NULL, 0, NULL)!=0) return -1; // Couldn't open file // Retrieve stream information if(av\_find\_stream\_info(ic)<0) return -1; // Couldn't find stream information // Find the first video stream video\_stream=-1; for(i=0; i<10; i++) if(ic->streams\[i\]->codec->codec\_type==CODEC\_TYPE\_VIDEO) { video\_stream=i; break; } if(video\_stream==-1) return -1; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=ic->streams\[video\_stream\]->codec; // Find the decoder for the video stream pCodec=avcodec\_find\_decoder(pCodecCtx->codec\_id); if(pCodec==NULL) return -1; // Codec not found // Open codec if(avcodec\_open(pCodecCtx, pCodec)<0) return -1; // Could not open codec // Allocate frames AVPacket pkt; AVFrame videoFrame; // auto detect the output format from the name. default is mpeg. fmt = guess\_format(NULL, filename, NULL); if (!fmt) { printf("Could not deduce output format from file extension: using MPEG.\\n"); fmt = guess\_format("mpeg", NULL, NULL); } if (!fmt) { fprintf(stderr, "Could not find suitable output format\\n"); exit(1); } /\* allocate the output media context \*/ oc = av\_alloc\_format\_context(); if (!oc) { fprintf(stderr, "Memory error\\n"); exit(1); } oc->oformat = fmt; \_snprintf(oc->filename, sizeof(oc->filename), "%s", filename); // Add video stream AVStream\* stream = av\_new\_stream(oc, 0); AVCodecContext\* videoEncoderContext = stream->codec; setupVideoEncode(videoEncoderContext); stream->sample\_aspect\_ratio = av\_d2q(1, 255); stream->pts\_wrap\_bits = 33; stream->codec->thread\_count = 0; // Set output parameters if (av\_set
-
Hi all, I am working on transcoding using ffmeg.Im having the mpeg4 video and alaw audio which should be converted to the desired video and audio format.Im reading the frame by frame conversion from my media stream using av_read_frame(...)
int main(int argc, char **argv)
{
const char *filename;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVFormatContext *ic;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVStream *audio_st, *video_st;
int i,frame,video_stream;// initialize libavcodec, and register all codecs and formats av\_register\_all(); filename = "test.mp4"; if(av\_open\_input\_file(&ic, filename, NULL, 0, NULL)!=0) return -1; // Couldn't open file // Retrieve stream information if(av\_find\_stream\_info(ic)<0) return -1; // Couldn't find stream information // Find the first video stream video\_stream=-1; for(i=0; i<10; i++) if(ic->streams\[i\]->codec->codec\_type==CODEC\_TYPE\_VIDEO) { video\_stream=i; break; } if(video\_stream==-1) return -1; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=ic->streams\[video\_stream\]->codec; // Find the decoder for the video stream pCodec=avcodec\_find\_decoder(pCodecCtx->codec\_id); if(pCodec==NULL) return -1; // Codec not found // Open codec if(avcodec\_open(pCodecCtx, pCodec)<0) return -1; // Could not open codec // Allocate frames AVPacket pkt; AVFrame videoFrame; // auto detect the output format from the name. default is mpeg. fmt = guess\_format(NULL, filename, NULL); if (!fmt) { printf("Could not deduce output format from file extension: using MPEG.\\n"); fmt = guess\_format("mpeg", NULL, NULL); } if (!fmt) { fprintf(stderr, "Could not find suitable output format\\n"); exit(1); } /\* allocate the output media context \*/ oc = av\_alloc\_format\_context(); if (!oc) { fprintf(stderr, "Memory error\\n"); exit(1); } oc->oformat = fmt; \_snprintf(oc->filename, sizeof(oc->filename), "%s", filename); // Add video stream AVStream\* stream = av\_new\_stream(oc, 0); AVCodecContext\* videoEncoderContext = stream->codec; setupVideoEncode(videoEncoderContext); stream->sample\_aspect\_ratio = av\_d2q(1, 255); stream->pts\_wrap\_bits = 33; stream->codec->thread\_count = 0; // Set output parameters if (av\_set