About Products Support FAQ Blog

How to Edit Fragmented MP4 HLS Streams (M3U8) With the Video Editing SDK

image

 

  By Olga Krovyakova - modified October 2, 2023, created April 1, 2019

With the newly released version 4.2, Solveig Multimedia's Video Editing SDK extends the suported formats.
Current version is generally focused on the online-based stream formats.

Video Editing SDK v.4.2 supports the following formats:

  • Fragmented MP4 HLS streams
  • HTTP hosted MP4 files
  • YouTube online videos

In this article you'll find the demonstration of the Fragmented MP4 HLS streams support.

 

TRY Video Editing SDK FREE

 

Fragmented MP4 HLS streams support

Video Editing SDK v.4.2 support the following features for Fragmented MP4 HLS streams:

Playback.

You can easily open the Fragmented MP4 HLS M3U8 stream and work with it just like with the local files. You can navigate through the file as well as play it back. Only parts necessary for preview of the stream will be downloaded to your PC.

To preview the Fragmented MP4 HLS stream, you can build the following graph:

Graph to preview the fragmented MP4 HLS stream

The graph contains a SolveigMM HLS Source as a source filter and Elecard AVC Video Decoder as a video decoder filter. Both filters shipped with the SDK.

Use the SMM Trim C++ Sample Application to test the support of the Fragmented MP4 HLS streams playback and trimming.
The following video demonstrates what you can do with the Fragmented MP4 HLS streams by means of the Video Editing SDK v.4.2:

button

Editing.

Video Editing SDK is now capable of trimming of the Fragmented MP4 HLS streams. Video Editing Engine is the main component in charge. What you need to do is configure the Video Editing Engine, specify the XTL, describing your current task, then run it and wait for the completion.

Video Editing Engine is a COM component, exposing the ITrimmerObjControl, and you create it as follows:

hr = ::CoCreateInstance( CLSID_TrimmerObjControl, NULL, CLSCTX_INPROC, IID_ITrimmerObjControl, (void**)&m_pITrimmerObjControl );

To configure the Editing Engine you sould use the IModuleConfig interface:

hr = m_pITrimmerObjControl->QueryInterface(IID_IModuleConfig, (void **)&m_pModuleCfgEditObj);

You must use the obtained interface to set an XTL string, containing your trimming task, and optionally specify the callback to track the operation progress:

VARIANT var1 = {0}, var2 = {0};

var1.vt = VT_BSTR;
var1.bstrVal = ...; //task string in XTL format
hr = m_pModuleCfgEditObj->SetValue( &SMAT_XTLString, &var1 );

var2.vt = VT_BYREF|VT_UI1;
var2.pbVal = (BYTE*) &m_xCTrimmerObjControlCB; //pointer to the callback class
hr = m_pModuleCfgEditObj->SetValue( &SMAT_Callback, &var2 );

VARIANT var_res = {0};
hr = m_pModuleCfgEditObj->CommitChanges(&var_res);

You start the trimming process by invoking the ITrimmerObjControl::Start() method:

hr = m_pITrimmerObjControl->Start();

And during the trimming process you can ask the Editing Engine for a progress value:

VARIANT var = {0};
hr = m_pModuleCfgEditObj->GetValue( &SMAT_Progress, &var );

When the processing is done the Editing Engine invokes the ITrimmerObjControlCB::OnStop() from the callback.

Below you can see the XTL sting example, that contains a trimming task:

<timelines version="2">
 <timeline>
  <group output="C:\hls\output.m3u8">
   <track video="1" audio="1" text="1" flags="">
    <clip src="http://smarteditingonline.solveigmm.com/files/test_multibitrate.m3u8"
                    start="160413589" stop="229542097" timeFormat="100ns_units">
    <clip src="http://smarteditingonline.solveigmm.com/files/test_multibitrate.m3u8"
                    start="469719350" stop="572525849" timeFormat="100ns_units">
   </track>
  </group>
 </timeline>
</timelines>

The source file in this XTL is the Fragmented MP4 HLS file, hosted on http://smarteditingonline.solveigmm.com. Two intervals (represented by 'clip'-tags) will be saved from the source file to the output file:

  • 160413589 - 229542097 UNITS (or 16.041 - 22.954 sec) and
  • 469719350 - 572525849 UNITS (or 46.971 - 57.252 sec)

If the source file contains multiple streams (e.g. for different bitrate values), the source structure will be recreated.
The test file http://smarteditingonline.solveigmm.com/files/test_multibitrate.m3u8 contains 2 different streams with different bitrate values (see the picture below).

image

After trimming the output folder (C:\hls) will contain 2 subfolders with both streams and the M3U8 playlist file (output.m3u8) with the description of streams configurations. The following picture shows the structure of the trimmed HLS:

image

The structure of the output M3U8 file:

#EXTM3U

#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=1007161,BANDWIDTH=1275068,VIDEO-RANGE=SDR,CODECS="mp4a.40.2, avc1.42c01f",RESOLUTION=1280x720,FRAME-RATE=24.000,CLOSED-CAPTIONS=NONE
500K/prog_index.m3u8

#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=1564155,BANDWIDTH=2042932,VIDEO-RANGE=SDR,CODECS="mp4a.40.2, avc1.42c01f",RESOLUTION=1280x720,FRAME-RATE=24.000,CLOSED-CAPTIONS=NONE
1000K/prog_index.m3u8

The trimmed file can be found by the following link:
http://smarteditingonline.solveigmm.com/sdkdemo/hls/output.m3u8

Please refer to the SMM Trim C++ Sample Application source codes for the detailed description on how to configure and run the Video Editing Engine to perform trimming operation.

 

TRY Video Editing SDK FREE

 

Frequently Asked Questions

 

What is a fragmented MP4 HLS stream (M3U8)?

A fragmented MP4 HLS stream is a popular video streaming format that utilizes fragmented MP4 files and the M3U8 playlist to deliver video content over the internet. By dividing the video into smaller segments and providing adaptive streaming capabilities, HLS ensures smooth playback and compatibility across a wide range of devices and platforms.

So, why the MP4 file must be fragmented? If you want to use HEVC/H.265 or AVC/H.264, you must use it according to Apple's video encoding standards in their HLS Authoring Specification. Fragmented MP4 files are also compatible with MPEG-DASH, an alternative to HLS, so you can utilize the same files; the only difference is the manifest file (playlist). This results in less encoding and storage requirements, which should save expenses.

 

Can I edit fragmented MP4 HLS streams with traditional video editing software?

Editing fragmented MP4 HLS streams with traditional video editing software can be challenging due to the segmented nature of the format. Traditional software is designed to work with complete video files rather than individual segments. To edit HLS streams, it is recommended to convert them into a single video file using specialized tools before importing them into traditional editing software. This conversion step may result in the loss of adaptive streaming features and metadata associated with the original stream.

In summary, editing fragmented MP4 HLS streams with traditional video editing software typically involves converting the segments into a complete video file before editing. This process simplifies compatibility, but may result in the loss of certain HLS-specific features.

 

Are other editing functions available for fragmented HLS MP4 streams besides trimming?

The following capabilities are available for Fragmented MP4 HLS streams in Video Editing SDK v.4.2:
  • Playback. The fragmented MP4 HLS M3U8 stream is precisely as easy to access and work with as local files. The file can be played back and browsed through. Your computer will only download the sections of the stream necessary to play the preview.
  • Editing. Fragmented MP4 HLS streams can be edited with the use of a video editing software development kit. The core of the system is the video editing engine. After setting up the Video Editing Engine and providing the XTL that describes the present task, you can start the program and wait for it to finish.

For information on how to set up and run the Video Editing Engine for trimming, see the SMM Trim C++ Sample Application source codes.

 

What platforms are supported with the SDK?

Video Editing SDK is available on Windows, Linux, macOS, Android platforms.

 

Are there any specific guidelines for handling captions or subtitles in a fragmented MP4 HLS stream?

When handling captions or subtitles in a fragmented MP4 HLS stream, it is important to use a supported caption format (e.g., WebVTT or TTML), ensure alignment with video segments, include a separate caption media playlist, consider synchronization across variant streams, and thoroughly test for display and accessibility.

 

Can I monetize or insert ads into a fragmented MP4 HLS stream?

Yes, it is possible to monetize or insert ads into a fragmented MP4 HLS stream. HLS supports various methods for ad insertion and monetization. The most common approach is using ad markers within the stream that indicate where ads should be inserted. Ad insertion can be performed either server-side or client-side.

 

 About the author

imageOlga Krovyakova is the Technical Support Manager in Solveig Multimedia since 2010.

She is the author of many text and video guidelines of company's products: Video Splitter, HyperCam, WMP Trimmer Plugin, AVI Trimmer+ and TriMP4.

She works with programs every day and therefore knows very well how they work. Сontact Olga via support@solveigmm.com if you have any questions. She will gladly assist you!