Question

I'm using jwplayer, ffmpeg and crtmpserver to do live streaming. I was wondering if it is possible to dynamically resize the jwplayer according to the video being streamed by ffmpeg. For example let's say following ffmpeg command is being used to stream video:

ffmpeg -re -i 'myVideo.mp4' -vf scale=30:30 -vcodec flv -acodec copy -s 30x30 -f flv rtmp://localhost/flvplayback/livestream

Jwplayer side of code:

<script type="text/javascript">
    jwplayer("myElement").setup({
      playlist: [{
        image: "/uploads/myPoster.jpg",
        sources: [{
            file: "/uploads/myManifest.smil",
            type: "rtmp"
          },{
          file: "/uploads/myVideo.mp4"
           }]
      }],
      primary: "flash",
      listbar: {
          position: 'right',
          size: 100
      },
      stretching: "exactfit"
});

Now, since ffmpeg is streaming video with -s as 30x30, video is too blur. So, is it possible to resize the jwplayer to fit the video; jwplayer size should be reduced in this case. I tried using jwplayer.resize() based on jwplayer().getCurrentQuality() but not sure how to use it in this case.

Was it helpful?

Solution

Found the answer. Above can can accomplished using jwplayer().onQualityChange event like the following:

    jwplayer().onQualityChange( function(event){
       resizePlayer();
    });

    function resizePlayer(){
      if (jwplayer().getCurrentQuality() == 0)
      {
        jwplayer().resize(1024, 720);

      } 
      if (jwplayer().getCurrentQuality() == 1)
      {
        jwplayer().resize(640, 360);
      } 
      if (jwplayer().getCurrentQuality() == 2)
      {
        jwplayer().resize(320,180);
      } 
    } 

The above event is triggered when the quality of the jwplayer is changed. This url here http://www.longtailvideo.com/support/jw-player/29365/rtmp-dynamic-stream shows how to create different quality video for the jwplayer. The above function resizePlayer() can be called using other suitable jwplayer events too as required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top