-
Notifications
You must be signed in to change notification settings - Fork 24
Subtitles and mp4 metadata
To embed non-subtitle metadata (like the title, penta id, ...) into an mp4 file:
apt-get install atomicparsley
AtomicParsley test.mp4 --TVShowName "FOSDEM" --TVEpisodeNum 1234 --TVSeason 18 --overWrite
Or use mp4v2-utils:
apt-get install mp4v2-utils
mp4tags -album 'FOSDEM 2018' -song 'Embedding mp4 tags in blah using llvm' -season 18 -episode 1234 -year 2018 -longdesc 'Ik heb eerbied voor jouw grijze haaaaareeeeen. Ze beschermen je lieve geziiiiiicht.' test.mp4
Then check if metadata have been recorded into the mp4 correctly:
AtomicParsley test.mp4 -t
https://amara.org is as free a subtitling webapp as it gets. It is also used by the Debconf subtitles team.
The debconf subs team has created a python script for syncing subtitle files from amara.org that might be useful for us: https://alioth.debian.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=debconfsubs/debconfsubs.git;a=blob;f=scripts/2016/amara.py;h=54aa959ec37b0c66eab393ecfed36f79d76dfc40;hb=HEAD .
Vtt is the w3c standard format for web based subtitle playback.
- One can export subtitles in .vtt directly from amara.org.
- Ffmpeg can convert existing subtitles to .vtt:
ffmpeg -i test.srt test.vtt
In theory, html5 should support subtitle track playback without any javascript. In practice, there are still a few rough edges.
We use the clappr java script based player for streaming. It makes sense to also use that for later playback. Clappr has quite good builtin support for subtitle playback. An example:
<html>
<head>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"></script>
</head>
<body>
<div id="player"></div>
<script>
var player = new Clappr.Player({
parentId: '#player',
source: 'http://clappr.io/highline.mp4',
poster: 'http://clappr.io/poster.png',
height: 360,
width: 640,
playback: {
crossOrigin: 'anonymous', // Required if track loaded from another domain
externalTracks: [
{lang: 'en', label: 'English', src: 'https://static.playmedia-cdn.net/clappr/en.vtt'},
],
},
});
</script>
</body>
</html>
Embedding a subtitle track into an mp4 file is easy.
ffmpeg -i infile.mp4 -i infile.srt -c copy -c:s mov_text outfile.mp4
...or more explicitly:
ffmpeg -i infile.mp4 -i infile.srt -c:v copy -c:a copy -c:s mov_text outfile.mp4
Burning the subtitles into the video is probably not a great idea. Still, adding it here for completeness.
It's easiest to use the libass library. Make sure your ffmpeg install has the library in the configuration --enable-libass.
First convert the subtitles to .ass format:
ffmpeg -i test.srt test.ass
Then add them using a video filter (via libass):
ffmpeg -i test.mp4 -vf ass=test.ass test_subtitles_burned_in.mp4