Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » play video in loop

This thread is locked; no one can reply to it. rss feed Print
play video in loop
Xpicolo
Member #16,781
December 2017

Hi,
How can i play video in loop?
I tried to put al_seek_video(video,0) after some frames in ex_video.c example,
but not work. (event ALLEGRO_EVENT_VIDEO_FINISHED still occurs)

Thanks,

beoran
Member #12,636
March 2011

Why not rewind the video with al_seek_video(video,0) when you get the ALLEGRO_EVENT_VIDEO_FINISHED event?

Xpicolo
Member #16,781
December 2017

I tried this, not work.

beoran
Member #12,636
March 2011

http://liballeg.org/a5docs/trunk/video.html#al_seek_video

According to the docs, rewinding is not supported for all video formats and decoders. What format is the video? And what video driver for Allegro5 are you using?

Xpicolo
Member #16,781
December 2017

I use .ogv file and OpenGL.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Chris Katko
Member #1,881
January 2002
avatar

To elaborate further: Some file formats only have one codec. But other file are actually "container" file formats. mkv, for example. That means they can have many different types of actual video and audio in the same file. Think of it like a zip, but dedicated to audio and video.

So you may have 100 mkv files that work fine, and 1 that doesn't. The reason is, that one (assuming it isn't corrupted) is using a different (unsupported) codec than the other 100.

So if it's not working, you need to find (and tell us) the codec that's missing or failing to load the file--not the container.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Xpicolo
Member #16,781
December 2017

Codec: Xiph.org's Theora Video (theo)
Decodec format: Planar 4:2:0 YUV
ENCODER: ffmpeg2theora-0.26

Edgar Reynaldo
Member #8,592
May 2007
avatar

Xpicolo
Member #16,781
December 2017

But that means to close, re-open and re-start video stream ?
So there will be a delay.

I'm wrong?

SiegeLord
Member #7,827
October 2006
avatar

What you need to do is right after you call al_seek_video_video(video, 0) is also call al_set_video_playing(video, true). Then it should work (and does for me on my machine).

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

Xpicolo
Member #16,781
December 2017

Thanks SiegeLord,
That is.
Now work ok.

But I have a problem with delay when i restart video with seek.
This is the code I tried, and the resulting log.
Please someone to look at it or try to execute.

Firts, my .ovg file is at 10 FPS, but events ALLEGRO_EVENT_VIDEO_FRAME_SHOW occur @ 170 ms

events FRAME_SHOW at 299 msec, play position 0.20 < why after 299msec and where is pos. 0.0 , 0.1 ?
events FRAME_SHOW at 164 msec, play position 0.30
events FRAME_SHOW at 168 msec, play position 0.40
events FRAME_SHOW at 167 msec, play position 0.50
events FRAME_SHOW at 168 msec, play position 0.60
events FRAME_SHOW at 169 msec, play position 0.70
events FRAME_SHOW at 172 msec, play position 0.80
events FRAME_SHOW at 171 msec, play position 0.90
events FRAME_SHOW at 172 msec, play position 1.00
events FRAME_SHOW at 172 msec, play position 1.10
events FRAME_SHOW at 172 msec, play position 1.20
events FRAME_SHOW at 172 msec, play position 1.30
events FRAME_SHOW at 170 msec, play position 1.40
events FRAME_SHOW at 168 msec, play position 1.50
events FRAME_SHOW at 167 msec, play position 1.60
events FRAME_SHOW at 168 msec, play position 1.70
events FRAME_SHOW at 169 msec, play position 1.80
events FRAME_SHOW at 171 msec, play position 1.90
events FRAME_SHOW at 173 msec, play position 2.00
events FRAME_SHOW at 171 msec, play position 2.10
events FRAME_SHOW at 173 msec, play position 2.20
events FRAME_SHOW at 172 msec, play position 2.30
events FRAME_SHOW at 172 msec, play position 2.40
events FRAME_SHOW at 172 msec, play position 2.50
events FRAME_SHOW at 171 msec, play position 2.60
events FRAME_SHOW at 170 msec, play position 2.70
events FRAME_SHOW at 169 msec, play position 2.80
events FRAME_SHOW at 166 msec, play position 2.90
events FRAME_SHOW at 164 msec, play position 3.00
events FRAME_SHOW at 163 msec, play position 3.00

restart play from 0.000000
events FRAME_SHOW at 671 msec, play position 0.50 < why after 671 ms and why 0.5 pos ?
events FRAME_SHOW at 166 msec, play position 0.60
events FRAME_SHOW at 166 msec, play position 0.70
events FRAME_SHOW at 169 msec, play position 0.80
events FRAME_SHOW at 170 msec, play position 0.90
events FRAME_SHOW at 172 msec, play position 1.00
events FRAME_SHOW at 173 msec, play position 1.10
events FRAME_SHOW at 173 msec, play position 1.20
events FRAME_SHOW at 172 msec, play position 1.30
events FRAME_SHOW at 173 msec, play position 1.40
events FRAME_SHOW at 172 msec, play position 1.50
events FRAME_SHOW at 170 msec, play position 1.60
events FRAME_SHOW at 267 msec, play position 1.70
events FRAME_SHOW at 168 msec, play position 1.80
events FRAME_SHOW at 169 msec, play position 1.90
events FRAME_SHOW at 172 msec, play position 2.00
events FRAME_SHOW at 174 msec, play position 2.10
events FRAME_SHOW at 172 msec, play position 2.20
events FRAME_SHOW at 174 msec, play position 2.30
events FRAME_SHOW at 173 msec, play position 2.40
events FRAME_SHOW at 173 msec, play position 2.50
events FRAME_SHOW at 173 msec, play position 2.60
events FRAME_SHOW at 172 msec, play position 2.70
events FRAME_SHOW at 171 msec, play position 2.80
events FRAME_SHOW at 170 msec, play position 2.90
events FRAME_SHOW at 167 msec, play position 3.00
events FRAME_SHOW at 165 msec, play position 3.10 < .ogv file have only 3 seconds
events FRAME_SHOW at 163 msec, play position 3.10

restart play from 0.000000
...

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_video.h> 5 6int width = 1024; 7int height = 768; 8 9ALLEGRO_DISPLAY *display; 10 11int main(int argc, char *argv[]) 12{ 13 ALLEGRO_VIDEO *video; 14 ALLEGRO_BITMAP *frame; 15 ALLEGRO_EVENT_QUEUE *queue; 16 ALLEGRO_EVENT event; 17 18 al_init(); 19 al_init_image_addon(); 20 al_init_video_addon(); 21 22 display=al_create_display(width, height); 23 queue=al_create_event_queue(); 24 25 video=al_open_video("main.ogv"); 26 27 al_register_event_source(queue, al_get_video_event_source(video)); 28 al_register_event_source(queue, al_get_display_event_source(display)); 29 30 al_start_video(video, al_get_default_mixer()); 31 32 double old_time=al_get_time(); 33 34 while(1) 35 { 36 al_wait_for_event(queue, &event); 37 38 if(event.type==ALLEGRO_EVENT_VIDEO_FRAME_SHOW) 39 { 40 printf("events FRAME_SHOW at %.0f msec, ",(al_get_time()-old_time)*1000); 41 old_time=al_get_time(); 42 43 ALLEGRO_BITMAP *frame = al_get_video_frame(video); 44 printf("play pozition %.2f\n",al_get_video_position(video, ALLEGRO_VIDEO_POSITION_ACTUAL)); 45 al_draw_bitmap(frame, 0, 0, 0); 46 al_flip_display(); 47 } 48 else if(event.type==ALLEGRO_EVENT_VIDEO_FINISHED) 49 { 50 al_seek_video(video, 0.00); 51 printf("\nrestart play from %f\n",al_get_video_position(video, ALLEGRO_VIDEO_POSITION_ACTUAL)); 52 al_set_video_playing(video, true); 53 54 } 55 } 56 return 0; 57}

SiegeLord
Member #7,827
October 2006
avatar

Can you share your video with us? Just want to make sure there's no some weird interaction between it and the video addon.

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

Xpicolo
Member #16,781
December 2017

this is the .ogv file

SiegeLord
Member #7,827
October 2006
avatar

Thanks for that, and the code. Indeed, there are a number of issues with playback, there are dropped frames, pauses and a bit of desync. There's nothing that you can do about it (the code and the file is fine), but we need to adjust how Allegro handles some things. I'll try to get it done before 5.2.4 release.

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

Go to: