Sobre Produtos Suporte

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

image

 

  By Olga Krovyakova - 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 how you 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

 

 

 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!