Click here to Skip to main content
16,007,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to set inlude of option? Pin
gentleguy5-Jan-08 1:39
gentleguy5-Jan-08 1:39 
GeneralRe: how to set inlude of option? Pin
CPallini5-Jan-08 4:22
mveCPallini5-Jan-08 4:22 
GeneralRe: how to set inlude of option? Pin
gentleguy5-Jan-08 1:44
gentleguy5-Jan-08 1:44 
GeneralRe: how to set inlude of option? Pin
gentleguy5-Jan-08 1:47
gentleguy5-Jan-08 1:47 
GeneralRe: how to set inlude of option? Pin
David Crow5-Jan-08 4:33
David Crow5-Jan-08 4:33 
JokeRe: how to set inlude of option? Pin
CPallini5-Jan-08 4:35
mveCPallini5-Jan-08 4:35 
GeneralRe: how to set inlude of option? Pin
gentleguy6-Jan-08 0:07
gentleguy6-Jan-08 0:07 
GeneralAVCODEC Pin
Girish Kumar4-Jan-08 22:24
Girish Kumar4-Jan-08 22:24 
Hi Friends
I Am new to this site
i got one problem regarding playback of mpeg compressed files
iam using windows mfc for this
iam receiving the file from the board via tcp protocol and iam storing in the hard disk and then calling decompression function like this
Decompression("filename.M4V");
HERE I WANT DIRECTLY WITHOUT STORING IN THE HARD DISK
IF WE WON'T GIVE EXTENSION TO FILE(LIKE .M4V,.MP4 ETC)IT IS NOT WORKING AT THE FUNCTION guess_format OF AV LIBRARY.
THE DETAILS OF THIS guess_format FUNCTION I DON'T KNOW

while i am storing the file (around 2 mb) in the buffer and calling decompression it is not working.but if you take from hard disk it is working....
pls help me


here m providing the code for reference


int Decompression(char *inputfile)
{
const char *filename;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *video_st;
double video_pts;
unsigned int i = 0;
AVFormatContext *pFormatCtx;
int videoStream = 0;
AVCodecContext *pCodecCtx;
AVFrame *pFrame;
AVCodec *pCodec;
AVPacket packet;
int frameFinished;
const char *filenamei;
AVOutputFormat *fmt1;

// initialize libavcodec, and register all codecs and formats */
av_register_all();

filename = "Girish1.YUV";
filenamei = inputfile;

// 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);
}

fmt1 = guess_format(NULL, filenamei, NULL);

if (!fmt1)
{
printf("Could not deduce input format from file extension: using MPEG.\n");
fmt1 = guess_format("mpeg", NULL, NULL);
}
if (!fmt1)
{
fprintf(stderr, "Could not find suitable input format\n");
exit(1);
}

// Open video file input

if(av_open_input_file(&pFormatCtx, filenamei, NULL, 10000, NULL)!=0)
{
printf("Couldn't open input file\n");
return NULL; // Couldn't open file
}

// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
{
printf("Couldn't find stream information\n");
return NULL; // Couldn't open file
} // Couldn't find stream information

// Dump information about file onto standard error
dump_format(pFormatCtx, 0, filenamei, false);

// Find the first video stream
videoStream=-1;
for(i=0; i < (pFormatCtx->nb_streams); i++)
if(pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO)
{
videoStream=i;
break;
}

if(videoStream==-1)
{
printf("Didn't find a video stream\n");
return NULL; // Didn't find a video stream
}

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

pCodecCtx->width = RESW;
pCodecCtx->height =RESH;

// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
printf("Codec not found\n");
return NULL; // Codec not found
}
// bitstreams where frame boundaries can fall in the middle of packets
/* if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
{
pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
}*/


// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
{
printf("Could not open codec\n");
return NULL; // Could not open codec
}


// Allocate video frame

/*pFrame = alloc_picture(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
if (!pFrame)
{
fprintf(stderr, "Could not allocate picture\n");
exit(1);
}*/


// allocate the output format 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 the video streams using the default format codecs and initialize the codecs
video_st = NULL;

if (fmt->video_codec != CODEC_ID_NONE)
{
video_st = add_video_stream(oc, fmt->video_codec);
}

// set the output parameters
if (av_set_parameters(oc, NULL) < 0)
{
fprintf(stderr, "Invalid output format parameters\n");
exit(1);
}

dump_format(oc, 0, filename, 1);

// now that all the parameters are set, we can open the video codecs and allocate the necessary encode buffers
if (video_st)
{
if(!(open_video(oc, video_st)))
{
printf("\nfailed to open videostream for output");
exit(1);
}
}


// open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE))
{
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0)
{
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
}

// write the stream header, if any
if((av_write_header(oc)) != 0)
{
printf("\nfailed to write the header");
}


for(;;k++)
{
// compute current video time
if (video_st)
{
video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
}
else
{
video_pts = 0.0;
}

pFrame = alloc_picture(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
if (!pFrame)
{
fprintf(stderr, "Could not allocate picture\n");
exit(1);
}

// write interleaved video frames */

if(av_read_frame(pFormatCtx, &packet)>=0)
{

if(packet.stream_index==videoStream)
{
// Decode video frame

avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
video_outbuf_size1 = 2000000; //by me
video_outbuf1 = (unsigned char *) av_malloc(video_outbuf_size1);
if(not_init == false)
{
not_init = true;
InitConvertTable();
}

// ConvertYUVtoYUV(320,240,(unsigned int*)pFrame,(unsigned int*)pFrame);
ConvertYUV2RGB((unsigned char*)pFrame->data[0],(unsigned char*)pFrame->data[1],(unsigned char*)pFrame->data[2],video_outbuf1,RESW,RESH);

PostMessage(g_hWnd,ON_RENDER,(unsigned long)video_outbuf1, NULL);

//Sleep(100);

// Did we get a video frame?
if(frameFinished)
{
if(!(write_video_frame(oc, video_st,pFrame,i)))
{
printf("\nfailed to write the video frame");
exit(1);
}
av_free_packet(&packet);
av_free(pFrame);
}
}

}

else
break;


}

//av_free_packet(&packet);
//av_free(pFrame);

// close each codec */
if (video_st)
{
close_video(oc, video_st);
}

// write the trailer, if any */
if((av_write_trailer(oc)) != 0)
{
printf("\nfailed to write the trailer");
}

// free the streams */
for(i = 0; i < oc->nb_streams; i++)
{
av_freep(&oc->streams[i]->codec);
av_freep(&oc->streams[i]);
}

if (!(fmt->flags & AVFMT_NOFILE))
{
// close the output file */
url_fclose(&oc->pb);
}

// free the stream */
av_free(oc);
av_free(video_outbuf1);

// Close the codec
avcodec_close(pCodecCtx);

// Close the video file
av_close_input_file(pFormatCtx);

//free(p);

return 0;
}


Girish

Girish

GeneralConvert Date to EXCEL Numeric Pin
im_hoser4-Jan-08 21:10
im_hoser4-Jan-08 21:10 
GeneralRe: Convert Date to EXCEL Numeric Pin
CPallini5-Jan-08 0:50
mveCPallini5-Jan-08 0:50 
GeneralProbelm in calling ActiveX VB dll Pin
manoharbalu4-Jan-08 19:35
manoharbalu4-Jan-08 19:35 
Generalurgent help Pin
gentleguy4-Jan-08 19:22
gentleguy4-Jan-08 19:22 
QuestionRe: urgent help Pin
CPallini4-Jan-08 23:09
mveCPallini4-Jan-08 23:09 
GeneralRe: urgent help Pin
gentleguy5-Jan-08 1:20
gentleguy5-Jan-08 1:20 
GeneralRe: urgent help Pin
Joan M5-Jan-08 2:14
professionalJoan M5-Jan-08 2:14 
QuestionProblem with using SENS and the COM Event System in VC++ Pin
ashishbhatt4-Jan-08 17:40
ashishbhatt4-Jan-08 17:40 
GeneralRe: Problem with using SENS and the COM Event System in VC++ Pin
David Crow4-Jan-08 17:50
David Crow4-Jan-08 17:50 
GeneralRe: Problem with using SENS and the COM Event System in VC++ Pin
ashishbhatt4-Jan-08 18:12
ashishbhatt4-Jan-08 18:12 
QuestionHow to get local ip address Pin
shakumar_224-Jan-08 17:18
shakumar_224-Jan-08 17:18 
AnswerRe: How to get local ip address Pin
David Crow4-Jan-08 17:46
David Crow4-Jan-08 17:46 
AnswerRe: How to get local ip address Pin
Hamid_RT4-Jan-08 18:01
Hamid_RT4-Jan-08 18:01 
Generalupgrading dbghelp.dll Pin
DevMentor.org4-Jan-08 9:20
DevMentor.org4-Jan-08 9:20 
GeneralRe: upgrading dbghelp.dll Pin
DevMentor.org4-Jan-08 9:49
DevMentor.org4-Jan-08 9:49 
QuestionText height in CRichEditCtrl Pin
DougVC4-Jan-08 7:24
DougVC4-Jan-08 7:24 
GeneralRe: Text height in CRichEditCtrl Pin
CPallini4-Jan-08 7:36
mveCPallini4-Jan-08 7:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.