Re: [Libav-user] How to generate an index image files?

2013-02-01 Thread Malik Cissé

Hi,

I have written an Mpeg-TS H.264 and AAC muxer.
H.264 plays fine but AAC audio demuxing fails using FFMPEG (other players like 
WMP work).
I receive "PES packet size mismatch" warning and the demuxed aac is corrupted.
Here is the Mpeg Transport Stream file:
ftp://public:enci...@ftp.enciris.com/output_mpegTs.ts
Any idea what is wrong? 
Malik
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] get RGB values from ffmpeg frame

2012-11-21 Thread Malik Cissé

Carl Eugen ... writes:
>...compile FFmpeg with msvc.
This sounds interesting. Where can I find msvc sample project?

Malik Cisse
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] ffmpeg H.264 decoding

2012-11-20 Thread Malik Cissé
Carl Eugen, Thanks for the info. This is what I wanted to know.

-Original Message-
From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On 
Behalf Of Carl Eugen Hoyos
Sent: 20 November 2012 11:12
To: libav-user@ffmpeg.org
Subject: Re: [Libav-user] ffmpeg H.264 decoding

Malik Cissé  writes:

> My question:
> The decoding goes very fast and CPU usage is low.
> Can I guaranty same performance on similar CPU’s?

I may misunderstand the question, but decoding is a deterministic process (if 
that is what you want to know).
General system load and other factors that are very difficult to foresee in 
real life of course affect decoding speed.

> Is any Hardware acceleration (mmx, GPU, DXVA, etc) used to decode the 
> frames?

SIMD (mmx) optimizations are hopefully used on CPUs that support it, hardware 
decoding is only used if you explicitly requested it.

Carl Eugen

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] get RGB values from ffmpeg frame

2012-11-20 Thread Malik Cissé
Navin, 
> Macros and datatypes like LT_SUCCESS, MAX_FR_SZ, metaD_t, LtHandle, 
> ASF_IDX_SZ etc. seem new. Am a bit puzzled.
The code is taken from a proprietary stuff and I did not want to disclose 
everything but the main idea is there.


-Original Message-
From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On 
Behalf Of Navin
Sent: 20 November 2012 12:39
To: libav-user@ffmpeg.org
Subject: Re: [Libav-user] get RGB values from ffmpeg frame

Actually, Malik; the idea was not to use the ffmpeg.exe. I wanted the 
bitmap/RGB values to be stored in memory (a datastructure) in my program and 
then I'd pass the pointer of the datastructure to a client program which is 
running at the same time. The client program would then take the info from the 
datastructure and use it to display the video frame.
Thanks for the code you posted. Macros and datatypes like LT_SUCCESS, 
MAX_FR_SZ, metaD_t, LtHandle, ASF_IDX_SZ etc. seem new. Am a bit puzzled.

Navin

On 11/20/2012 5:00 PM, Malik Cissé wrote:
> Hi Navin,
>
> Also YUV4:2:0 in BMP does not seem feasible (sorry for my previous statement).
> One think you can do too is use ffmpeg in a system call in your code.
> This is very versatile (you need to replace 422 by 420 though) char 
> ffmpegString[256];//should be plenty
>   char fmt[] = "bmp"; //bmp, jpg, png, pgm etc...
>   sprintf(ffmpegString, "ffmpeg.exe -s %dx%d -vcodec rawvideo -f rawvideo 
> -pix_fmt uyvy422 -i raw_uyvy422.yuv -f image2 raw_uyvy422.%s",RawWidth, 
> RawHeight, fmt);
>   system(ffmpegString);
>
> Malik Cisse
>
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] get RGB values from ffmpeg frame

2012-11-20 Thread Malik Cissé
Hi Navin,

Also YUV4:2:0 in BMP does not seem feasible (sorry for my previous statement).
One think you can do too is use ffmpeg in a system call in your code.
This is very versatile (you need to replace 422 by 420 though)
char ffmpegString[256];//should be plenty
char fmt[] = "bmp"; //bmp, jpg, png, pgm etc...
sprintf(ffmpegString, "ffmpeg.exe -s %dx%d -vcodec rawvideo -f rawvideo 
-pix_fmt uyvy422 -i raw_uyvy422.yuv -f image2 raw_uyvy422.%s",RawWidth, 
RawHeight, fmt); 
system(ffmpegString);

Malik Cisse


-Original Message-
From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On 
Behalf Of Navin
Sent: 20 November 2012 12:09
To: libav-user@ffmpeg.org
Subject: Re: [Libav-user] get RGB values from ffmpeg frame

Hey thanks everyone! Still trying/struggling with the code sent by Malik 
because avcodec_decode_video is deprecated.
Thought I'd post the entire code here for anyone who could help or for anyone 
who needs such code in future. This is the corrected version of ffmpeg's 
tutorial02, with SDL added to it too.
Problems are:
1. Since I was facing trouble with RGB, I thought I'd use SDL to output the 
frames as bitmaps, but although I could store the bitmap in an area in memory, 
it threw an exception when I tried extracting it out of memory.
2. Besides, when at least trying to output the bitmap to hard disk, I'm unable 
to output it unless SDL_DisplayYUVOverlay(bmp, &rect); is called (and I don't 
want to call it because I don't want the video to be displayed. I just want the 
bitmap to be output).
3. Main problem is still with extracting RGB, so would be grateful for any 
help. If not RGB, then at least with question 1 (how to store and extract the 
BMP from SDL memory).

The code:

extern "C"
{
#include 
#include 
#include 
}
#include
#include 
#include 
#include "SDL_opengl.h"
#include 
#include 

//#ifdef __MINGW32__
#undef main /* Prevents SDL from overriding main() */
//#endif

#include 



//
// These functions should not be used except from pointers in a RWops
static int myseekfunc(SDL_RWops *context, int offset, int whence) { 
SDL_SetError("Can't seek in this kind of RWops"); return(-1); }
static int myreadfunc(SDL_RWops *context, void *ptr, int size, int 
maxnum) { memset(ptr,0,size*maxnum); return(maxnum); }
static int mywritefunc(SDL_RWops *context, const void *ptr, int size, 
int num) { return(num); }
static int myclosefunc(SDL_RWops *context)
{
   if(context->type != 0xdeadbeef) { SDL_SetError("Wrong kind of RWops 
for myclosefunc()"); return(-1); }
   free(context->hidden.unknown.data1);
   SDL_FreeRW(context);
   return(0);
}

// Note that this function is NOT static -- we want it directly callable 
from other source files
SDL_RWops *MyCustomRWop()
{
   SDL_RWops *c=SDL_AllocRW();
   if(c==NULL) return(NULL);

   c->seek =myseekfunc;
   c->read =myreadfunc;
   c->write=mywritefunc;
   c->close=myclosefunc;
   c->type =0xdeadbeef;
   printf("deadbeef=%d\n",c->type);
   c->hidden.unknown.data1=malloc(10);
   return(c);
}


int main(int argc, char *argv[])
{
   AVFormatContext *pFormatCtx = NULL;
   int i, videoStream;
   AVCodecContext  *pCodecCtx = NULL;
   AVCodec *pCodec = NULL;
   AVFrame *pFrame = NULL;
   AVPacketpacket;
   int frameFinished;
   //float   aspect_ratio;

   AVDictionary*optionsDict = NULL;
   struct SwsContext *sws_ctx = NULL;

   SDL_Overlay *bmp = NULL;
   SDL_Surface *screen = NULL;
   SDL_Surface *screen2 = NULL;
   SDL_Surface *rgbscreen = NULL;
   SDL_Rectrect;
   SDL_Event   event;


   if(argc < 2) { fprintf(stderr, "Usage: test.exe \n"); 
exit(1); }
   // Register all formats and codecs
   av_register_all();

   if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {  
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());   
exit(1); }

   // Open video file
   if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
return -1; // Couldn't open file

   // Retrieve stream information
   if(avformat_find_stream_info(pFormatCtx, NULL)<0)return -1; // 
Couldn't find stream information

   // Dump information about file onto standard error
   //av_dump_format(pFormatCtx, 0, argv[1], 0);

   // Find the first video stream
   videoStream=-1;
   for(i=0; inb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) { 
videoStream=i;  break; }
   if(videoStream==-1)return -1; // Didn't find a video stream

   // Get a pointer to the codec context for the video stream
   pCodecCtx=pFormatCtx->streams[videoStream]->codec;

   // Find the decoder for the video stream
   pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
   if(pCodec==NULL) {fprintf(stderr, "Unsupported codec!\n");
return -1;} // Codec not found

   // Open codec
   if(avcodec_open2(pCodecCtx, pCodec, &optionsDict) < 0)return -1; 
// Could not open codec

   // A

Re: [Libav-user] get RGB values from ffmpeg frame

2012-11-20 Thread Malik Cissé
Hi Navin,
Here is an example with SDL and avcodec_decode_video2 (which is not deprecated).

int main(int argc, char **argv)
{
AVCodec *codec;
AVCodecContext *c= NULL;
int got_picture, len;
AVFrame *picture;
int out_size_y;
int out_size_cr;
AVPacket pkt;
int result;
unsigned char *pIdxBuffer;
int IdxBufferSize;
int IdxByteTransfered;
unsigned char *pHdrBuffer;
int HdrBufferSize;
int HdrByteTransfered;
unsigned long long  fileSize;
FILE*pFileAsf;
int isFirstTime = 1;
int Status = LT_SUCCESS;
int FrameType = 0;
int LoopCnt = 0;
metaD_t metaD;
unsigned char *pVidData = (unsigned char *)malloc(MAX_FR_SZ);
int vidBytesXfered  = 0;
unsigned char *pAudData = (unsigned char *)malloc(MAX_FR_SZ);
int audBytesXfered  = 0;
int noSamples;//number of audio samples
unsigned char *pAsfData = (unsigned char *)malloc(MAX_FR_SZ);
int asfBytesXfered  = 0;
charbaseName[50] = "output_asf";
charfileName[50];
charstrNumber[20];
charstrHdr[5] = ".asf";
FILE *outfile = fopen("test_720x480.yuv", "wb");//output decompressed 
file
FILE *outfile1 = fopen("test_720x480.h264", "wb");//output decompressed 
file
int i,j;
//### sdl stuff 
SDL_Surface *screen;
SDL_Overlay *bmp;
SDL_Rect   rect;
bool running;
SDL_Event   event;
BOOLtoggle = 1;

printf("Video decoding\n");

//init
init_user_data(&metaD);

LtHandle  = 0;
pIdxBuffer= (unsigned char *)malloc(ASF_IDX_SZ);
IdxBufferSize = ASF_IDX_SZ;
pHdrBuffer= (unsigned char *)malloc(metaD.asf_packet_size);
HdrBufferSize = metaD.asf_packet_size;

//init board
//code has been removed...

//out_size_y = metaD.vc1_width * metaD.vc1_height;
//out_size_cr = (metaD.vc1_width * metaD.vc1_height)/4;

get_hdr_info(&metaD);

result = init_ffmpeg_lib();
if(result < 0)
{
fprintf(stderr, "Error while initializing FFMPEG lib\n");
exit(1);
}

/* find the video decoder */
if(IS_H264)
{
codec = avcodec_find_decoder(CODEC_ID_H264);
}
else
{
codec = avcodec_find_decoder(CODEC_ID_VC1);
}
if (!codec)
{
fprintf(stderr, "codec not found\n");
exit(1);
}

c= avcodec_alloc_context();

//###

//###


picture= (AVFrame *)avcodec_alloc_frame();


//h264
if(IS_H264)
{
//c->extradata  = extra;
//c->extradata_size = 14;
}
else
{
//vc1
//this is important
c->width  = metaD.vc1_width;
c->height = metaD.vc1_height;
c->extradata  = metaD.pTopLevelHeader;
c->extradata_size = metaD.codec_data_len;
}

/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}

if (!outfile)
{
av_free(c);
exit(1);
}

// SDL stuff 
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
fprintf(stderr, "Could not initialize SDL - %s\n", 
SDL_GetError());
exit(1);
}
screen = SDL_SetVideoMode(metaD.vc1_width, metaD.vc1_height, 0, 0);
if(!screen)
{
fprintf(stderr, "SDL: could not set video mode - exiting\n");
exit(1);
}

// Allocate a place to put our YUV image on that screen
bmp = SDL_CreateYUVOverlay(metaD.vc1_width,
metaD.vc1_height,
SDL_YV12_OVERLAY,
screen);
// end SDL stuff 

LT_StartVc1(LtHandle);
running = TRUE;
while(running)//audio video fetch loop
{
printf("LoopCnt: %d\r", LoopCnt++);

Status = LT_GetVc1Frame(LtHandle, pVidData, MAX_FR_SZ, 
&vidBytesXfered, &FrameType);
if( Status < 0 ) // is an error occured ?
{
printf("Vc1 fetch error\n");
LT_GetError(Status);
return Status;
}
fwrite(pVidDat

Re: [Libav-user] ffmpeg H.264 decoding

2012-11-20 Thread Malik Cissé
Carl Eugen Hoyos  writes:
Malik Cissé  writes:

>SIMD (mmx) optimizations are hopefully used on CPUs that support it, hardware 
>decoding is only >used if you explicitly requested it.
This is what I wanted to know.
How can I force hw decoding? Is there any good example code for this?

Thanks, Malik Cisse
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] get RGB values from ffmpeg frame

2012-11-20 Thread Malik Cissé
Hi Navin,

You don't need RGB for bitmap. AFAIK BMP pictures can also embed YUV4:2:0
Here is a h264 decoding code that works fine. It may help you extracting the 
right parts.




//#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "avcodec/avcodec.h"

static int FindStartCode (unsigned char *Buf, int zeros_in_startcode)
{
  int info;
  int i;

  info = 1;
  for (i = 0; i < zeros_in_startcode; i++)
if(Buf[i] != 0)
  info = 0;

  if(Buf[i] != 1)
info = 0;
  return info;
}

int getNextNal(FILE* inpf, unsigned char* Buf)
{
int pos = 0;
while(!feof(inpf) && (Buf[pos++]=fgetc(inpf))==0);

int StartCodeFound = 0;
int info2 = 0;
int info3 = 0;

while (!StartCodeFound)
{
if (feof (inpf))
{
return -1;
}
Buf[pos++] = fgetc (inpf);
info3 = FindStartCode(&Buf[pos-4], 3);
if(info3 != 1)
info2 = FindStartCode(&Buf[pos-3], 2);
StartCodeFound = (info2 == 1 || info3 == 1);
}
fseek (inpf, -4, SEEK_CUR);
return pos - 4;
}

int main()
{
int i;
FILE * inpf;
FILE * outf;
inpf = fopen("test.264", "rb");
outf = fopen("out1_720x576.yuv", "wb");
int nalLen = 0;
unsigned char* Buf = (unsigned char*)calloc ( 100, sizeof(char));
unsigned char* Buf1 = (unsigned char*)calloc ( 100, sizeof(char));
int width = 720;
int height = 576;
//unsigned char yuvData[352 * 240 * 3];


AVCodec *codec;   // Codec
AVCodecContext *c;// Codec Context
AVFrame *picture; // Frame  

avcodec_init(); 
avcodec_register_all(); 
codec = avcodec_find_decoder(CODEC_ID_H264);

if (!codec)  {
return 0; 
} 
//allocate codec context
c = avcodec_alloc_context(); 
if(!c){
return 0;
}
//open codec
if (avcodec_open(c, codec) < 0) {
return 0; 
} 

//allocate frame buffer
picture   = avcodec_alloc_frame();
if(!picture){
return 0;
}

while(!feof(inpf))
{
//printf("cntr: %d\n", cntr++);
nalLen = getNextNal(inpf, Buf);

//try to decode this frame
int  got_picture, result; 
result= avcodec_decode_video(c, picture, &got_picture, Buf, 
nalLen); 
if(result > 0)
{
//fwrite(picture->data[0],1,width*height,outf);
//fwrite(picture->data[1],1,width*height/4,outf);
//fwrite(picture->data[2],1,width*height/4,outf);

#if 0 //this is also ok!
for(i=0; iheight; i++)
fwrite(picture->data[0] + i * 
picture->linesize[0], 1, c->width, outf );
for(i=0; iheight/2; i++)
fwrite(picture->data[1] + i * 
picture->linesize[1], 1, c->width/2, outf );
for(i=0; iheight/2; i++)
fwrite(picture->data[2] + i * 
picture->linesize[2], 1, c->width/2, outf );
#endif 


//http://ffmpeg.org/doxygen/trunk/group__lavc__picture.html#g99bc554a84681f7ee6422a384007a4ca
//Copy pixel data from an AVPicture into a buffer, 
always assume a linesize alignment of 1.
avpicture_layout((AVPicture *)picture, c->pix_fmt, 
c->width, c->height, Buf1, c->width*c->height*1.5);
fwrite(Buf1, c->width*c->height*1.5, 1, outf);

}
}

if(c) {
avcodec_close(c); 
av_free(c);
c = NULL;
} 
if(picture) {
av_free(picture);
picture = NULL;
} 
return 1;
}
Malik,


-Original Message-
From: libav-user-boun...@ffmpeg.org [mailto:libav-user-boun...@ffmpeg.org] On 
Behalf Of Navin
Sent: 20 November 2012 09:49
To: libav-user@ffmpeg.org
Subject: Re: [Libav-user] get RGB values from ffmpeg frame

Been trying these techniques, but I keep getting crashes. Help please?:

 avpicture_fill((AVPicture*) frame2, frame2_buffer, PIX_FMT_RGB24, 
width2, height2);
 //printf("data = %d, %d, %d, %d 
\n",frame2->data[0],frame2->data[1],frame2->data[2],frame2->data[3]);
 //printf("linesize = %d %d %d\n",frame2->linesize[0], 
frame2->linesize[1], frame2->linesize[2]);
 //printf("width = %d\n", pCodecCtx->width);
 //printf("height = %d\n", pCodecCtx->height);
 //std::cin.get();

 int linesize = frame2->linesize[0];
 for(int xx = 0; xx < (lines

[Libav-user] ffmpeg H.264 decoding

2012-11-19 Thread Malik Cissé

Hi,

I managed to get an ffmpeg based H.264 elementary stream decoder work.
It uses following synthax to decode one frame:
...
codec = avcodec_find_decoder(CODEC_ID_H264);
..
len = avcodec_decode_video2(c, picture, &got_picture, &pkt);

My question:
The decoding goes very fast and CPU usage is low.
Can I guaranty same performance on similar CPU's?
Is any Hardware acceleration (mmx, GPU, DXVA, etc) used to decode the frames?
What is done behind the scene? Is there any buffering?
Thanks,

Malik

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user