Remove subtitle/caption from hls and dash manifest file - http-live-streaming

I am currently using aws mediaconvert to encode videos to hls and dash format. I believe that in the m3u8 (for hls) and mpd (for dash) file which is generated, these can be parsed to remove required subtitles. I am looking to parse the m3u8 and mpd file, create an updated manifest without required subtitles and save it back to s3. Has someone previously done something similar?

This could be done with a Lambda Function triggered by the arrival of the source manifest in a specified S3 bucket. A Lambda script could remove the captions line(s) and post a revised manifest to the different S3 bucket. The script should then copy the segments over to the new bucket as well in order to maintain a playable HLS or DASH file group.
Alternatively you can ingest the asset as-is into MediaPackage as a VOD asset, and use the '?aws.manifestfilter=subtitle_language:xxx' filter when asking for the VOD manifest. This feature of MediaPackage returns a customized (filtered) version of the source manifest on demand without you having to permanently alter it. Specifying a filter of 'subtitle_language:zzz' will return a manifest with no subtitles in it. You could also ask for only specified subtitle renditions to be included.

Related

Rearranging the order of ts files in m3u8 causes them to get stuck during playback

I have one m3u8 file and several TS files.
The following is the actual output of the m3u8 file.
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0000.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0003.ts
#EXT-X-ENDLIST
I rewrote this m3u8 in the following format, saved it, and played it.
Then the playback order of the video was exactly as I changed the m3u8.
However, the video playback does not work as expected and gets stuck.
#extm3u.
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:5
#EXTINF:4.027222,
test0003.ts
#EXTINF:4.004000,
test0002.ts
#EXTINF:4.004000,
test0001.ts
#EXTINF:4.004000,
test0000.ts
#EXT-X-ENDLIST
If I want to change the order of the TS files like this, how do I edit the m3u8 file?
Or can I use the ffmpeg command to change the order of the ts files and then recreate the m3u8 file?
I'm afraid you're not allowed to manually edit the playlist (or re-generate it using ffmpeg command). Due to the restriction of HLS protocol (RFC8216) , media segments (the .ts files in your case) in the middle must NOT be removed when you set either value event or vod to -hls_playlist_type option in your ffmpeg command , even without -hls_playlist_type, it is still limited to change the playlist (and NOT including freely removing any media segment).
Quote from General Server Responsibilities in RFC8216
The server MUST NOT change the Media Playlist file, except to:
Append lines to it (Section 6.2.1).
Remove Media Segment URIs from the Playlist in the order that they
appear, along with any tags that apply only to those segments
(Section 6.2.2).
Increment the value of the EXT-X-MEDIA-SEQUENCE or EXT-X-
DISCONTINUITY-SEQUENCE tags (Section 6.2.2).
Add an EXT-X-ENDLIST tag to the Playlist (Section 6.2.1).
A Media Playlist has further constraints on its updates if it
contains an EXT-X-PLAYLIST-TYPE tag. An EXT-X-PLAYLIST-TYPE tag with
a value of VOD indicates that the Playlist file MUST NOT change. An
EXT-X-PLAYLIST-TYPE tag with a value of EVENT indicates that the
server MUST NOT change or delete any part of the Playlist file; it
MAY append lines to it.
Note that the EXT-X-PLAYLIST-TYPE in your playlist related to -hls_playlist_type in ffmpeg

Easily differentiate video files from image files in Node

I'm building a project where people can upload files, I would like to then display those files in a browser where people can interact with them (vote, comment etc)
However, this means I need to programatically build the html depending on the format of the video or image. Is there a way to feed a file (or filename) into a library, and determine whether I need to display it in a video element or an image element? Even a list of video formats vs image formats would help but I haven't seen anything in regards to that.
No module can reliably determine the file type. The user could either change the extension or even the magic number of the file to obfuscate it. The only reliable way it to try to pass file to some image / video transcoder to let it decide or error out if the format is invalid. This way you know you are working with known formats since all files are transcoded to your specific extensions. That could be mp4 or png. I recommend using handbrake for videos and sharp for images. Leaving the NPM links down below:
https://www.npmjs.com/package/handbrake-js
https://www.npmjs.com/package/sharp

How do i get any file signature (or call it file header) in NodeJS

I am working on a module which uploads images, pdfs, audio and video files. I mainly covered all the validations in it but i am stuck at one point where i cannot detect the header of the video/audio file. It is when i change the type of any file, like changed the .JS to mp3 or mp4. Is there any packages in nodeJS which can detect the file signature or header?
Thanks in advance.
If you can not/do not, want to check by the filename extension you will have to parse the file using an appropriate media inspector.
To list a few:
file-type
mux.js

Need a way to write headers on a wav file generated by sox

I'm using sox to convert some mp3 files to wav for a project. The problem is that the software that plays the files does not have the media name for the element it is playing. I can't seem to find a win32 cli tool to read the header of the wav file and write what I need to it.
Sox will read the header but it's not showing the title of the media element that was inserted with the old software I used. I just couldnt automate it or I would have used it instead.
I have determined the info is written in either CART CHUNK section or just to the file headers. I can't figure out to write my own data there.
The way I was able to do this was with this project: https://github.com/JamesHeinrich/getID3

Rebuilding MP4 file from fragmented MP4 "mdat" atom?

I'm trying to rebuild a video file from a Smooth Streaming server. Smooth Streaming serves fMP4 files which are regular MP4 files without neither their FTYP nor their MOOV atoms.
All the informations stored in those atom are placed into a Manifest XML file, which I have.
Is there a way to programmatically rebuild the original MP4 file, either by:
rebuilding a new file straight from H264/AAC content located in MDAT
(and picture format infos); or
rebuilding FTYP and MOOV atoms
Or else, is there a tool which can merge fMP4?
Yes. It is completely possible.
You can do this with FFmpeg. Study the mov.c [MP4 demuxer] from libavformat.
You will need to complete the MP4 in memory with all data that is "missing" in the fMP4. In other words, when you need an atom that doesn't exist in fMP4 [almost all], you will have to input all information hard-coded (such information, most of them come from the manifest).
It's not easy... but for sure it's possible. I've done by myself. Unfortunately the code is not my property.
Good luck! ;-)
UPDATE: the PIFF format specification will be very useful (http://go.microsoft.com/?linkid=9682897) so one can understand what is already in the fMP4 and what is not!
It is simple to rebuild a mp4 file, if there are ism and ismc file which are related to fragmented mp4 files.
It is requested that you should know media type, codec type, codec specific data and time scale of each trak to rebuild a moov and ftyp atom.
these information can be retrieved from ism and ismc file.
you can retrieve a media type of each track from the ism file.
you can retrieve codec type, codec specific data and time scale of each track from the ismc file.
simply speaking, ism/ismc files are meta data for server and client so that you can rebuild meta data(ftyp, moov atom) for a mp4 file.

Resources