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