Opened 7 years ago
Last modified 6 years ago
#4724 new task
Video playback
Reported by: | fcxSanya | Owned by: | |
---|---|---|---|
Priority: | Nice to Have | Milestone: | Backlog |
Component: | Core engine | Keywords: | |
Cc: | Patch: |
Description
Even if there are currently no plans to use it for the main game, it's desirable to have the video playback feature in the engine. It was already requested for Hyrule Conquest (https://wildfiregames.com/forum/index.php?/topic/22638-i-might-port-hyrule-total-war-to-0ad/&do=findComment&comment=335694) and may be eventually used by other mods and maybe even for 0 A.D. itself.
Change History (5)
follow-up: 5 comment:2 by , 7 years ago
Replying to Vladislav Belov:
So, probably we could use ffmpeg for render/decoding video files too?
Yeah, it seems to be the most widespread / mature open source project related to the video processing.
There is a ffplay utility which is "a very simple and portable media player using the FFmpeg libraries and the SDL library", we can use it as an example.
Also there are a number of tutorials for writing a ffmpeg-based video player, like this one: http://dranger.com/ffmpeg/
Another alternative is Theora, it's supported by ffmpeg too, but if we will aim to Theora-only support, we may find much smaller and simpler library / API.
One of potentially useful findings here is TheoraPlay library by icculus which is used in some games he ported to Linux.
It would be interesting to see what other open-source games and game engines use.
STK (which is a nice project to derive code from :D) has some cinematic, but I believe it's all game-engine based.
One of the projects which came to my mind where I saw videos is Warzone 2100, it seems to be using Theora: https://github.com/Warzone2100/warzone2100/blob/master/lib/sequence/sequence.cpp
comment:3 by , 7 years ago
Some other games using Theora are here (search for Theora in that page): https://wiki.xiph.org/Games_that_use_Vorbis
Theora is a bit old as a video codec however. VP9 has a better efficiency (quality / file size) and is also free (code and patents). Then AV1 is going to replace VP9 in a year or so.
comment:4 by , 7 years ago
comment:5 by , 6 years ago
Replying to fcxSanya:
There is a ffplay utility which is "a very simple and portable media player using the FFmpeg libraries and the SDL library", we can use it as an example.
Also there are a number of tutorials for writing a ffmpeg-based video player, like this one: http://dranger.com/ffmpeg/
I've read the tutorial, it's based on ffplay itself (which seems to be something like a reference implementation of ffmpeg-based player),
at the fifth step the tutorial achieves a minimally-usable player, what requires a ~800-lines long program[1]
with audio-processing thread, video-decoding thread, videoframes queue, video-display thread, mutexes and time-sync between threads; here is a scheme from tutorial 04:
________ audio _______ _____ | | pkts | | | | to spkr | DECODE |----->| AUDIO |--->| SDL |--> |________| |_______| |_____| | video _______ | pkts | | +---------->| VIDEO | ________ |_______| _______ | | | | | | EVENT | +------>| VIDEO | to mon. | LOOP |----------------->| DISP. |--> |_______|<---FF_REFRESH----|_______|
All that stuff starting from the ffmpeg API calls and ending with the threads organization may become obsolete with time. The tutorial is based on an older non-longer-accessible one, was outdated at some stage itself[2]
and later updated by other people[3]
.
I expect other libraries to provide simpler APIs and thus more easily maintainable solutions.
[1]
for comparison, the current version of ffplay.c is 3743-lines long
[2]
see "CAVEAT" section in Tutorial 05 and End
[3]
see "UPDATE" in End and the github project linked there
There was a video recording feature in the past. There was an ability to render view in the Atlas, but it was removed for some reason (the one of them is supporting ffmpeg): r14181. We told with @elexis about it, someone have to follow ffmpeg library changes.
But there is a way, when we do not include ffmpeg, and just render the game and output frames to stdout in the raw format. And anyone will be able to catch it with own ffmpeg version.
So, probably we could use ffmpeg for render/decoding video files too?