Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcoding: Improve docs and examples #2838

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/config-transcode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ This section defines the various transcoding profiles.

* Optional

If the flags match the ones defined in clients, the profile is selected for that client. Choose an unused flag, e.g. "0x100", to avoid collisions with other features.
If the flags match the ones defined in clients, the profile is selected for that client.
There are are ``TRANSCODE1``, ``TRANSCODE2``, ``TRANSCODE3`` or choose an unused flag,
e.g. ``0x10000``, to avoid collisions with other features.

::

Expand Down
6 changes: 6 additions & 0 deletions doc/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ Nginx

* Restart Nginx service

Reverse proxies can also be used to handle really old devices and convert their request, e.g. to enable transcoding on http 1.0 protocol.
The example only works in conjunction with the respective gerbera configuration and `iptables` settings.

.. literalinclude:: ../scripts/nginx/gerbera-transcode.conf


.. index:: Sqlite

Using Sqlite Database (Default)
Expand Down
33 changes: 32 additions & 1 deletion doc/transcoding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ We define ``vlcprof`` in the profiles section:
<profile name="vlcprof" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<agent command="vlc"
arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/>
arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc://quit"/>
<buffer size="10485760" chunk-size="131072" fill-size="2621440"/>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
Expand Down Expand Up @@ -285,6 +285,37 @@ We also provide a way to specify that a profile should only process the Theora c
<accept-ogg-theora>yes</accept-ogg-theora>


Complete Example
----------------

.. code-block:: xml

<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="audio/x-flac" client-flags="TRANSCODING1" using="audio2mp3" />
<transcode mimetype="audio/flac" client-flags="TRANSCODING1" using="audio2mp3" />
</mimetype-profile-mappings>
<profiles>
<profile name="audio2mp3" enabled="yes" type="external">
<mimetype>audio/mpeg</mimetype>
<dlna-profile>MP3</dlna-profile>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>no</hide-original-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<sample-frequency>44100</sample-frequency>
<audio-channels>2</audio-channels>
<agent command="ffmpeg" arguments="-loglevel error -vn -i %in -ab 320k -f mp3 -y %out" />
<thumbnail>yes</thumbnail>
<buffer size="1048576" chunk-size="131072" fill-size="262144" />
</profile>
</profiles>
</transcoding>
<clients enabled="yes">
<client ip="192.168.120.42" flags="TRANSCODING1"></client>
</clients>


Testing And Troubleshooting
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
43 changes: 43 additions & 0 deletions scripts/nginx/gerbera-transcode.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# iptables -t nat -A PREROUTING \
# -i <incoming network interface> \
# -p tcp --dport GERBERA_PORT \
# --src <client's IP> \
# --dst GERBERA_IP> \
# -j REDIRECT --to-port NGINX_PORT

server {
listen GERBERA_IP:NGINX_PORT;

location / {
proxy_pass http://GERBERA_IP:GERBERA_PORT/;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header User-Agent "imperial DABMAN i250 (proxied by nginx)"; # Used for client filtering in Gerbera

proxy_http_version 1.1; # This is important :)
}
}

# <clients enabled="yes">
# <client userAgent="imperial DABMAN i250" flags="TRANSCODING1" />
# <!-- Identify the requests by User-Agent string and flag them accordingly -->
# </clients>
# <transcoding enabled="yes">
# <mimetype-profile-mappings>
# <transcode mimetype="audio/ogg" client-flags="TRANSCODING1" using="profile"/>
# </mimetype-profile-mappings>
# <profiles>
# <profile name="profile" enabled="yes" type="external">
# <mimetype>audio/mpeg</mimetype>
# <dlna-profile>MP3</dlna-profile>
# <accept-url>no</accept-url>
# <first-resource>yes</first-resource>
# <accept-ogg-theora>no</accept-ogg-theora>
# <agent command="<path to shell script that does the actual transcoding>" arguments="%in %out" />
# <buffer size="1048576" chunk-size="131072" fill-size="262144"/>
# </profile>
# </profiles>
# </transcoding>
3 changes: 3 additions & 0 deletions src/config/client_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ static constexpr auto quirkFlags = std::array {
std::pair("PV_SUBTITLES", QUIRK_FLAG_PV_SUBTITLES),
std::pair("PANASONIC", QUIRK_FLAG_PANASONIC),
std::pair("STRICTXML", QUIRK_FLAG_STRICTXML),
std::pair("TRANSCODING1", QUIRK_FLAG_TRANSCODING1),
std::pair("TRANSCODING2", QUIRK_FLAG_TRANSCODING2),
std::pair("TRANSCODING3", QUIRK_FLAG_TRANSCODING3),
};

int ClientConfig::remapFlag(const std::string& flag)
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void ConfigGenerator::generateTranscoding()

agent = setValue(fmt::format("{}/{}/", profileTag, ConfigDefinition::mapConfigOption(ATTR_TRANSCODING_PROFILES_PROFLE_AGENT)), "", true);
setValue(agent, ATTR_TRANSCODING_PROFILES_PROFLE_AGENT_COMMAND, "vlc");
setValue(agent, ATTR_TRANSCODING_PROFILES_PROFLE_AGENT_ARGS, "-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit");
setValue(agent, ATTR_TRANSCODING_PROFILES_PROFLE_AGENT_ARGS, "-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc://quit");

buffer = setValue(fmt::format("{}/{}/", profileTag, ConfigDefinition::mapConfigOption(ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER)), "", true);
setValue(buffer, ATTR_TRANSCODING_PROFILES_PROFLE_BUFFER_SIZE, fmt::to_string(DEFAULT_VIDEO_BUFFER_SIZE));
Expand Down
3 changes: 3 additions & 0 deletions src/util/upnp_quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ using QuirkFlags = std::uint32_t;
#define QUIRK_FLAG_PV_SUBTITLES 0x00000040
#define QUIRK_FLAG_PANASONIC 0x00000080
#define QUIRK_FLAG_STRICTXML 0x00000100
#define QUIRK_FLAG_TRANSCODING1 0x00010000
#define QUIRK_FLAG_TRANSCODING2 0x00020000
#define QUIRK_FLAG_TRANSCODING3 0x00040000

// forward declaration
class ActionRequest;
Expand Down
2 changes: 1 addition & 1 deletion test/config/fixtures/mock-config-all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit" />
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc://quit" />
<buffer size="14400000" chunk-size="512000" fill-size="120000" />
</profile>
</profiles>
Expand Down
2 changes: 1 addition & 1 deletion test/config/fixtures/mock-config-minimal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit" />
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc://quit" />
<buffer size="14400000" chunk-size="512000" fill-size="120000" />
</profile>
</profiles>
Expand Down
2 changes: 1 addition & 1 deletion test/config/fixtures/mock-transcoding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit" />
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc://quit" />
<buffer size="14400000" chunk-size="512000" fill-size="120000" />
</profile>
</profiles>
Expand Down
4 changes: 2 additions & 2 deletions web/js/gerbera-updates.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ const errorCheck = (event, xhr) => {
};

const showMessage = (message, callback, type, icon) => {
const toast = {message: message, type: type, icon: icon};
console.log(`${type}: ${message}`);
const toast = {message: message, type: type, icon: icon};
if (callback) {
toast.callback = callback;
}
$('#toast').toast('show', toast);
};

const showTask = (message, callback, type, icon) => {
const toast = {message: message, type: type, icon: icon};
console.log(`${type}: ${message}`);
const toast = {message: message, type: type, icon: icon};
if (callback) {
toast.callback = callback;
}
Expand Down