اذهب إلى المحتوى
  • 0

ممكن حد يصححلى الكود ويتابع معايا لحد مايشتغل بالشكل الصحيح

Drive Man

السؤال

 
    public void convert2() throws IOException {
        dila = ProgressDialog.show(uploadved.this, "برجاء الانتظار", "جاري تجهيز الفيديو");

        File videoFile = new File(videoUri.toString());
        if (videoFile.exists()) {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            retriever.setDataSource(videoFile.getPath());
            String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
            Log.e("tyyyyy", "h" + height);
            String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
            Log.e("tyyyyy", "w" + width);
            w = Integer.parseInt(width);
            h = Integer.parseInt(height);

            int quality = w * h / 1024 * 1024 / 1000;
            qul = String.valueOf(quality);
            Log.e("tyyyyy", qul);
            retriever.release();
            if (h > 1024) {
                try {
                    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName + ".mp4");
                    file.createNewFile();
                    String outputPath = file.getPath().toString();
                    Log.d("tyyyyy", "outpath is " + outputPath);

                    retriever.setDataSource(videoFile.getPath());
                    Bitmap bmp = retriever.getFrameAtTime();
                    int newWidth = 576;
                    int newHeight = 1024;
                    Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true);
                    retriever.release();

                    // Save the video to the phone
                    MediaMuxer muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

// Add the video track
                    int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(outputPath, newWidth, newHeight));
                    String aduo = String.valueOf(videoTrackIndex);
                    Log.e("tyyyyy", "videoResolution" + "=" + aduo);

// Add the audio track
                    int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(outputPath, 44100, 2));
                    String adad = String.valueOf(audioTrackIndex);
                    Log.e("tyyyyy", "videoResolution" + "=" + adad);

// Start writing to the muxer
                    muxer.start();

// Write the video frames to the muxer
                    ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024);
                    int[] pixels = new int[resizedBmp.getWidth() * resizedBmp.getHeight()];

                    for (int i = 0; i < resizedBmp.getHeight(); i++) {
                        buffer.clear();
                        resizedBmp.getPixels(pixels, 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight());
                        byte[] bytes = new byte[buffer.limit()];
                        for (int j = 0; j < bytes.length; j++) {
                            bytes[j] = buffer.get(j);
                        }

                        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
                        info.offset = 0;
                        info.size = bytes.length;

                        muxer.writeSampleData(videoTrackIndex, buffer, info);
                    }

// Write the audio samples to the muxer
                    short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()];
                    int[] intSamples = new int[samples.length];

                    for (int i = 0; i < resizedBmp.getHeight(); i++) {
                        buffer.clear();
                        resizedBmp.getPixels(intSamples, 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight());
                        for (int j = 0; j < samples.length; j++) {
                            buffer.putShort((short) intSamples[j]);
                        }
                        byte[] bytes = buffer.array();
                        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
                        info.offset = 0;
                        info.size = bytes.length;

                        muxer.writeSampleData(audioTrackIndex, buffer, info);
                    }

// Stop writing to the muxer
                    muxer.stop();
                    muxer.release();
                    uritoupload = Uri.parse(outputPath);
                    vedgetr.setMediaController(new MediaController(this));
                    dila.dismiss();
                    vedgetr.setVideoURI(uritoupload);
                    vedgetr.start();
                } catch (IOException e) {
                    Log.e("tyyyyy", "catch" + e.getMessage().toString());
                }
            } else if (w > 576) {
                try {


                    Bitmap bmp = retriever.getFrameAtTime();
                    int newWidth = 576;
                    int newHeight = 1024;
                    Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true);
                    retriever.release();
                    File newVideoFile = new File(Environment.getExternalStorageDirectory(), "new_video.mp4");

                    // Save the video to the phone
                    MediaMuxer muxer = new MediaMuxer(newVideoFile.getPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

                    // Add the video track
                    int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(newVideoFile.getPath(), newWidth, newHeight));
                    String aduo = String.valueOf(videoTrackIndex);
                    Log.e("tyyyyy", "videoResolution" + "=" + aduo);
                    // Add the audio track
                    int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(newVideoFile.getPath(), 44100, 2));
                    String adad = String.valueOf(videoTrackIndex);
                    Log.e("tyyyyy", "videoResolution" + "=" + adad);
                    // Start writing to the muxer
                    muxer.start();

                    // Write the video frames to the muxer
                    ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024);
                    int[] pixels = new int[resizedBmp.getWidth() * resizedBmp.getHeight()];

                    for (int i = 0; i < resizedBmp.getHeight(); i++) {
                        buffer.clear();
                        resizedBmp.getPixels(pixels, 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight());
                        byte[] bytes = new byte[buffer.limit()];
                        for (int j = 0; j < bytes.length; j++) {
                            bytes[j] = buffer.get(j);
                        }

                        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
                        info.offset = 0;
                        info.size = bytes.length;

                        muxer.writeSampleData(videoTrackIndex, buffer, info);
                    }

                    // Write the audio samples to the muxer
                    short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()];
                    int[] intSamples = new int[samples.length];

                    for (int i = 0; i < resizedBmp.getHeight(); i++) {
                        buffer.clear();
                        resizedBmp.getPixels(intSamples, 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight());
                        for (int j = 0; j < samples.length; j++) {
                            buffer.putShort((short) intSamples[j]);
                        }
                        byte[] bytes = buffer.array();
                        MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
                        info.offset = 0;
                        info.size = bytes.length;

                        muxer.writeSampleData(audioTrackIndex, buffer, info);
                    }

                    // Stop writing to the muxer
                    muxer.stop();
                    muxer.release();
                    uritoupload = Uri.parse(newVideoFile.getPath());

                    vedgetr.setMediaController(new MediaController(this));
                    dila.dismiss();
                    vedgetr.setVideoURI(uritoupload);
                    vedgetr.start();
                } catch (IOException e) {
                    Log.e("tyyyyy", "catch" + e.toString());
                }
            } else {
                vedgetr.setMediaController(new MediaController(this));
                dila.dismiss();
                vedgetr.start();
            }
        } else {
            // The video file does not exist
            throw new IllegalArgumentException("The video file does not exist");
        }


    }

ودى رسالة الخطأ 

      enableLogLight: enable = false
WindowClient            com.tocrest.a2crest                 Add to mViews: DecorView@9438c40[برجاء الانتظار], this = android.view.WindowManagerGlobal@ac9d1f
OpenGLRenderer          com.tocrest.a2crest                 CanvasContext() 0x7966362080
ViewRootIm... الانتظار] com.tocrest.a2crest                 hardware acceleration is enabled, this = ViewRoot{3c1caff برجاء الانتظار,ident = 7}
AndroidRuntime          com.tocrest.a2crest                 Shutting down VM
--------- beginning of crash
art                     com.tocrest.a2crest                 Attempt to remove non-JNI local reference, dumping thread
AndroidRuntime          com.tocrest.a2crest                 FATAL EXCEPTION: main
                                                            Process: com.tocrest.a2crest, PID: 2997
                                                            java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/video:27122 flg=0x1 }} to activity {com.tocrest.a2crest/com.tocrest.a2crest.vedio.uploadved}: java.lang.IllegalArgumentException: The video file does not exist
                                                            	at android.app.ActivityThread.deliverResults(ActivityThread.java:4547)
                                                            	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4590)
                                                            	at android.app.ActivityThread.-wrap20(ActivityThread.java)
                                                            	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1772)
                                                            	at android.os.Handler.dispatchMessage(Handler.java:110)
                                                            	at android.os.Looper.loop(Looper.java:232)
                                                            	at android.app.ActivityThread.main(ActivityThread.java:6806)
                                                            	at java.lang.reflect.Method.invoke(Native Method)
                                                            	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
                                                            	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
                                                            Caused by: java.lang.IllegalArgumentException: The video file does not exist
                                                            	at com.tocrest.a2crest.vedio.uploadved.convert2(uploadved.java:542)
                                                            	at com.tocrest.a2crest.vedio.uploadved.onActivityResult(uploadved.java:356)
                                                            	at android.app.Activity.dispatchActivityResult(Activity.java:7234)
                                                            	at android.app.ActivityThread.deliverResults(ActivityThread.java:4543)
                                                            	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4590) 
                                                            	at android.app.ActivityThread.-wrap20(ActivityThread.java) 
                                                            	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1772) 
                                                            	at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                            	at android.os.Looper.loop(Looper.java:232) 
                                                            	at android.app.ActivityThread.main(ActivityThread.java:6806) 
                                                            	at java.lang.reflect.Method.invoke(Native Method) 
                                                            	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103) 
                                                            	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
ActivityManager         pid-1396                              Force finishing activity com.tocrest.a2crest/.vedio.uploadved
WindowManager           pid-1396                            Set focused app to: AppWindowToken{6bf3439 token=Token{6089400 ActivityRecord{1b60a83 u0 com.tocrest.a2crest/.vedio.watchervedio t545}}} old focus=AppWindowToken{388b03a token=Token{1146b65 ActivityRecord{a18bc5c u0 com.tocrest.a2crest/.vedio.uploadved t545}}} moveFocusNow=true
Process                 com.tocrest.a2crest                 Sending signal. PID: 2997 SIG: 9
DropBoxManagerService   pid-1396                            file :: /data/system/dropbox/2023@08@02@M6763D_11.A.35_0350_202009032342@com.tocrest.a2crest@data_app_crash@868835034720615_1690951022453_1690951022543.txt.gz
--------- beginning of events
AES                     pid-1396                            onEndOfErrorDumpThread: data_app_crash Process: com.tocrest.a2crest
                                                            Time: 1690951022453
                                                            Flags: 0x28e8be46
                                                            Package: com.tocrest.a2crest v15 (1.15)
                                                            PID: 2997
                                                            Foreground: Yes
                                                            Build: OPPO/CPH1729/CPH1729:7.1.1/N6F26Q/1572535473:user/release-keys
                                                            
                                                            java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/video:27122 flg=0x1 }} to activity {com.tocrest.a2crest/com.tocrest.a2crest.vedio.uploadved}: java.lang.IllegalArgumentException: The video file does not exist
                                                            	at android.app.ActivityThread.deliverResults(ActivityThread.java:4547)
                                                            	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4590)
                                                            	at android.app.ActivityThread.-wrap20(ActivityThread.java)
                                                            	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1772)
                                                            	at android.os.Handler.dispatchMessage(Handler.java:110)
                                                            	at android.os.Looper.loop(Looper.java:232)
                                                            	at android.app.ActivityThread.main(ActivityThread.java:6806)
                                                            	at java.lang.reflect.Method.invoke(Native Method)
                                                            	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
                                                            	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
                                                            Caused by: java.lang.IllegalArgumentException: The video file does not exist
                                                            	at com.tocrest.a2crest.vedio.uploadved.convert2(uploadved.java:542)
                                                            	at com.tocrest.a2crest.vedio.uploadved.onActivityResult(uploadved.java:356)
                                                            	at android.app.Activity.dispatchActivityResult(Activity.java:7234)
                                                            	at android.app.ActivityThread.deliverResults(ActivityThread.java:4543)
                                                            	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4590) 
                                                            	at android.app.ActivityThread.-wrap20(ActivityThread.java) 
                                                            	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1772) 
                                                            	at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                            	at android.os.Looper.loop(Looper.java:232) 
                                                            	at android.app.ActivityThread.main(ActivityThread.java:6806) 
                                                            	at java.lang.reflect.Method.invoke(Native Method) 
                                                            	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103) 
                                                            	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
                                                            
                                                            CPU usage from 315848ms to 0ms ago (٢٠٢٣-٠٨-٠٢ ٠٦:٣١:٤٦.٦٠٧ to ٢٠٢٣-٠٨-٠٢ ٠٦:٣٧:٠٢.٤٥٥):
                                                              5.8% 1396/system_server: 4.2% user + 1.5% kernel / faults: 57043 minor 3629 major
                                                              5.7% 406/surfaceflinger: 3% user + 2.7% kernel / faults: 3428 minor 115 major
                                                              2% 589/media.codec: 0.8% user + 1.2% kernel / faults: 36572 minor 39 major
                                                              2% 618/mediaserver: 1.2% user + 0.7% kernel / faults: 1970 minor 45 major
                                                              1.7% 5026/com.google.android.gms: 1.4% user + 0.3% kernel / faults: 60968 minor 1621 major
                                                              1.2% 15409/adbd: 0.3% user + 0.9% kernel / faults: 11697 minor 4 major
                                                              1.2% 233/exe_cq: 0% user + 1.2% kernel
                                                              0.7% 98/kswapd0: 0% user + 0.7% kernel
                                                              0.6% 30349/com.coloros.safesdkproxy: 0.6% user + 0% kernel / faults: 11446 minor 931 major
                                                              1% 3935/psensord: 0% user + 1% kernel / faults: 13 minor
                                                              0.9% 11274/tx_thread: 0% user + 0.9% kernel
                                                              0.9% 317/logd: 0.3% user + 0.6% kernel / faults: 1814 minor 58 major
                                                              0.8% 235/mmcqd/0: 0% user + 0.8% kernel
                                                              0.6% 12767/com.android.systemui: 0.4% user + 0.1% kernel / faults: 7590 minor 473 major
                                                              0.5% 608/audioserver: 0.3% user + 0.2% kernel / faults: 731 minor 33 major
                                                              0.5% 7/rcu_preempt: 0% user + 0.5% kernel
                                                              0.5% 7377/com.google.android.gms.persistent: 0.3% user + 0.1% kernel / faults: 24368 minor 1306 major
                                                              0.4% 26267/kworker/u16:4: 0% user + 0.4% kernel
                                                              0.4% 12492/com.nearme.statistics.rom: 0.3% user + 0.1% kernel / faults: 9236 minor 604 major
                                                              0.3% 226/ipi_cpu_dvfs_rt: 0% user + 0.3% kernel
                                                              0.3% 24293/kworker/u16:3: 0% user + 0.3% kernel
                                                              0.3% 10387/com.emoji.keyboard.touchpal: 0.3% user + 0% kernel / faults: 15095 minor 625 major
                                                              0.3% 28047/kworker/u16:1: 0% user + 0.3% kernel
                                                              0.3% 32209/kworker/u16:5: 0% user + 0.3% kernel
                                                              0.3% 405/servicemanager: 0.1% user + 0.2% kernel / faults: 103 minor 2 major
                                                              0.3% 587/aal: 0.1% user + 0.2% kernel / faults: 73 minor
                                                              0.3% 31570/kworker/u16:6: 0% user + 0.3% kernel
                                                              0.1% 12387/com.coloros.safecenter:clear_filter: 0.1% user + 0% kernel / faults: 3584 mino
                                                            
                                                            08-02 06:36:54.167  1396  1396 I free_storage_changed: 13987037184
                                                            08-02 06:36:54.597  1396  1515 I netstats_mobile_sample: [903686017,862909,186362558,560307,893944289,675631,186393645,560541,740582713,632604,338812605,603029,-1]
                                                            08-02 06:36:54.599  1396  1515 I netstats_wifi_sample: [6150509506,5131411,704049571,2674338,6078435988,5119481,666533956,2662971,6078124245,5117191,666521861,2662904,-1
AES                     pid-1396                                process : com.tocrest.a2crest
AES                     pid-1396                                 module : com.tocrest.a2crest v15 (1.15)
AEE_LIBAEE              pid-1396                            shell: raise_exp(4, 2997, -1361051648, com.tocrest.a2crest, 0x0x79f8ffad60, 0x0x0)
AEE_AED                 pid-4004                              Process:com.tocrest.a2crest

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

لا توجد أي إجابات على هذا السؤال بعد

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...