Hello I have problem with streaming video in the newest allegro 5.
I have:
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_video.h>
int main(){
al_install_audio();
al_init_acodec_addon();
al_init_video_addon();
ALLEGRO_VIDEO *splash_vid = al_open_video("vid.ogv");
ALLEGRO_MIXER *mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
al_start_video(splash_vid, mixer);
al_close_video(splash_vid);
al_destroy_mixer(mixer);
return 0;
}
but after launch I have only black screen which can't be closed.
Can u help me solve this problem?
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 :
http://liballeg.org/a5docs/trunk/video.html
You have a black screen that can't be closed because you didn't create a display.
Now I have something like that and I created display earlier, in main fucntion:
void splash_screen(void)
{
ALLEGRO_VIDEO *splash_vid = al_open_video("vid.ogv");
ALLEGRO_MIXER *mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
ALLEGRO_BITMAP *bitmap = al_create_bitmap(al_get_video_scaled_width(splash_vid), al_get_video_scaled_height(splash_vid));
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;
while (!done)
{
ALLEGRO_EVENT vid_ev;
al_wait_for_event(vid_event_queue, &vid_ev);
switch (vid_ev.type)
{
case ALLEGRO_EVENT_VIDEO_FRAME_SHOW:
bitmap = al_get_video_frame(splash_vid);
al_draw_bitmap(bitmap, 0, 0, 0);
al_flip_display();
//std::cout << _LINE_ << ' ' << _FILE_ << std::endl;
al_clear_to_color(al_map_rgb(0, 0, 0));
break;
case ALLEGRO_EVENT_VIDEO_FINISHED:
done = true;
break;
}
}
al_destroy_event_queue(vid_event_queue);
al_close_video(splash_vid);
al_destroy_mixer(mixer);
}
and still I have black screen.
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.
Still it doesn't work :/
I can't event gets this events because this lines not executes
Still it doesn't work :/
I can't event gets this events because this lines not executes
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.
Ok, so this is my main function:
#include "All_headers.h"
ALLEGRO_TIMER *fps_timer = NULL;
ALLEGRO_DISPLAY *display = NULL;
int width = 640;
int height = 480;
int fps = 60;
int main(void)
{
//allegro variables
if (!al_init()) // test allegro
al_show_native_message_box(display, "Arcade Jump", "Error", "Error", "Error with allegro", ALLEGRO_MESSAGEBOX_WARN);
al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
display = al_create_display(width, height);
al_set_window_title(display, "Arcade Jump");
al_hide_mouse_cursor(display);
if (!display) //test display
al_show_native_message_box(display, "Arcade Jump", "Error", "Error", "Error with display", ALLEGRO_MESSAGEBOX_WARN);
fps_timer = al_create_timer(1.0 / fps);
al_start_timer(fps_timer);
//addon init
al_install_audio();
al_init_acodec_addon();
al_init_video_addon();
al_install_keyboard();
al_init_primitives_addon();
al_init_image_addon();
splash_screen();
menu();
// destroying globall variables
al_destroy_display(display);
al_destroy_timer(fps_timer);
return EXIT_SUCCESS;
}
Splash function:
#include "All_headers.h"
void splash_screen(void)
{
ALLEGRO_VIDEO *splash_vid = al_open_video("vid.ogv");
ALLEGRO_MIXER *mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
ALLEGRO_BITMAP *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;
while (!done)
{
ALLEGRO_EVENT vid_ev;
al_wait_for_event(vid_event_queue, &vid_ev);
if (vid_ev.type == ALLEGRO_EVENT_VIDEO_FRAME_SHOW)
{
bitmap = al_get_video_frame(splash_vid);
al_draw_bitmap(bitmap, 0, 0, 0);
al_flip_display();
std::cout << _LINE_ << ' ' << _FILE_ << std::endl;
al_clear_to_color(al_map_rgb(0, 0, 0));
}
else if (vid_ev.type == ALLEGRO_EVENT_VIDEO_FINISHED)
{
done = true;
break;
}
std::cout << _LINE_ << ' ' << _FILE_ << std::endl;
}
al_destroy_event_queue(vid_event_queue);
al_close_video(splash_vid);
al_destroy_mixer(mixer);
}
and headers:
#pragma once
// allegro extensions
#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_audio.h>
#include <allegro5\allegro_acodec.h>
#include <allegro5\allegro_video.h>
#include <iostream>
// splash screen
void splash_screen(void);
// global variables
extern ALLEGRO_TIMER *fps_timer;
extern ALLEGRO_DISPLAY *display;
extern int width;
extern int height;
extern int fps;
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
You still haven't set the drawing target to the backbuffer before drawing the video frame and flipping the display.
Still no working, I can't figure why.
My event queue is all the time empty.
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
I've been having problems with DirectX and when I try to close my example program to play your .ogv file it deadlocks in al_close_video.
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?
So if you know, could you tell me which video format I can use ?
See my edit.
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?
Nuget doesn't come with the examples. You have to download the sources and compile ex_video yourself.
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
You should post your solution. Are you parsing the video yourself?
Yes.
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.