Hi,
I also tried using the avcodec_decode_video2 function for decoding(taken fom
api-exaple.c) and encountered the following errors for wmv and mp4:
MP4
Stream info retrieval success
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Vid2.mp4':
Metadata:
major_brand : FACE
minor_version : 1337
compatible_brands: isomavc1FACE
Duration: 00:04:15.60, start: 0.000000, bitrate: 391 kb/s
Stream #0.0(und): Video: h264, yuv420p, 352x262 [PAR 151:152 DAR
3322:2489], 295 kb/s, PAR 349:352 DAR 349:262, 25 fps, 25 tbr, 25k tbn, 50
tbc
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 93 kb/s
Video Stream found
[h264 @ 0x8796480]AVC: nal size 1836019574
[h264 @ 0x8796480]no frame!
Error while decoding frame
WMV
[wmv3 @ 0x80ac9b0]Extra data: 8 bits left, value: 0
Stream info retrieval success
Input #0, asf, from 'Vid1.wmv':
Metadata:
title :
author :
copyright :
comment :
WMFSDKVersion : 12.0.7600.16385
WMFSDKNeeded : 0.0.0.0000
IsVBR : 1
VBR Peak : 116
Buffer Average : 521
Duration: 00:24:42.26, start: 5.000000, bitrate: 6084 kb/s
Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 235 kb/s
Stream #0.1: Video: wmv3, yuv420p, 1440x1080, 29.97 tbr, 1k tbn, 1k tbc
Video Stream found
[wmv3 @ 0x80ac9b0]Extra data: 8 bits left, value: 0
[wmv3 @ 0x80ac9b0]warning: first frame is no keyframe
[wmv3 @ 0x80ac9b0]Bits overconsumption: 32774 > 32768 at 50x41
[wmv3 @ 0x80ac9b0]concealing 2379 DC, 2379 AC, 2379 MV errors
saving frame
Error while decoding frame
The code i used is given below:
#include<stdio.h>
#include<stdlib.h>
#include "libavutil/fifo.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libavfilter/avfilter.h"
#include "libavcodec/avcodec.h"
#include<sys/stat.h>
#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096
int main(int argc, char *argv[])
{
av_register_all();
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVPacket pkt;
AVFrame *picture;
AVStream *instream;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
char buf[1024];
FILE *f;
//Open file / Stream
if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
{
printf("Stream open failed\n");
return -1;
}
//Retrieve stream info
if(av_find_stream_info(pFormatCtx)<0)
{
printf("Stream info retrieval failed\n");
return -1;
}
int i = 0,error,frameFinished,len;
printf("Stream info retrieval success\n");
dump_format(pFormatCtx,0,argv[1],0);
int videoStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
{
instream = pFormatCtx->streams [i];
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
{
pCodecCtx = pFormatCtx->streams[i]->codec;
videoStream=i;
pCodec=avcodec_find_decoder(pFormatCtx->streams[i]->codec->codec_id);
if(pCodec==NULL)
{
printf("Unsupported codec!\n");
return -1; // Codec not found
}
break;
}
}
if(videoStream==-1)
{
printf(" Video Stream Absent\n");
return -1; // Didn't find a video stream
}
printf("Video Stream found\n");
// Open codec
if(avcodec_open(instream->codec, pCodec)<0)
{
printf("Codec open failed\n");
return -1; // Could not open codec
}
//Allocate video frame
picture=avcodec_alloc_frame();
av_init_packet(&pkt);
f = fopen(argv[1], "rb");
if (!f) {
fprintf(stderr, "could not open %s\n", argv[1]);
exit(1);
}
for(;;) {
pkt.size = fread(inbuf, 1, INBUF_SIZE, f);
if (pkt.size == 0)
break;
pkt.data = inbuf;
while (pkt.size > 0) {
len = avcodec_decode_video2(instream->codec, picture,
&frameFinished, &pkt);
if (len < 0) {
fprintf(stderr, "Error while decoding frame\n");
exit(1);
}
if (frameFinished) {
printf("saving frame\n");
fflush(stdout);
}
pkt.size -= len;
pkt.data += len;
}
}
}
Kindly let me know what I am doing wrong here.
On Thu, Feb 24, 2011 at 3:13 PM, John Doe <[email protected]> wrote:
> Hi,
>
> I have written a simple program based on the api-example.c file in ffmpeg
> and drangers tutorial to capture video frames from various video files. I am
> facing different issues while decoding various file formats. I am new to
> ffmpeg. I have gone through drangers tutorial and api-example.c in
> libavcodec. But I am unable to find a reason for this peculiar behaviour.
> Kindly let me knwo what i am to do here.
>
> In case of wmv, it captures two frames and then returns and error in
> decoding.
> This is the log i get after running the program
>
> [wmv3 @ 0x86739b0]Extra data: 8 bits left, value: 0
> Stream info retrieval success
> Input #0, asf, from 'Vid1.wmv':
> Metadata:
> title :
> author :
> copyright :
> comment :
> WMFSDKVersion : 12.0.7600.16385
> WMFSDKNeeded : 0.0.0.0000
> IsVBR : 1
> VBR Peak : 116
> Buffer Average : 521
> Duration: 00:24:42.26, start: 5.000000, bitrate: 6084 kb/s
> Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 235 kb/s
> Stream #0.1: Video: wmv3, yuv420p, 1440x1080, 29.97 tbr, 1k tbn, 1k tbc
> Video Stream found
> [wmv3 @ 0x86739b0]Extra data: 8 bits left, value: 0
> Start transcoding
> Reading from video Stream with packet size : 50810
> Frame Captured
> Reading from video Stream with packet size : 11889
> Error in decoding
>
> In case of an mp4 file , av_read_frame is failing altogether.This is the
> error log:
> Note: the x264 library has been comppiled and ffmpeg has been configured
> with x264 library.
>
>
> Stream info retrieval success
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Vid2.mp4':
> Metadata:
> major_brand : FACE
> minor_version : 1337
> compatible_brands: isomavc1FACE
> Duration: 00:04:15.60, start: 0.000000, bitrate: 391 kb/s
> Stream #0.0(und): Video: h264, yuv420p, 352x262 [PAR 151:152 DAR
> 3322:2489], 295 kb/s, PAR 349:352 DAR 349:262, 25 fps, 25 tbr, 25k tbn, 50
> tbc
> Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 93 kb/s
> Video Stream found
> Start transcoding
> Stream over
>
> This code however captures and decodes all the frames from an MPEG-TS
> stream that is streamed using vlc player when the url of the stream is given
> an input argument.
>
> This is my code: Can you tell me what I am missing?
> #include<stdio.h>
> #include<stdlib.h>
> #include "libavutil/fifo.h"
> #include "libavformat/avformat.h"
> #include "libavutil/avutil.h"
> #include "libavfilter/avfilter.h"
> #include "libavcodec/avcodec.h"
> #include<sys/stat.h>
>
>
> int main(int argc, char *argv[])
> {
> av_register_all();
>
> AVFormatContext *pFormatCtx;
> AVCodecContext *pCodecCtx;
> AVCodec *pCodec;
> AVPacket pkt;
> AVFrame *pFrame;
> AVStream *instream;
>
> //Open file / Stream
> if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
> {
> printf("Stream open failed\n");
> return -1;
> }
> //Retrieve stream info
> if(av_find_stream_info(pFormatCtx)<0)
> {
> printf("Stream info retrieval failed\n");
> return -1;
> }
>
> int i = 0,error,frameFinished;
> printf("Stream info retrieval success\n");
> dump_format(pFormatCtx,0,argv[1],0);
> int videoStream=-1;
> for(i=0; i<pFormatCtx->nb_streams; i++)
> {
> instream = pFormatCtx->streams [i];
> if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
> {
> pCodecCtx = pFormatCtx->streams[i]->codec;
> videoStream=i;
>
> pCodec=avcodec_find_decoder(pFormatCtx->streams[i]->codec->codec_id);
> if(pCodec==NULL)
> {
> printf("Unsupported codec!\n");
> return -1; // Codec not found
> }
> break;
> }
> }
> if(videoStream==-1)
> {
> printf(" Video Stream Absent\n");
> return -1; // Didn't find a video stream
> }
> printf("Video Stream found\n");
>
> // Open codec
> if(avcodec_open(instream->codec, pCodec)<0)
> {
> printf("Codec open failed\n");
> return -1; // Could not open codec
> }
>
>
> //Allocate video frame
> pFrame=avcodec_alloc_frame();
> av_init_packet(&pkt);
>
> printf("Start transcoding\n");
> while(av_read_frame (pFormatCtx, &pkt)>=0)
> {
> if(pkt.stream_index = videoStream)
> {
> printf("Reading from video Stream with packet size :
> %d\n",pkt.size);
> error = avcodec_decode_video(pCodecCtx, pFrame,
> &frameFinished, pkt.data, pkt.size);
>
> if(error < 0)
> {
> printf("Error in decoding\n");
> return -1;
> }
> if(frameFinished)
> {
> printf("Frame Captured\n");
>
> }
> av_init_packet(&pkt);
> }
> }
> printf("Stream over\n");
> }
>
>
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user