Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 12 Mar 2012
Offline Last Active May 23 2012 10:01 AM

Topics I've Started

[FFMPEG] Play a video with many streams

22 May 2012 - 09:28 AM


I'm actually playing a MPEG video in C++ using ffmpeg. However, there is several video stream.

In my test video there is 4 videos streams with ids : 0, 16, 33, 49 and no audio stream. But formatContext->streams[i] give me only 2 streams : a video stream with PID 33 and an audio stream with PID 49 whereas there should be 4 videos streams ! It's the same with VLC (in the console we can see the 4 pids but there is only one video stream and one audio stream).

I'm sure my video contains 4 videos streams identified by these PID. I don't find how to get them with ffmpeg.

Is somebody have any idea ?

FFMPEG and av_open_input_stream

13 March 2012 - 12:06 PM


I try to read a mpeg2 video from a stream with ffmpeg library. In my first tests, I tried to read from a byte buffer, but now I read directly from a file (in my ReadPacket function) in order to be sure it's right data.
I tried many way to do that, but av_open_input_stream function return always -1.
I post my code here and hope someone could help me ! If someone have a full code to do that, i''ll be happy to see it. Thanks.


pFormatCtx = avformat_alloc_context();
if (!pFormatCtx)
return -1;

FILE* f = fopen("D:\\projets\\test_data\\video\\video_ts.mpg", "rb");

int bioBufferSize = 8000;
unsigned char *bioBuffer = (unsigned char *)av_malloc(bioBufferSize +  FF_INPUT_BUFFER_PADDING_SIZE);
ByteIOContext *bioContext = new ByteIOContext();
int ret = init_put_byte(bioContext, bioBuffer, bioBufferSize, 0, (void *)f, readPackets, NULL, seekPackets);

AVFormatParameters params, *ap = &params;
memset(ap, 0, sizeof(*ap));
ap->prealloced_context = 1

//pFormatCtx->video_codec_id = findCodecOrDie("mpeg2video", AVMEDIA_TYPE_VIDEO, 0, avcodecOpts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
//pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
AVInputFormat *inputFormat = av_find_input_format("mpegts");
//pFormatCtx->iformat = inputFormat;

ret = av_open_input_stream(&pFormatCtx, bioContext, "stream", inputFormat, ap);

delete bioContext;


And my readPacket func :

static int readPackets(void *opaque, uint8_t *buf, int buf_size)
	FILE* f = (FILE *)opaque;
	int read = fread(buf, 1, buf_size, f);
	return read;

DirectX (in C# with SlimDX) and ffmepg

12 March 2012 - 08:43 AM


I have a C++ DLL which uses ffmepg to read a video. When it gets a picture, I transmit AVFrame (and put it to RGB24 format with sws_scale) to C# code thanks to a callback.
I try to display this picture with DirectX (Texture texture = Texture.FromMemory(..) ). When I convert the AVFrame to bmp, it's working but the image loses alpha canal. I would like use directly AVFrame->data[0] but DirectX do not know how manage it !

Is someone knowning how to display an AVFrame in DirectX ?
I would like to display keyframe and the others frame.