Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro video addon

This thread is locked; no one can reply to it. rss feed Print
Allegro video addon
Kamil Biały
Member #15,049
April 2013
avatar

Hi!

I have a little problem ( at least I think so ), so... I have no idea how to play video with allegro video streaming addon. I try something like this.

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_audio.h> 4#include <allegro5/allegro_acodec.h> 5#include <allegro5/allegro_video.h> 6 7int main(int argc, char **argv){ 8 9 ALLEGRO_DISPLAY *display = NULL; 10 ALLEGRO_MIXER *mixer = NULL; 11 ALLEGRO_VIDEO *video = NULL; 12 ALLEGRO_BITMAP *bitmap = NULL; 13 int x = 0; 14 15 if(!al_init()) { 16 fprintf(stderr, "failed to initialize allegro!\n"); 17 return -1; 18 } 19 20 al_install_audio( ); 21 al_init_acodec_addon( ); 22 23 mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); 24 video = al_open_video("video.ogg"); 25 al_set_new_bitmap_flags( ALLEGRO_VIDEO_BITMAP ); 26 bitmap = al_create_bitmap( al_get_video_width( video ), al_get_video_height( video ) ); 27 28 display = al_create_display(al_get_video_width( video ), al_get_video_height( video )); 29 if(!display) { 30 fprintf(stderr, "failed to create display!\n"); 31 return -1; 32 } 33 34 35 al_clear_to_color(al_map_rgb(0,0,0)); 36 37 al_flip_display(); 38 al_start_video(video,mixer); 39 /* 40 for( x = 0; x < 100; ++x ) 41 { 42 bitmap = al_get_video_frame(video); 43 44 printf("%d", al_get_video_position(video, 0)); 45 } 46 */ 47 bitmap = al_get_video_frame( video ); 48 al_draw_bitmap( bitmap, 0, 0, 0 ); 49 50 al_rest( 5.0 ); 51 52 al_destroy_display(display); 53 al_destroy_mixer( mixer ); 54 al_destroy_bitmap( bitmap ); 55 al_close_video( video ); 56 57 return 0; 58}

But when i try to draw bitmap, it flush me an error to console:

#SelectExpand
1Assertion failed: bitmap, file C:\allegro\src\bitmap_draw.c, line 137 2 3This application has requested the Runtime to terminate it in an unusual way. 4Please contact the application's support team for more information. 5 6Process returned 3 (0x3) execution time : 9.499 s 7Press any key to continue.

Please, help.
I,m using allegro 5.1.6

SiegeLord
Member #7,827
October 2006
avatar

That should work, I think. Try opening the video (we really should rename it to load_video) after you create the display. Also, check to make sure your video is loaded fine (al_open_video will return NULL if not).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Kamil Biały
Member #15,049
April 2013
avatar

It doesn't work. :(
The video is opening, because it create display in video dimensions.
The problem starts when I try to get a video frame.

I try to add image addon, but it doesn't help...
:(

SiegeLord
Member #7,827
October 2006
avatar

Looks like the first couple frames are NULL for whatever reason... just trudge along until you get a non-NULL one.

Another couple of things about your code... you are leaking memory when you create the bitmap yourself... you don't need to do that, al_get_video_frame handles the bitmap it returns automatically. Along the same lines, do not call al_destroy_bitmap on the bitmap returned by al_get_video_frame. Lastly, you don't need to create a default mixer unless you really have to. You can get a default one via al_get_default_mixer(). Your mixer wasn't working anyway as you didn't attach it to a voice. Here's the fixed code if you want to try it:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_audio.h> 4#include <allegro5/allegro_video.h> 5 6int main(int argc, char** argv) 7{ 8 ALLEGRO_DISPLAY* display = NULL; 9 ALLEGRO_VIDEO* video = NULL; 10 ALLEGRO_BITMAP* bitmap = NULL; 11 int x = 0; 12 13 if(!al_init()) 14 { 15 fprintf(stderr, "failed to initialize allegro!\n"); 16 return -1; 17 } 18 19 al_install_audio(); 20 al_reserve_samples(1); 21 22 display = al_create_display(al_get_video_width(video), al_get_video_height(video)); 23 24 if(!display) 25 { 26 fprintf(stderr, "failed to create display!\n"); 27 return -1; 28 } 29 30 al_clear_to_color(al_map_rgb(0, 0, 0)); 31 al_flip_display(); 32 33 video = al_open_video("video.ogg"); 34 al_start_video(video, al_get_default_mixer()); 35 36 for(x = 0; x < 100; ++x) 37 { 38 bitmap = al_get_video_frame(video); 39 40 if(bitmap) 41 al_draw_bitmap(bitmap, 0, 0, 0); 42 else 43 printf("NULL\n"); 44 45 printf("%f\n", al_get_video_position(video, 0)); 46 al_flip_display(); 47 al_rest(0.01); 48 } 49 50 al_destroy_display(display); 51 al_close_video(video); 52 return 0; 53}

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Kamil Biały
Member #15,049
April 2013
avatar

It... works! Wow :D

Thank you for help :)

Go to: