Introduction
libVLC is an embeddable engine for 3rd party applications and frameworks.
It runs on the same platforms as VLC (and sometimes on more) and can provide playback, streaming and conversion of multimedia files and streams.
libVLC has numerous bindings for other languages, such as C++, Python, java, Objective-C and C#.
The generated documentation can be browsed from here.
License
libVLC is released under the LGPLv2 (or later) license. This allows embedding the engine in 3rd party applications, while letting them to be licensed under other licenses.
However, note that some plugins are under more restrictive licenses, such as GPLv3 (or later).
Example
4#include <stdio.h>
5#include <stdbool.h>
6#include <inttypes.h>
7#include <pthread.h>
9
10struct cbs_context
11{
13 pthread_cond_t cond;
14 bool stopping;
15 bool stopped;
17 bool time_changed;
18};
19
21{
22 struct cbs_context *ctx = opaque;
23
25 return;
26
27 pthread_mutex_lock(&ctx->lock);
29 ctx->stopping = true;
30 else
31 ctx->stopped = true;
32 pthread_cond_signal(&ctx->cond);
33 pthread_mutex_unlock(&ctx->lock);
34}
35
36static void on_position_changed(
void *opaque,
libvlc_time_t time,
double pos)
37{
38 (void) pos;
39 struct cbs_context *ctx = opaque;
40
41 pthread_mutex_lock(&ctx->lock);
42 ctx->time_us = time;
43 ctx->time_changed = true;
44 pthread_cond_signal(&ctx->cond);
45 pthread_mutex_unlock(&ctx->lock);
46}
47
48int main(
int argc,
char* argv[])
49{
50 (void) argc; (void) argv;
54
55 struct cbs_context ctx = {
56 .lock = PTHREAD_MUTEX_INITIALIZER,
57 .cond = PTHREAD_COND_INITIALIZER,
58 .stopping = false,
59 .stopped = false,
60 .time_us = 0,
61 .time_changed = false,
62 };
63
64
66
67
69
70
72 .version = 0,
75 };
76
77
79
80
82
83
85
86
87 pthread_mutex_lock(&ctx.lock);
88 while (!ctx.stopping)
89 {
90 while (!ctx.stopping && !ctx.time_changed)
91 pthread_cond_wait(&ctx.cond, &ctx.lock);
92
93 if (ctx.time_changed)
94 {
95 ctx.time_changed = false;
97 int64_t seconds = microseconds / 1000000;
98 int64_t minutes = seconds / 60;
99 microseconds -= seconds * 1000000;
100 seconds -= minutes * 60;
101 pthread_mutex_unlock(&ctx.lock);
102 printf("Current time: %" PRId64 ":%" PRId64 ":%" PRId64 "\n",
103 minutes, seconds, microseconds);
104 pthread_mutex_lock(&ctx.lock);
105 }
106 }
107
108
109 while (!ctx.stopped)
110 pthread_cond_wait(&ctx.cond, &ctx.lock);
111 pthread_mutex_unlock(&ctx.lock);
112
113
115
117
118 return 0;
119}