mrmaffen / vlc-android-sdk

VLC Android SDK pushed to Maven Central. Primarily used in project tomahawk-android.
792 stars 244 forks source link

video frame is not rendering complete screen. It showing video in a small portion of SurfaceView . #104

Open VikashKumar0 opened 6 years ago

JohanJarvi commented 6 years ago

I'm having this problem as well, I'll let you know if I figure out how to fix it.

iceteahh commented 6 years ago

@JohanJarvi Did you fix it?

JohanJarvi commented 6 years ago

No I haven't had time to really dig down in it too much, I tried for about a day but no luck so far. Will continue digging and update you guys once I've got it working, if I get it working.

JohanJarvi commented 6 years ago

Still no luck guys, anyone figured this out yet?

JohanJarvi commented 6 years ago

@VikashKumar0 Okay so I figured out a basic hack to get it filling a larger portion of the screen, works really well if you know the resolution of the screen you are trying to view, if the resolution is unknown then more work needs to be done but this is a baseline.

There are a few steps involved though so bare with me:

  1. Find the size of your screen.
  2. Set up your final IVLCOut to incorporate the screen size.
  3. Adjust scaling factor in mMediaPlayer to increase size of video stream according to the resolution of your target device.

To explain each task:

  1. Setup your globals:

    public class SingleStreamView extends AppCompatActivity implements IVLCVout.Callback {
    
    public int mHeight;
    public int mWidth;

    Secondly, in the onCreate task find your screen sizes of your device:

    
    DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        mHeight = displayMetrics.heightPixels;
        mWidth = displayMetrics.widthPixels;
2.
Then go down to your "CreatePlayer" event and where you set up your video output:

// Set up video output final IVLCVout vout = mMediaPlayer.getVLCVout(); vout.setVideoView(mSurface); vout.setWindowSize(mWidth,mHeight); vout.addCallback(this); vout.attachViews();


The winning line that made it center in my surface was the "vout.setWindowSize(mWidth,mHeight);"

I hope this helped, it helped me center my video feed in my app.

3.
Then I simply used the setscale option to "fullscreen" the video. That said, it's a bit of a hack, and I would like to try and figure out a way to grab the codec information so to dynamically set the scale of the video.

Either way I found that with a Samsung Galaxy s8, a good scaling factor for a 640x480p RTSP stream was 1.8. Coded like so:
        Media m = new Media(libvlc, Uri.parse(RTSP_ADDRESS));
        m.setHWDecoderEnabled(true,false);
        m.addOption(":network-caching=100");
        m.addOption(":clock-jitter=0");
        m.addOption(":clock-synchro=0");
        m.addOption(":fullscreen");
        mMediaPlayer.setMedia(m);
        mMediaPlayer.setAspectRatio("16:9");
        mMediaPlayer.setScale(1.8f);
        mMediaPlayer.play();


Where you got "mMediaPlayer.setScale(1.8f);"

Hope this helps you!
SuryaChundawat commented 6 years ago

Its not resolved my issue Application is crashed while applying this.

JohanJarvi commented 6 years ago

Hi @SuryaChundawat,

could you post the stack trace of your errors?

Perhaps I could you debug the issue that is causing your application to crash when applying these things. I had no issues applying any of these changes to my application so perhaps there is a special case that is causing your application to behave this way?

kvnbass commented 5 years ago

You have saved a lot of lives from certain danger and death with your solution @JohanJarvi thank you!