Jump to content
  • Advertisement
Sign in to follow this  
sp33dy

Multi format movie playing

This topic is 4014 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, My first post!! YAY. I've spent the last day googling for different movie libraries that could be used with either OpenGL or SDL on Windows XP. There are a few that standout; mplayer and Fmmpeg. I'd like to write an opengl app that places movies (especially AVI, divx, xvid, mpeg2, mpeg) into rotating cubes/texture. Having looked and played with the mplayer, it looks ideal (handles a lot of formats), but is driven either by command line or via an interactive method of calling. This would be good, but it renders directly to the screen (ie, I can see no way of grabbing frames and painting onto a texture). Has anyone written a tutorial/code that links directly to mplayer and uses its functions as I would like? I'm half tempted to learn some of the code to write my own controller (but that's a lot of code to read!). Any thoughts on this or a better alternative? I'd like to use a library that is o/s independent, but I'm willing to stick to XP (Directx) if I have to... Any response would be appreciated. Regards Sp33dy

Share this post


Link to post
Share on other sites
Advertisement
I am also interested in this topic so maybe we could work something out together?

Somewhere I found some code to render a video to a texture using ffmpeg (mplayer uses ffmpeg too I think).
I will look if I can find it and give you the link


ffmpeg
This should be a good starting point but it is only for playing videos in an sdl window (using ans YUV overlay). So you (we) have to modify this code so that it can render the video to a texture

Share this post


Link to post
Share on other sites
Hi there madRenEGadE,

Yes, I'd read that article. I've also looked at the opengl article from nehe's site:

NeHe Avi tutorial 35

I was impressed with nehe's and the ffmpeg examples. Nehe's is as close to what I want and might be the starting point. Trying to add in additional codec's to it, but that seems a lot of work. The MPlayer is truely great, astonishing compatability and very fast rendering. Why I thought it must be possible to reuse the code, but directly rather than through the command line structure. It's a shame that package doesn't provide an option to return each frame into the opengl/sdl texture that is to be wrapped by a 3d object.

Just my thoughts. Yes, I certainly am going to find sometime to hack around. If you are about, I'd appreciate any updates you find. I'll do the same here.

Regards

Sp33dy

Share this post


Link to post
Share on other sites
Here is a part of my code, you must modify and clean it up to run, but it works. Caution its for OpenGL, but DirectX should be no problem.


if(av_open_input_file(&pFormatCtx, filename.c_str(), NULL, 0, NULL)!=0)
{
MessageBox(NULL,"av_open error","Error",MB_OK); // Couldn't open file
PostQuitMessage(0);
return 0;
}

if(av_find_stream_info(pFormatCtx)<0)
{
MessageBox(NULL,"No streams","Error",MB_OK);
PostQuitMessage(0);
return 0;
}

unsigned int i;
videoStream = -1;

for(i=0; i<pFormatCtx->nb_streams; i++)
{
if(pFormatCtx->streams->codec->codec_type==CODEC_TYPE_VIDEO)
{
videoStream=i;
break;
}
if(videoStream==-1)
{
MessageBox(NULL,"No video streams","Error",MB_OK);
PostQuitMessage(0);
return 0;
}
}

pCodecCtx=pFormatCtx->streams[videoStream]->codec;

AVCodec *pCodec;

pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
MessageBox(NULL,"No codec availaible","Error",MB_OK);
PostQuitMessage(0);
return 0;
}

if(avcodec_open(pCodecCtx, pCodec)<0)
{
MessageBox(NULL,"Codec could not be opened","Error",MB_OK);
PostQuitMessage(0);
return 0;
}

pFrameRGB=avcodec_alloc_frame();
pFrame=avcodec_alloc_frame();

numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height);
buffer=new uint8_t[numBytes];

avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
pSWSCtx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);




And here how to copy it ot the texture:


if(av_read_frame(pFormatCtx, &packet)>=0)
{
if(packet.stream_index==videoStream)
{
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);

if(frameFinished)
{
//sws_scale((AVPicture *)pFrameRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
sws_scale(pSWSCtx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
}
}
}
else
curr_frame = 0;

av_free_packet(&packet);




I hope it helps a bit. If you have questions, ask.

EDIT: Oops, forgot to post the texture update function, sorry.


glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,vid->GetWidth(),vid->GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,(char*)pFrameRGB->data[0]);

Share this post


Link to post
Share on other sites
Thanks Red_falcon,

Very kind of you. I'll give it a play later. I'm tempted with either SDL or OpenGL (haven't got a concrete choice yet, although I'm aware SDL is over the top of OpenGL).

I hadn't thought of searching these here forums for ffmpeg, low and behold, another good thread:

ffmpeg on these forums

Starting to get some valid options to chase. I actually assumed ffmpeg was for mpeg only!!! Doh...

Regards

Sp33dy

Share this post


Link to post
Share on other sites
Actually not, FFMPEG supports enough other formats :)

That's why i use it for Quicktime, cause i dislike, that official QT SDK lacks of OpenGL support under Windows.

Share this post


Link to post
Share on other sites
Right,

Well based on that, FFMpeg is the choice to try.

Now the question is (probably not for here, but you obviously have an opinion). Is it better to work with OpenGL (there are a good set of NeHe tutorials) or SDL. I know SDL is another wrapper. Just wondered if it makes it easier to move to another platform. Initially I'm developing for XP, but am considering a new Linux Box too....

Regards

Sp33dy

P.S. I'm a professional Java developer/Architect. Been a while since I coded in C/C++, but it won't take me long. Hence why these basic questions are coming out. Before I invest in the time, it's nice to have opinions of others..

Share this post


Link to post
Share on other sites
I have never used any wrappers, only native OpenGL and a couple of supporting libs. But if you want it to be portable then you can try SDL or something equal. I can't speak for Linux, cause i never tried to program for it.

Share this post


Link to post
Share on other sites
Why not use SDL AND OpenGL? I want to use ffmpeg for video playback in my game engine and
so I am using sdl for window creation and event handling and opengl for rendering.
It is very easy to port to other platforms.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!