Tourenathan-G5organisation / SiliCompressor

A powerful, flexible and easy to use Video and Image compression library for Android.
Apache License 2.0
1.38k stars 292 forks source link

compressed video file not play in VideoView from WebServer #63

Open pritesh25 opened 6 years ago

pritesh25 commented 6 years ago

i'm developing application which record the video and save to web server, and since recorded video have too much size i use compression technique SiliCompressor in order to reduce size of original video.

after applying compression technique, video size reduces and i also play that compressed video file into my VideoView and till here working perfectly.

when i upload compressed video file to my live webserver and try to play video from url in VideoView, it's not playing.

However it work in my localhost server well.

can u help me what is problem ?

here is my code to play video from my live web server

VideoView vv = (VideoView)findViewById(R.id.vv);
        vv.setZOrderOnTop(true);

        try {
            MediaController mediacontroller = new MediaController(this);
            mediacontroller.setAnchorView(vv);

            Uri uri = Uri.parse(_video_link);
            vv.setMediaController(mediacontroller);
            vv.setVideoURI(uri);
            vv.seekTo(1);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        vv.requestFocus();
        vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {

                mp.setLooping(true);
                vv.start();

            }
        });
        vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp)
            {
                vv.resume();
            }
        });
thealpha commented 6 years ago

what are you using firebase or what as your backend

pritesh25 commented 6 years ago

i am using php and MySQL as backend

thealpha commented 6 years ago

did you solved or still facing error

thealpha commented 6 years ago

what do you want to compress video or image ...I can I help you

pritesh25 commented 6 years ago

still im facing error , I'm compressing video

thealpha commented 6 years ago

are you compressing image

pritesh25 commented 6 years ago

no , not now because images size is not too much if i compared with video

thealpha commented 6 years ago

use this to compress image it is very use full....

   private Bitmap decodeFile(File f) {
   Bitmap b = null;
    //Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    int IMAGE_MAX_SIZE = 1024;
    int scale = 1;
    if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
        scale = (int) Math.pow(2, (int) Math.ceil(Math.log(IMAGE_MAX_SIZE /
                (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
    }
    //Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    try {
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Log.d(TAG, "Width :" + b.getWidth() + " Height :" + b.getHeight());
    try {
        FileOutputStream out = new FileOutputStream(thumb_filePath);
        b.compress(Bitmap.CompressFormat.JPEG, 50, out);
        out.flush();
        out.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return b;
}
pritesh25 commented 6 years ago

but of i want to compress video then what would you recommend me ?

thealpha commented 6 years ago

for video

pritesh25 commented 6 years ago

yes for video

thealpha commented 6 years ago

wait these types of libraries does not work as you expected I will give you the code....just be calm

pritesh25 commented 6 years ago

ok sure , I'll wait for your response.

thealpha commented 6 years ago

ok good !!

thealpha commented 6 years ago

yo !!! the file is very big how can I send you.... I have the code...how can I send it to you ..it has 7 class

pritesh25 commented 6 years ago

upload the file on Google drive and share the link here or else you can mail me link personally too.

thealpha commented 6 years ago

do u have facebook or Gmail or WhatsApp like thing

pritesh25 commented 6 years ago

yes here i my email priteshvishwakarma@gmail.com mail me on this email id

thealpha commented 6 years ago

okkk done I will send you now

thealpha commented 6 years ago

are you facing this problem

screen shot 2018-05-29 at 1 28 51 pm
thealpha commented 6 years ago

like your video cannot be played through download url

pritesh25 commented 6 years ago

yes video is not playing from the URL specially when the video is compressed and uploaded to the web server , file is completely uploaded to the web server I check the file size and everything , everything is working perfectly. but compressed video file is not playing through the URL

thealpha commented 6 years ago

how did you get that compressed file from compress video()

pritesh25 commented 6 years ago

i use this compression technique (sillicompression)

thealpha commented 6 years ago

https://github.com/RudreshJR/VideoCompression/blob/master/app/src/main/java/com/rudresh/videocompression/MainActivity.java

this link helps you see this if there is problem just come here we will talk about that

thealpha commented 6 years ago

or https://github.com/lalongooo/VideoCompressor this library by telegram

thealpha commented 6 years ago

SiliCompressor.with(Context).compressVideo(sourceVideoUri, destionationDirPath);

what should I pass here i am getting error ...he said that I should pass videouri, and file path but see

thealpha commented 6 years ago

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mediaRecorder.setVideoEncodingBitRate(690000); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mediaRecorder.setVideoFrameRate(30); mediaRecorder.setVideoSize(640, 480); this code will hep to compress even crappy but you can set quality of video

thealpha commented 6 years ago

why am I getting this error UrisyntexException() wtf

pritesh25 commented 6 years ago

i already used this https://github.com/lalongooo/VideoCompressor library also but after using any compression technique to compress video file. that compressed video file not stream from the live web server (it work perfectly work in localhost).

Tourenathan-G5organisation commented 6 years ago

Hi @pritesh25, i don't think the problem is with SilliCompressor, because the video plays locally. Please check your file upload method. Also, try to upload the video file without compressing and see if it will play from the web server.

pritesh25 commented 6 years ago

I know video is playing locally but it is not playing when it is uploaded on the live server.

skill20 commented 6 years ago

compressed video file is not playing through the URL when i use ijk player, when i use default player video url is playing ok。

pritesh25 commented 6 years ago

you mean default player as a [VideoView ](https://developer.android.com/reference/android/widget/VideoView)???

SaadShafiq commented 4 years ago

Hi @pritesh25, i don't think the problem is with SilliCompressor, because the video plays locally. Please check your file upload method. Also, try to upload the video file without compressing and see if it will play from the web server.

Can you guys please help me? my video is not playing locally after compression @Tourenathan-G5organisation @pritesh25

Mr-Ramzan commented 4 years ago

Hi @pritesh25, i don't think the problem is with SilliCompressor, because the video plays locally. Please check your file upload method. Also, try to upload the video file without compressing and see if it will play from the web server.

Can you guys please help me? my video is not playing locally after compression @Tourenathan-G5organisation @pritesh25

@SaadShafiq did you resolved that issue? Even the sample project's compressed video is not playable nither on the device not pc.

SahilKashyap commented 4 years ago

Hi, Did anyone resolve this issue...?.."Video not streaming from web url after compression."

s-komaragiri commented 3 years ago

Does anyone have a suggested solution for this ?

NiharDodiya commented 3 years ago

private Bitmap decodeFile(File f) { Bitmap b = null; //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = null; try { fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int IMAGE_MAX_SIZE = 1024; int scale = 1; if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.ceil(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; try { fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(TAG, "Width :" + b.getWidth() + " Height :" + b.getHeight()); try { FileOutputStream out = new FileOutputStream(thumb_filePath); b.compress(Bitmap.CompressFormat.JPEG, 50, out); out.flush(); out.close();

} catch (Exception e) {
    e.printStackTrace();
}
return b;

}

Code working perfectly