Re: [Libav-user] How to generate an index image files?
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
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] get RGB values from ffmpeg frame
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; ic-height; i++) fwrite(picture-data[0] + i * picture-linesize[0], 1, c-width, outf ); for(i=0; ic-height/2; i++) fwrite(picture-data[1] + i * picture-linesize[1], 1, c-width/2, outf ); for(i=0; ic-height/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 (linesize * width1)-1; xx += 3) { int r =
Re: [Libav-user] get RGB values from ffmpeg frame
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(pVidData, sizeof(char), vidBytesXfered,
Re: [Libav-user] get RGB values from ffmpeg frame
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] ffmpeg H.264 decoding
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é mc@... 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
[Libav-user] ffmpeg H.264 decoding
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