pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.53k stars 770 forks source link

got error when set 640x360 #100

Closed ghost closed 6 years ago

ghost commented 6 years ago

screen shot 2017-12-12 at 10 22 01 am

int width = 640; int height = 360; int orientations = 90; if (status == 1){ orientations = 180; } int fps = 30; int bitrate = 2500 1024; int bitrateAudio = 128; int sampleRate = 44100; if (rtmpCamera1.prepareVideo(width, height, fps, bitrate,false, orientations) && rtmpCamera1.prepareAudio(bitrateAudio 1024, sampleRate, true, false, false)) { rtmpCamera1.startStream(session.getStringSession("streamUrl")); connectWebsocket(); }

I don't know what happen, but still work in 640x480 >_<

pedroSG94 commented 6 years ago

If work on 640x480 could be for multiple reason but normally:

But I don't understand why crash in AudioEncoder... Can you tell me device model and Android API?

ghost commented 6 years ago

You are right !!!

List tmpList = camera.getParameters().getSupportedVideoSizes(); width = tmpList.get(5).width; height = tmpList.get(5).height;

i use this code to get width and hieght for each device(Sony SO-02G android 5, Sony SO-01H android 6, NEXUS 6 android 8). but review screen stretched

pedroSG94 commented 6 years ago
List<Camera.Size> tmpList = camera.getParameters().getSupportedVideoSizes();

Is not correct. You should use:

List<Camera.Size> tmpList = camera.getParameters().getSupportedPreviewSizes();

Because you are streaming from preview. For preview stretched the solution is set to your view same aspect ratio than your stream resolution. Example:

With stream resolution 640x480:
640 / 480 = 1.33333.
So you should select 1.3333 pixel of width each 1 pixel of height
Valid resolution example: 1333.33x1000
Where 1333.33 is 1000(random height) * 1.33333

640x360:
640 / 360 = 1.77778
Valid resolution example: 1280x720
ghost commented 6 years ago

i see, thanks

(1) But when i start with stream resolution 640x360 and preview resolution 1280x720(or w / h = 1.77778), server got:

screen shot 2017-12-13 at 3 47 16 pm

(2) if stream and preview are same resolution, it will work fine, but hight resolution is stream too slow (good in 640x360 or 640x480), if preview resolution set 640x360 or 640x480, app can crash

ps: i dont know (1) is error of server or app

ghost commented 6 years ago

ah, when i use NEXUS 6 android 8, stream and preview are reverse, it will normal if rotation set 270(portraint), 180(landscape), but if do this others device will reverse >_<

pedroSG94 commented 6 years ago

No. When I said set your view same aspect ratio is set layout params to your view not use startPreview method of my library. Anyway you can use AutoFitTextureView class instance of SurfaceView or other option and this will resize preview for you. I think image error is because 360 is not multiple of 16 and that get a error in rotation methods. You can check it if you set rotation to 0 you should get a normal image. Nexus 6 error could be a hardware problem (I'm not sure but normally all device should see fine with 90 orientation in portrait and 0 in landscape for back camera and rotate it 180 for front camera) correct like in Nexus 5X that have camera with wrong orientation.