![]() |
|
How to play video in allegro 5 |
Crisbe
Member #16,579
October 2016
|
Hello I have problem with streaming video in the newest allegro 5. I have: #include <allegro5/allegro_audio.h> int main(){ al_install_audio(); ALLEGRO_VIDEO *splash_vid = al_open_video("vid.ogv"); al_start_video(splash_vid, mixer); but after launch I have only black screen which can't be closed. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You have to monitor video events and then display a frame when you get an ALLEGRO_EVENT_VIDEO_FRAME_SHOW event. You then get the bitmap to draw with al_get_video_frame. You need to register the video event source with an ALLEGRO_EVENT_QUEUE to receive video events. Read the video section of the manual for details : You have a black screen that can't be closed because you didn't create a display. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
Now I have something like that and I created display earlier, in main fucntion: void splash_screen(void) al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); al_start_video(splash_vid, mixer); std::cout << al_is_video_playing(splash_vid); ALLEGRO_EVENT_QUEUE *vid_event_queue = al_create_event_queue(); al_register_event_source(vid_event_queue, al_get_video_event_source(splash_vid)); bool done = false; al_destroy_event_queue(vid_event_queue); and still I have black screen. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Set the drawing target to the backbuffer before drawing your bitmap and flipping the display. Also, you don't need to create a bitmap. al_get_video_frame maintains one for you. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
Still it doesn't work :/ |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Crisbe said:
Still it doesn't work :/ That's pretty vague. We need more details. Post full code of a Minimum, Complete, Verifiable Example (MCVE) that fails to play video or fails to compile correctly and then we can help you. If you video is under 10MB, post it as an attachment as well. Or upload it somewhere else so we can test it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
Ok, so this is my main function: #include "All_headers.h" ALLEGRO_TIMER *fps_timer = NULL; int main(void) al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); if (!display) //test display fps_timer = al_create_timer(1.0 / fps); //addon init splash_screen(); // destroying globall variables Splash function: #include "All_headers.h" void splash_screen(void) al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); std::cout << al_is_video_playing(splash_vid); ALLEGRO_EVENT_QUEUE *vid_event_queue = al_create_event_queue(); al_register_event_source(vid_event_queue, al_get_video_event_source(splash_vid)); al_start_video(splash_vid, mixer); bool done = false; al_destroy_event_queue(vid_event_queue); and headers: #pragma once // splash screen // global variables |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You can include code in <code>code goes here...</code> tags for easier reading and formatting. Your video is only 1.41 MB. Please upload it as an attachment. I will not be using ZippyShare to install AdWare. Thanks. EDIT My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
1void splash_screen(void)
2{
3 ALLEGRO_VIDEO *splash_vid = al_open_video("vid.ogv");
4 ALLEGRO_MIXER *mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
5
6 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
7 ALLEGRO_BITMAP *bitmap;
8
9 std::cout << al_is_video_playing(splash_vid);
10
11 ALLEGRO_EVENT_QUEUE *vid_event_queue = al_create_event_queue();
12
13 al_register_event_source(vid_event_queue, al_get_video_event_source(splash_vid));
14
15 al_start_video(splash_vid, mixer);
16
17 bool done = false;
18 while (!done)
19 {
20 ALLEGRO_EVENT vid_ev;
21 al_wait_for_event(vid_event_queue, &vid_ev);
22 if (vid_ev.type == ALLEGRO_EVENT_VIDEO_FRAME_SHOW)
23 {
24 bitmap = al_get_video_frame(splash_vid);
25 al_set_target_backbuffer(display);
26 al_draw_bitmap(bitmap, 0, 0, 0);
27 al_flip_display();
28 std::cout << __LINE__ << ' ' << __FILE__ << std::endl;
29 al_clear_to_color(al_map_rgb(0, 0, 0));
30 }
31 else if (vid_ev.type == ALLEGRO_EVENT_VIDEO_FINISHED)
32 {
33 done = true;
34 break;
35 }
36 std::cout << __LINE__ << ' ' << __FILE__ << std::endl;
37 }
38
39 al_destroy_event_queue(vid_event_queue);
40 al_close_video(splash_vid);
41 al_destroy_mixer(mixer);
42}
Still no working, I can't figure why. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
It's not playing because you're never receiving an ALLEGRO_EVENT_VIDEO_FRAME_SHOWN event. Looks like a bug in Allegro. Could be due to an unsupported video format. .ogv is just a container for different video files. EDIT However, try ex_video to play your .ogv file. There doesn't appear to be anything wrong with the video file. VLC Media Player can play it just fine, and when I run "ex_video.exe vid.ogv" it plays fine. There may be something wrong with my build. I've been having other problems with DirectX. What version of Allegro are you using? Are you using binaries? If so, what version? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
So if you know, could you tell me which video format I can use ? |
Crisbe
Member #16,579
October 2016
|
I have Allegro 5.2.1.1 and I downloaded it from NuGet packages using Visual Studio 2015 Enterprise EDIT How can I use ex_video? |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Nuget doesn't come with the examples. You have to download the sources and compile ex_video yourself. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
Still don't know how to play video but I solved my problem. I rendered my video frame by frame in images and I am drawing them sequentially. Thanks for help and have a nice day |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You should post your solution. Are you parsing the video yourself? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Crisbe
Member #16,579
October 2016
|
Yes. 1void intro(void)
2{
3 ALLEGRO_SAMPLE *intro_music = al_load_sample("Intro/Intro_music.ogg");
4 ALLEGRO_BITMAP *image = NULL;
5 std::string count = "000000";
6 std::string name = "Intro/Intro_";
7 std::string png = ".png";
8 std::string all_name;
9 std::string buffer;
10 bool done = false;
11 int c = 0, i = 0;
12
13 ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
14 al_register_event_source(event_queue, al_get_timer_event_source(fps_timer));
15 al_register_event_source(event_queue, al_get_keyboard_event_source());
16
17 al_reserve_samples(1);
18 al_play_sample(intro_music, 1, 0, 1, ALLEGRO_PLAYMODE_ONCE, 0);
19
20 while (!done)
21 {
22 ALLEGRO_EVENT ev;
23 al_wait_for_event(event_queue, &ev);
24 if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
25 {
26 if (ev.keyboard.keycode == ALLEGRO_KEY_SPACE)
27 done = true;
28 }
29 else if (ev.type == ALLEGRO_EVENT_TIMER)
30 {
31 all_name = name + count + png;
32 image = al_load_bitmap(all_name.c_str());
33 al_draw_bitmap(image, 0, 0, 0);
34 al_flip_display();
35 al_clear_to_color(al_map_rgb(0, 0, 0));
36 al_destroy_bitmap(image);
37 c++;
38 count.clear();
39 count = std::to_string(c);
40 while (buffer.length() + count.length() < 6)
41 buffer += '0';
42 count = buffer + count;
43 while (count.length() > 6)
44 count.erase(count.begin());
45 ++i;
46 }
47 if (i == 390)
48 done = true;
49 }
50 al_destroy_sample(intro_music);
51}
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Like I said, ex_video works, where our example programs do not. They must be doing something different. Look at the source of ex_video.c for clues. You can compile it yourself like any other normal allegro program now that you have Allegro from Nuget installed. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|