kaltura / nginx-vod-module

NGINX-based MP4 Repackager
GNU Affero General Public License v3.0
2.01k stars 440 forks source link

problems with webm support #823

Open mstoykov opened 6 years ago

mstoykov commented 6 years ago

I use tears of steel webm file as the test file (http://ftp.nluug.nl/pub/graphics/blender/demo/movies/ToS/tears_of_steel_1080p.webm) . Using it just like it is I get 404 and this in the logs

mkv_metadata_reader_read: truncated file (2) while sending to client, client: 172.17.0.1, server: , request: "GET /dash/tears_of_steel.webm/manifest.mpd HTTP/1.1", host: "1-1.b.cdn13.com" 

After some hours of trial and error I figured that the audio was the problem. Removing the audio yielded manifest with two segments with total length of 7 seconds although full 15 seconds were played by dash.js.

After some reencoding, looking up what was recommended around the issues and the web I used:

ffmpeg -i tears_of_steel.webm -t 30  -s 960x400 -c:v libvpx-vp9 -speed 2  -threads 4 -tile-columns 4 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 -crf 20 -c:a libopus -b:a 64k -f webm 

The -t 30 -s 960x400 is to minimize the size of the encode time. With these options and practically anything else I tried with very little deviation (and not positive at that) I will get a manifest like

<?xml version="1.0"?>                                                                          
<MPD                                                                                           
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                      
    xmlns="urn:mpeg:dash:schema:mpd:2011"                                                      
    xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"                                            
    type="static"                                                                              
    mediaPresentationDuration="PT30.006S"                                                      
    minBufferTime="PT10S"                                                                      
    profiles="urn:mpeg:dash:profile:isoff-main:2011">                                          
  <Period>                                                                                     
    <AdaptationSet                                                                             
        id="1"                                                                                 
        segmentAlignment="true"                                                                
        maxWidth="960"                                                                         
        maxHeight="400"                                                                        
        maxFrameRate="500/21">                                                                 
        <SegmentTemplate                                                                       
            timescale="1000"                                                                   
            media="fragment-$Number$-$RepresentationID$.webm"                                  
            initialization="init-$RepresentationID$.webm"                                      
            startNumber="1">                                                                   
            <SegmentTimeline>                                                                  
                <S d="5333"/>                                                                  
                <S d="1334"/>                                                                  
            </SegmentTimeline>                                                                 
        </SegmentTemplate>                                                                     
      <Representation                                                                          
          id="v1-x3"                                                                           
          mimeType="video/webm"                                                                
          codecs="vp9"                                                                         
          width="960"                                                                          
          height="400"                                                                         
          frameRate="500/21"                                                                   
          sar="1:1"                                                                            
          startWithSAP="1"                                                                     
          bandwidth="0">                                                                       
      </Representation>                                                                        
    </AdaptationSet>                                                                           
    <AdaptationSet                                                                             
        id="2"                                                                                 
        segmentAlignment="true">                                                               
      <AudioChannelConfiguration                                                               
          schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011"                 
          value="1"/>                                                                          
        <SegmentTemplate                                                                       
            timescale="1000"                                                                   
            media="fragment-$Number$-$RepresentationID$.webm"                                  
            initialization="init-$RepresentationID$.webm"                                      
            startNumber="1">                                                                   
            <SegmentTimeline>                                                                  
                <S d="3198"/>                                                                  
            </SegmentTimeline>                                                                 
        </SegmentTemplate>                                                                     
      <Representation                                                                          
          id="a1-x3"                                                                           
          mimeType="audio/webm"                                                                
          codecs="opus"                                                                        
          audioSamplingRate="48000"                                                            
          startWithSAP="1"                                                                     
          bandwidth="0">                                                                       
      </Representation>                                                                        
    </AdaptationSet>                                                                           
  </Period>                                                                                    
</MPD>               

which because of the single audio segment and it size will play for 3 seconds and stop, without the audio I would get the same behavior as before. Also I hit #780, but because the size of the video I just raised the value of vod_max_frames_size to 1024m,

If I change the container to mp4 add -strict -2 and change the audio codec to ac3, the generated manifest for the mp4 will be fine and playable (atleast for the 30 seconds, I am going to try the whole video soon)

I suppose I am doing something wrong. But no changes in the way I encode or the whether I use mkv or webm yielded a playable dash manifest. All the videos are playable from the same firefox I am testing the manifest, so they are not corrupted or something else that will make them unplayable

erankor commented 6 years ago

I checked this sample, there are 2 issues here -

  1. It uses lacing for the audio frames, this is not supported.
  2. There is an issue in the 9th video fragment - the validation performed by the module is too strict.

I created a quick hack for the second issue, and the video plays fine. A more elegant fix can probably be implemented quite easily, but considering the first issue and the fact MKV in general has been discontinued, I'm not sure it's worth the effort.

mstoykov commented 6 years ago

First thank you for the quick reply.

Could you propose how to (re)encode/mux the file in order for the current source to work?

The fix, even the hack one, would be greatly appreciated as even though MKV might be discontinued, which I am not aware of, webm seems to be doing good for itself.

erankor commented 6 years ago

Sorry, I meant 'discontinued in the context of this module', not the format as a whole :) Regarding lacing - you can probably repackage (without retranscoding) using ffmpeg - ffmpeg doesn't use lacing when encoding MKV. I'll check regarding the code fix

mstoykov commented 6 years ago

Is there any update on the fix? I would be happy with the quick hack as well :).

erankor commented 6 years ago

Sorry for the delay, I now pushed the change that I wrote shortly after you opened this issue - https://github.com/kaltura/nginx-vod-module/pull/867 What I didn't like about this change was that I had to apply it on 'simple block' element (it didn't work when I applied it only on 'cluster'). I wanted to dig deeper into it, but didn't get a chance to do it.

mstoykov commented 6 years ago

For me this fix did not change the returned playlist - I still get only around 3 seconds of playthrough. Maybe you missed some part of it ? I'm going to try some more encoding options to see if it will make a difference.

jessp01 commented 5 years ago

Hi @MStoykov, any news on this? Thanks.

tan-tan-kanarek commented 3 years ago

+1