-
المساهمات
26 -
تاريخ الانضمام
-
تاريخ آخر زيارة
آخر الزوار
لوحة آخر الزوار معطلة ولن تظهر للأعضاء
إنجازات Drive Man
عضو مساهم (2/3)
9
السمعة بالموقع
-
package com.tocrest.a2crest.vedio; import android.Manifest; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.media.MediaCodec; import android.media.MediaFormat; import android.media.MediaMetadataRetriever; import android.media.MediaMuxer; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ImageView; import android.widget.MediaController; import android.widget.ProgressBar; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.VideoView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import com.android.volley.AuthFailureError; import com.android.volley.DefaultRetryPolicy; import com.android.volley.NetworkResponse; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.Volley; import com.bumptech.glide.Glide; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; import com.makeramen.roundedimageview.RoundedImageView; import com.tocrest.a2crest.Dialog.difroved; import com.tocrest.a2crest.R; import com.tocrest.a2crest.shall; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @SuppressWarnings("ALL") public class uploadved extends AppCompatActivity implements difroved.ExampleDialogeListener { TextView uploader; RoundedImageView geter; VideoView vedgetr; MediaController mc; File file; String wasfst; String realPath; String mohtst; String qul; int progstat = 0; int w; int h; TextView shertved; ImageView ext, imgvedto; EditText edtanwan, edtwasf; Spinner spmraddafo; BottomSheetDialog bottomSheetDialog; private RequestQueue rQueue; private static final int SELECT_VIDEO_REQUEST = 0; public Uri videoUri; String displayName; String Path; ExecutorService service; String enwanvido; int fileLength; Context context; boolean check = true; public Bitmap bitmap; ImageView trimVideo, slowmotion; TextView slowmotiontext; private ProgressBar progressBar; Dialog dila; Uri uritoupload; ////////////////ROTH test ///////////////////// int videoResolution; Uri inputPath ; String outputPath; int width = 576; int height = 1024; private static final int REQUEST_FOR_VIDEO_FILE = 1000; private TextView tv_input, tv_output, tv_indicator, tv_progress; private String outputDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(); private String inputPath2; private ProgressBar pb_compress; private long startTime, endTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uploadved); geter = findViewById(R.id.geter); uploader = findViewById(R.id.uploader); vedgetr = findViewById(R.id.vedgetr); mc = new MediaController(uploadved.this); vedgetr.setMediaController(mc); geter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ContextCompat.checkSelfPermission(uploadved.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { selectVideo(); } else { ActivityCompat.requestPermissions(uploadved.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } } }); private void selectVideo() { Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.EXTERNAL_CONTENT_URI); intent.setType("video/*"); // intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult( Intent.createChooser(intent, "Select Video"), SELECT_VIDEO_REQUEST); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult( requestCode, permissions, grantResults); // check condition if (requestCode == 1 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { selectVideo(); } else { Toast.makeText(getApplicationContext(), "Permission Denied !", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == SELECT_VIDEO_REQUEST && resultCode == RESULT_OK && data != null) { videoUri = data.getData(); displayName = String.valueOf(Calendar.getInstance().getTimeInMillis()); MediaPlayer mp = MediaPlayer.create(this, videoUri); Log.e("tyyyyy", "viduritost"+"="+videoUri.toString()); Log.e("tyyyyy", "viduripathtost"+"="+videoUri.getPath().toString()); file=new File(videoUri.getPath()); realPath =data.getDataString(); Log.e("tyyyyy", "videopath"+realPath); int duration = mp.getDuration(); mp.release(); String durationStr = String.format("%d", TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))); String durationStr2 = String.format("%d", TimeUnit.MILLISECONDS.toMinutes(duration)); try { convert3(); } catch (IOException e) { throw new RuntimeException(e); } outputPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "compressed_video.mp4"; width = 576; height = 1024; file=new File(videoUri.getPath()); String filePath = file.getAbsolutePath().toString(); inputPath=videoUri; Path=filePath; Log.d("tyyyyy","PATH URI IS ="+videoUri.getPath().toString()); } } public void convert3() throws IOException { dila = ProgressDialog.show(uploadved.this, "برجاء الانتظار", "جاري تجهيز الفيديو"); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(uploadved.this, videoUri); String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); int w = Integer.parseInt(width); int h = Integer.parseInt(height); int quality = w*h/1024*1024; String qul = String.valueOf(quality); Log.e("tyyyyy", "videoResolution = " + qul); Log.e("tyyyyy", "hi = " +height); Log.e("tyyyyy", "wi = " +width); retriever.release(); if (h > 1024) { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName + ".mp4"); String outputPath = file.getPath(); String rettopatha=videoUri.getPath().toString(); Log.d("tyyyyy","rettopath"+"="+rettopatha); Bitmap bmp = retriever.getFrameAtTime(); int newWidth = 576; int newHeight = 1024; Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true); retriever.release(); MediaMuxer muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); // Add the video track int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, newWidth, newHeight)); Log.e("tyyyyy", "videoResolution = " + videoTrackIndex); // Add the audio track int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_AAC, 44100, 2)); Log.e("tyyyyy", "audioTrackIndex = " + audioTrackIndex); muxer.start(); // Write the video frames to the muxer ByteBuffer buffer = ByteBuffer.allocateDirect(resizedBmp.getByteCount()); resizedBmp.copyPixelsToBuffer(buffer); buffer.flip(); MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); info.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME; info.offset = 0; muxer.writeSampleData(videoTrackIndex, buffer, info); // Write the audio samples to the muxer short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()]; buffer.clear(); buffer.asShortBuffer().put(samples); buffer.flip(); info = new MediaCodec.BufferInfo(); info.offset = 0; info.size = buffer.remaining(); muxer.writeSampleData(audioTrackIndex, buffer, info); muxer.stop(); muxer.release(); Uri 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()); } } else if (w > 576) { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName + ".mp4"); String outputPath = file.getPath(); File filea=new File(videoUri.getPath()); retriever.setDataSource(outputPath); Bitmap bmp = retriever.getFrameAtTime(); int newWidth = 576; int newHeight = 1024; Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true); retriever.release(); MediaMuxer muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); // Add the video track int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, newWidth, newHeight)); Log.e("tyyyyy", "videoResolution = " + videoTrackIndex); // Add the audio track int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_AAC, 44100, 2)); Log.e("tyyyyy", "audioTrackIndex = " + audioTrackIndex); muxer.start(); // Write the video frames to the muxer ByteBuffer buffer = ByteBuffer.allocateDirect(resizedBmp.getByteCount()); resizedBmp.copyPixelsToBuffer(buffer); buffer.flip(); MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); info.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME; info.offset = 0; muxer.writeSampleData(videoTrackIndex, buffer, info); // Write the audio samples to the muxer short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()]; buffer.clear(); buffer.asShortBuffer().put(samples); buffer.flip(); info = new MediaCodec.BufferInfo(); info.offset = 0; info.size = buffer.remaining(); muxer.writeSampleData(audioTrackIndex, buffer, info); muxer.stop(); muxer.release(); Uri 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()); } } else { dila.dismiss(); vedgetr.setVideoURI(videoUri); vedgetr.start(); Toast.makeText(this, "try", Toast.LENGTH_SHORT).show(); } } }
-
public void convert3() throws IOException { dila = ProgressDialog.show(uploadved.this, "برجاء الانتظار", "جاري تجهيز الفيديو"); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(uploadved.this, videoUri); String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); int w = Integer.parseInt(width); int h = Integer.parseInt(height); int quality = w*h/1024*1024; String qul = String.valueOf(quality); Log.e("tyyyyy", "videoResolution = " + qul); Log.e("tyyyyy", "hi = " +height); Log.e("tyyyyy", "wi = " +width); retriever.release(); if (h > 1024) { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName + ".mp4"); String outputPath = file.getPath(); String rettopatha=videoUri.getPath().toString(); Log.d("tyyyyy","rettopath"+"="+rettopatha); Bitmap bmp = retriever.getFrameAtTime(); int newWidth = 576; int newHeight = 1024; Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true); retriever.release(); MediaMuxer muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); // Add the video track int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, newWidth, newHeight)); Log.e("tyyyyy", "videoResolution = " + videoTrackIndex); // Add the audio track int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_AAC, 44100, 2)); Log.e("tyyyyy", "audioTrackIndex = " + audioTrackIndex); muxer.start(); // Write the video frames to the muxer ByteBuffer buffer = ByteBuffer.allocateDirect(resizedBmp.getByteCount()); resizedBmp.copyPixelsToBuffer(buffer); buffer.flip(); MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); info.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME; info.offset = 0; muxer.writeSampleData(videoTrackIndex, buffer, info); // Write the audio samples to the muxer short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()]; buffer.clear(); buffer.asShortBuffer().put(samples); buffer.flip(); info = new MediaCodec.BufferInfo(); info.offset = 0; info.size = buffer.remaining(); muxer.writeSampleData(audioTrackIndex, buffer, info); muxer.stop(); muxer.release(); Uri 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()); } } else if (w > 576) { try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), displayName + ".mp4"); String outputPath = file.getPath(); File filea=new File(videoUri.getPath()); retriever.setDataSource(outputPath); Bitmap bmp = retriever.getFrameAtTime(); int newWidth = 576; int newHeight = 1024; Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true); retriever.release(); MediaMuxer muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); // Add the video track int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, newWidth, newHeight)); Log.e("tyyyyy", "videoResolution = " + videoTrackIndex); // Add the audio track int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_AAC, 44100, 2)); Log.e("tyyyyy", "audioTrackIndex = " + audioTrackIndex); muxer.start(); // Write the video frames to the muxer ByteBuffer buffer = ByteBuffer.allocateDirect(resizedBmp.getByteCount()); resizedBmp.copyPixelsToBuffer(buffer); buffer.flip(); MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); info.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME; info.offset = 0; muxer.writeSampleData(videoTrackIndex, buffer, info); // Write the audio samples to the muxer short[] samples = new short[resizedBmp.getWidth() * resizedBmp.getHeight()]; buffer.clear(); buffer.asShortBuffer().put(samples); buffer.flip(); info = new MediaCodec.BufferInfo(); info.offset = 0; info.size = buffer.remaining(); muxer.writeSampleData(audioTrackIndex, buffer, info); muxer.stop(); muxer.release(); Uri 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()); } } else { dila.dismiss(); vedgetr.setVideoURI(videoUri); vedgetr.start(); Toast.makeText(this, "try", Toast.LENGTH_SHORT).show(); } }
-
@SuppressWarnings("ALL") public class uploadved extends AppCompatActivity implements difroved.ExampleDialogeListener { TextView uploader; RoundedImageView geter; VideoView vedgetr; MediaController mc; File file; String wasfst; String mohtst; String qul; int progstat = 0; int w; int h; TextView shertved; ImageView ext, imgvedto; EditText edtanwan, edtwasf; Spinner spmraddafo; BottomSheetDialog bottomSheetDialog; private RequestQueue rQueue; private static final int SELECT_VIDEO_REQUEST = 0; public Uri videoUri; String displayName; String Path; ExecutorService service; String enwanvido; int fileLength; Context context; String URLphp = "https://elokhtboot.com/okt/Nashr/uploadved.php"; boolean check = true; public Bitmap bitmap; ImageView trimVideo, slowmotion; TextView slowmotiontext; private ProgressBar progressBar; Dialog dila; Uri uritoupload; ////////////////ROTH test ///////////////////// int videoResolution; Uri inputPath ; String outputPath; int width = 576; int height = 1024; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uploadved); geter = findViewById(R.id.geter); uploader = findViewById(R.id.uploader); vedgetr = findViewById(R.id.vedgetr); mc = new MediaController(uploadved.this); vedgetr.setMediaController(mc); geter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ContextCompat.checkSelfPermission(uploadved.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { selectVideo(); } else { ActivityCompat.requestPermissions(uploadved.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } } }); uploader.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (videoUri != null) { bottomSheetDialog = new BottomSheetDialog(uploadved.this, R.style.BottomSheetDialogTheme2); View va = LayoutInflater.from(uploadved.this) .inflate(R.layout.veduploadbotorrsheet, uploadved.this.findViewById(R.id.btomCount)); bottomSheetDialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED); v.setMinimumHeight(Resources.getSystem().getDisplayMetrics().heightPixels); shertved = va.findViewById(R.id.shertved); ext = va.findViewById(R.id.ext); imgvedto = va.findViewById(R.id.imgvedto); edtanwan = va.findViewById(R.id.edtanwan); edtwasf = va.findViewById(R.id.edtwasf); spmraddafo = va.findViewById(R.id.spmraddafo); edtanwan.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { enwanvido = edtanwan.getText().toString().trim(); Log.d("enwan", enwanvido); int t = enwanvido.length(); if (t > 1) { t = 1; } if (t > 40) { t = 250; } if (t > 250) { t = 250; } switch (t) { case 0: edtanwan.setBackgroundResource(R.drawable.backwrong); shertved.setVisibility(View.GONE); Toast.makeText(uploadved.this, "يجب اضافة عنوان للفيديو", Toast.LENGTH_SHORT).show(); break; case 1: edtanwan.setBackgroundResource(R.drawable.edenwanved); shertved.setVisibility(View.VISIBLE); shertved.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { uploadvideo(displayName, videoUri); } }); break; case 250: edtanwan.setBackgroundResource(R.drawable.backwrong); shertved.setVisibility(View.GONE); Toast.makeText(uploadved.this, "عدد الاحرف اكثر من اللازم", Toast.LENGTH_SHORT).show(); break; default: edtanwan.setBackgroundResource(R.drawable.edenwanved); shertved.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { uploadvideo(displayName, videoUri); } }); break; } } @Override public void afterTextChanged(Editable s) { } }); edtwasf.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { wasfst = edtwasf.getText().toString().trim(); Log.d("enwan", wasfst); int t = wasfst.length(); if (t > 1) { t = 1; } if (t > 155) { t = 155; } switch (t) { case 0: edtwasf.setBackgroundResource(R.drawable.backwrong); shertved.setVisibility(View.GONE); break; case 1: edtwasf.setBackgroundResource(R.drawable.edenwanved); shertved.setVisibility(View.VISIBLE); shertved.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { uploadvideo(displayName, videoUri); } }); break; case 250: edtwasf.setBackgroundResource(R.drawable.backwrong); shertved.setVisibility(View.GONE); break; default: edtwasf.setBackgroundResource(R.drawable.edenwanved); shertved.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { uploadvideo(displayName, videoUri); ////Here is where the user can click to execute the upload order } }); break; } } @Override public void afterTextChanged(Editable s) { } }); spmraddafo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mohtst = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { mohtst = "غير ذلك"; } }); Glide.with(imgvedto).load(videoUri).into(imgvedto); ext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bottomSheetDialog.dismiss(); } }); bottomSheetDialog.setContentView(va); bottomSheetDialog.show(); } else { Toast.makeText(uploadved.this, "من فضلك قم باختيار فيديو", Toast.LENGTH_SHORT).show(); } } }); }//////////////////////////////////////////////////// // This method converts the video. /////////////////////////////////////////////////// private void selectVideo() { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult( Intent.createChooser(intent, "Select Video"), SELECT_VIDEO_REQUEST); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult( requestCode, permissions, grantResults); // check condition if (requestCode == 1 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { selectVideo(); } else { Toast.makeText(getApplicationContext(), "Permission Denied !", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100 && resultCode == RESULT_OK && data != null) { videoUri = data.getData(); displayName = String.valueOf(Calendar.getInstance().getTimeInMillis() + ".mp4"); MediaPlayer mp = MediaPlayer.create(this, videoUri); videoUri = data.getData(); String videoPath = videoUri.getPath(); Log.e("tyyyyy", videoPath); int duration = mp.getDuration(); mp.release(); String durationStr = String.format("%d", TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))); String durationStr2 = String.format("%d", TimeUnit.MILLISECONDS.toMinutes(duration)); outputPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "compressed_video.mp4"; width = 576; height = 1024; file=new File(videoUri.getPath()); String filePath = file.getAbsolutePath().toString(); inputPath=videoUri; Path=filePath; vedgetr.setVideoURI(videoUri); vedgetr.start(); Log.d("tyyyyy",filePath); /* try { resizeVideo(inputPath, outputPath, width, height); //vedgetr.setVideoPath(outputPath); // vedgetr.start(); } catch (IOException e) { throw new RuntimeException(e); }*/ /*String outputPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "compressed_video.mp4"; String path = videoUri.getPath().toString(); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(this,videoUri); 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); int w = Integer.parseInt(width); int h = Integer.parseInt(height); int quality = w*h/1024 * 1024/1000; String qul= String.valueOf(quality); Log.e("tyyyyy", qul); // Display the video quality Log.e("tyyyyy", outputPath); file =new File(Path); String inputpath=file.getPath().toString(); String filePath = file.getAbsolutePath().toString(); Log.e("tyyyyy", filePath);*/ try { convert2(); } catch (IOException e) { throw new RuntimeException(e); } } } public void convert2() throws IOException { dila = ProgressDialog.show(uploadved.this, "برجاء الانتظار", "جاري تجهيز الفيديو"); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(uploadved.this,videoUri); 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(uploadved.this,videoUri); 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(); } }
-
- 1
-
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
-
newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_YEAR); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_MIMETYPE); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DISC_NUMBER); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_NUM_TRACKS); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_WRITER); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_COMPILATION); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_HAS_AUDIO); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_HAS_VIDEO); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_HAS_IMAGE); newRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_HAS_BINARY);**Cannot resolve symbol 'METADATA_KEY_HAS_BINARY' newRetriever.setOption("vf", "scale=" + targetWidth + ":" + newHeight);**Cannot resolve method 'setOption' in 'FFmpegMediaMetadataRetriever' newRetriever.setOption("override_ffmpeg_path", getApplicationInfo().dataDir + "/lib");**Cannot resolve method 'setOption' in 'FFmpegMediaMetadataRetriever' newRetriever.save(newFile.getAbsolutePath());**Cannot resolve method 'setOption' in 'FFmpegMediaMetadataRetriever' // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package wseemann.media; import android.content.ContentResolver; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.MediaDataSource; import android.net.Uri; import android.util.Log; import androidx.annotation.RequiresApi; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.TimeZone; public class FFmpegMediaMetadataRetriever { private static final String TAG = "FMMR"; public static Bitmap.Config IN_PREFERRED_CONFIG; private static final String[] JNI_LIBRARIES = new String[]{"crypto", "ssl", "avutil", "swscale", "avcodec", "avformat", "ffmpeg_mediametadataretriever_jni"}; private long mNativeContext; public static final int OPTION_PREVIOUS_SYNC = 0; public static final int OPTION_NEXT_SYNC = 1; public static final int OPTION_CLOSEST_SYNC = 2; public static final int OPTION_CLOSEST = 3; public static final String METADATA_KEY_ALBUM = "album"; public static final String METADATA_KEY_ALBUM_ARTIST = "album_artist"; public static final String METADATA_KEY_ARTIST = "artist"; public static final String METADATA_KEY_COMMENT = "comment"; public static final String METADATA_KEY_COMPOSER = "composer"; public static final String METADATA_KEY_COPYRIGHT = "copyright"; public static final String METADATA_KEY_CREATION_TIME = "creation_time"; public static final String METADATA_KEY_DATE = "date"; public static final String METADATA_KEY_DISC = "disc"; public static final String METADATA_KEY_ENCODER = "encoder"; public static final String METADATA_KEY_ENCODED_BY = "encoded_by"; public static final String METADATA_KEY_FILENAME = "filename"; public static final String METADATA_KEY_GENRE = "genre"; public static final String METADATA_KEY_LANGUAGE = "language"; public static final String METADATA_KEY_PERFORMER = "performer"; public static final String METADATA_KEY_PUBLISHER = "publisher"; public static final String METADATA_KEY_SERVICE_NAME = "service_name"; public static final String METADATA_KEY_SERVICE_PROVIDER = "service_provider"; public static final String METADATA_KEY_TITLE = "title"; public static final String METADATA_KEY_TRACK = "track"; public static final String METADATA_KEY_VARIANT_BITRATE = "bitrate"; public static final String METADATA_KEY_DURATION = "duration"; public static final String METADATA_KEY_AUDIO_CODEC = "audio_codec"; public static final String METADATA_KEY_VIDEO_CODEC = "video_codec"; public static final String METADATA_KEY_VIDEO_ROTATION = "rotate"; public static final String METADATA_KEY_ICY_METADATA = "icy_metadata"; public static final String METADATA_KEY_FRAMERATE = "framerate"; public static final String METADATA_KEY_CHAPTER_START_TIME = "chapter_start_time"; public static final String METADATA_KEY_CHAPTER_END_TIME = "chapter_end_time"; public static final String METADATA_CHAPTER_COUNT = "chapter_count"; public static final String METADATA_KEY_FILESIZE = "filesize"; public static final String METADATA_KEY_VIDEO_WIDTH = "video_width"; public static final String METADATA_KEY_VIDEO_HEIGHT = "video_height"; public FFmpegMediaMetadataRetriever() { this.native_setup(); } public native void setDataSource(String var1) throws IllegalArgumentException; public void setDataSource(String uri, Map<String, String> headers) throws IllegalArgumentException { int i = 0; String[] keys = new String[headers.size()]; String[] values = new String[headers.size()]; for(Iterator var6 = headers.entrySet().iterator(); var6.hasNext(); ++i) { Map.Entry<String, String> entry = (Map.Entry)var6.next(); keys[i] = (String)entry.getKey(); values[i] = (String)entry.getValue(); } this._setDataSource(uri, keys, values); } private native void _setDataSource(String var1, String[] var2, String[] var3) throws IllegalArgumentException; public native void setDataSource(FileDescriptor var1, long var2, long var4) throws IllegalArgumentException; public void setDataSource(FileDescriptor fd) throws IllegalArgumentException { this.setDataSource(fd, 0L, 576460752303423487L); } public void setDataSource(Context context, Uri uri) throws IllegalArgumentException, SecurityException { if (uri == null) { throw new IllegalArgumentException(); } else { String scheme = uri.getScheme(); if (scheme != null && !scheme.equals("file")) { AssetFileDescriptor fd = null; label128: { try { ContentResolver resolver = context.getContentResolver(); try { fd = resolver.openAssetFileDescriptor(uri, "r"); } catch (FileNotFoundException var17) { throw new IllegalArgumentException(); } if (fd == null) { throw new IllegalArgumentException(); } FileDescriptor descriptor = fd.getFileDescriptor(); if (!descriptor.valid()) { throw new IllegalArgumentException(); } if (fd.getDeclaredLength() < 0L) { this.setDataSource(descriptor); } else { this.setDataSource(descriptor, fd.getStartOffset(), fd.getDeclaredLength()); } } catch (SecurityException var18) { Log.e("FMMR", "SecurityException: ", var18); break label128; } finally { try { if (fd != null) { fd.close(); } } catch (IOException var16) { Log.e("FMMR", "IOException: ", var16); } } return; } this.setDataSource(uri.toString()); } else { this.setDataSource(uri.getPath()); } } } @RequiresApi(23) public void setDataSource(MediaDataSource dataSource) throws IllegalArgumentException { this._setDataSource(dataSource); } private native void _setDataSource(MediaDataSource var1) throws IllegalArgumentException; public native String extractMetadata(String var1); public native String extractMetadataFromChapter(String var1, int var2); public Metadata getMetadata() { Metadata data = new Metadata(); HashMap metadata; if ((metadata = this.native_getMetadata(false, false, (HashMap)null)) == null) { return null; } else { return !data.parse(metadata) ? null : data; } } private final native HashMap<String, String> native_getMetadata(boolean var1, boolean var2, HashMap<String, String> var3); public Bitmap getFrameAtTime(long timeUs, int option) { if (option >= 0 && option <= 3) { Bitmap b = null; BitmapFactory.Options bitmapOptionsCache = new BitmapFactory.Options(); bitmapOptionsCache.inDither = false; byte[] picture = this._getFrameAtTime(timeUs, option); if (picture != null) { b = BitmapFactory.decodeByteArray(picture, 0, picture.length, bitmapOptionsCache); } return b; } else { throw new IllegalArgumentException("Unsupported option: " + option); } } public Bitmap getFrameAtTime(long timeUs) { Bitmap b = null; BitmapFactory.Options bitmapOptionsCache = new BitmapFactory.Options(); bitmapOptionsCache.inDither = false; byte[] picture = this._getFrameAtTime(timeUs, 2); if (picture != null) { b = BitmapFactory.decodeByteArray(picture, 0, picture.length, bitmapOptionsCache); } return b; } public Bitmap getFrameAtTime() { return this.getFrameAtTime(-1L, 2); } private native byte[] _getFrameAtTime(long var1, int var3); public Bitmap getScaledFrameAtTime(long timeUs, int option, int width, int height) { if (option >= 0 && option <= 3) { Bitmap b = null; BitmapFactory.Options bitmapOptionsCache = new BitmapFactory.Options(); bitmapOptionsCache.inDither = false; byte[] picture = this._getScaledFrameAtTime(timeUs, option, width, height); if (picture != null) { b = BitmapFactory.decodeByteArray(picture, 0, picture.length, bitmapOptionsCache); } return b; } else { throw new IllegalArgumentException("Unsupported option: " + option); } } public Bitmap getScaledFrameAtTime(long timeUs, int width, int height) { Bitmap b = null; BitmapFactory.Options bitmapOptionsCache = new BitmapFactory.Options(); bitmapOptionsCache.inDither = false; byte[] picture = this._getScaledFrameAtTime(timeUs, 2, width, height); if (picture != null) { b = BitmapFactory.decodeByteArray(picture, 0, picture.length, bitmapOptionsCache); } return b; } private native byte[] _getScaledFrameAtTime(long var1, int var3, int var4, int var5); public native byte[] getEmbeddedPicture(); public native void release(); private native void native_setup(); private static native void native_init(); private final native void native_finalize(); protected void finalize() throws Throwable { try { this.native_finalize(); } finally { super.finalize(); } } public native void setSurface(Object var1); static { String[] var0 = JNI_LIBRARIES; int var1 = var0.length; for(int var2 = 0; var2 < var1; ++var2) { String jniLibrary = var0[var2]; System.loadLibrary(jniLibrary); } native_init(); } public class Metadata { public static final int STRING_VAL = 1; public static final int INTEGER_VAL = 2; public static final int BOOLEAN_VAL = 3; public static final int LONG_VAL = 4; public static final int DOUBLE_VAL = 5; public static final int DATE_VAL = 6; public static final int BYTE_ARRAY_VAL = 7; private HashMap<String, String> mParcel; public Metadata() { } public boolean parse(HashMap<String, String> metadata) { if (metadata == null) { return false; } else { this.mParcel = metadata; return true; } } public boolean has(String metadataId) { if (!this.checkMetadataId(metadataId)) { throw new IllegalArgumentException("Invalid key: " + metadataId); } else { return this.mParcel.containsKey(metadataId); } } public HashMap<String, String> getAll() { return this.mParcel; } public String getString(String key) { this.checkType(key, 1); return String.valueOf(this.mParcel.get(key)); } public int getInt(String key) { this.checkType(key, 2); return Integer.valueOf((String)this.mParcel.get(key)); } public boolean getBoolean(String key) { this.checkType(key, 3); return Integer.valueOf((String)this.mParcel.get(key)) == 1; } public long getLong(String key) { this.checkType(key, 4); return Long.valueOf((String)this.mParcel.get(key)); } public double getDouble(String key) { this.checkType(key, 5); return Double.valueOf((String)this.mParcel.get(key)); } public byte[] getByteArray(String key) { this.checkType(key, 7); return ((String)this.mParcel.get(key)).getBytes(); } public Date getDate(String key) { this.checkType(key, 6); long timeSinceEpoch = Long.valueOf((String)this.mParcel.get(key)); String timeZone = (String)this.mParcel.get(key); if (timeZone.length() == 0) { return new Date(timeSinceEpoch); } else { TimeZone tz = TimeZone.getTimeZone(timeZone); Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(timeSinceEpoch); return cal.getTime(); } } private boolean checkMetadataId(String val) { return true; } private void checkType(String key, int expectedType) { String type = (String)this.mParcel.get(key); if (type == null) { throw new IllegalStateException("Wrong type " + expectedType + " but got " + type); } } } }
-
public void convert() throws IOException { String videoPath = "/sdcard/input.mp4"; // Get the video resolution MediaMetadataRetriever retriever = new MediaMetadataRetriever(); int videoResolution = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); // If the video resolution is higher than 360p, downscale it to 360p if (videoResolution > 360) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(videoPath); Bitmap bmp = retriever.getFrameAtTime(); int newWidth = 360; int newHeight = (int) (bmp.getHeight() * newWidth / bmp.getWidth()); Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true); retriever.release(); // Save the video to the phone MediaMuxer muxer = null; try { muxer = new MediaMuxer(videoPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); // Add the video track int videoTrackIndex = muxer.addTrack(MediaFormat.createVideoFormat(videoPath, newWidth, newHeight)); // Add the audio track int audioTrackIndex = muxer.addTrack(MediaFormat.createAudioFormat(videoPath, 44100, 2)); // Start writing to the muxer muxer.start(); // Write the video frames to the muxer ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024); for (int i = 0; i < resizedBmp.getHeight(); i++) { buffer.clear(); resizedBmp.getPixels(buffer.array(), 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight()); byte[] bytes = ByteBuffer.wrap(buffer.array()).asByteArray(); muxer.writeSampleData(videoTrackIndex, bytes, bytes.length); } // Write the audio samples to the muxer for (int i = 0; i < resizedBmp.getHeight(); i++) { buffer.clear(); resizedBmp.getPixels(buffer.array(), 0, resizedBmp.getWidth(), 0, i, resizedBmp.getWidth(), resizedBmp.getHeight()); byte[] bytes = ByteBuffer.wrap(buffer.array()).asByteArray(); muxer.writeSampleData(audioTrackIndex, bytes, bytes.length); } // Stop writing to the muxer muxer.stop(); muxer.release(); } catch (IOException e) { Log.e("MainActivity", "Error writing to muxer", e); } } // Set the video view's media controller vedgetr.setMediaController(new MediaController(this)); // Set the video view's video path vedgetr.setVideoPath(videoPath); // Start playing the video vedgetr.start(); }
- 1 جواب
-
- 1
-
حد يقدر يساعدنى فى كتابة كود يخلى اشوف جودة الفيديو لو اعلى من 360 بكسل احول جودة الفيديو 360 بكسل واحفظة على التليفون وبعد كده اشغل الفيديو الجديد
- 5 اجابة
-
- 1
-
ytr.bmp
-
geter = findViewById(R.id.geter); uploader = findViewById(R.id.uploader); vedgetr = findViewById(R.id.vedgetr); //////////////////ffmg/////////////////// mc = new MediaController(uploadved.this); vedgetr.setMediaController(mc); geter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check condition if (ContextCompat.checkSelfPermission( uploadved.this, Manifest.permission .WRITE_EXTERNAL_STORAGE) == PackageManager .PERMISSION_GRANTED) { // When permission is granted // Create method selectVideo(); } else { // When permission is not granted // request permission ActivityCompat.requestPermissions( uploadved.this, new String[] { Manifest.permission .WRITE_EXTERNAL_STORAGE }, 1); } } }); private void selectVideo() { Intent intent = new Intent(Intent.ACTION_PICK); // Set type intent.setType("video/*"); // set action intent.setAction(Intent.ACTION_GET_CONTENT); // Start activity result startActivityForResult( Intent.createChooser(intent, "Select Video"), 100); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult( requestCode, permissions, grantResults); // check condition if (requestCode == 1 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // When permission is granted // Call method selectVideo(); } else { // When permission is denied // Display Toast Toast .makeText(getApplicationContext(), "Permission Denied !", Toast.LENGTH_SHORT) .show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); // Check condition if (requestCode == 100 && resultCode == RESULT_OK && data != null) { // When result is ok // Initialize Uri videoUri = data.getData(); // Set video uri vedgetr.setVideoURI(videoUri); vedgetr.start(); // Initialize file File file = new File( Environment.getExternalStorageDirectory() .getAbsolutePath()); // Create compress video method } } private class CompressVideo extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... strings) { // Initialize video path String videoPath = null; try { // Initialize uri Uri uri = Uri.parse(strings[1]); // Initialize output directory File outputDir = new File(Environment.getExternalStorageDirectory(), "CompressedVideos"); outputDir.mkdirs(); // Compress video videoPath = new Compressor(uploadved.this) .setVideoConstraints(VideoConstraint.RESOLUTION, 720, 1280) .setVideoConstraints(VideoConstraint.ASPECT_RATIO, 1, 1) .setVideoConstraints(VideoConstraint.DURATION, 30) .setVideoConstraints(VideoConstraint.VIDEO_BITRATE, 2 * 1024 * 1024) .setAudioChannels(1) .setAudioBitRate(128 * 1024) .compressToFile(uri.toString(), outputDir.getPath()); } catch (URISyntaxException e) { e.printStackTrace(); } // Return Video path return videoPath; } }
- 8 اجابة
-
- 1
-
دلوقتى انا مش لاقى مكتبة Compressor ytr.bmp
- 8 اجابة
-
- 1
-
@SuppressWarnings("ALL") public class uploadved extends AppCompatActivity implements difroved.ExampleDialogeListener{ RoundedImageView geter; VideoView vedgetr; public Uri videoUri; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uploadved); geter = findViewById(R.id.geter); vedgetr = findViewById(R.id.vedgetr); geter.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // check condition if (ContextCompat.checkSelfPermission( uploadved.this, Manifest.permission .WRITE_EXTERNAL_STORAGE) == PackageManager .PERMISSION_GRANTED) { // When permission is granted // Create method selectVideo(); } else { // When permission is not granted // request permission ActivityCompat.requestPermissions( uploadved.this, new String[] { Manifest.permission .WRITE_EXTERNAL_STORAGE }, 1); } } }); private void selectVideo() { Intent intent = new Intent(Intent.ACTION_PICK); // Set type intent.setType("video/*"); // set action intent.setAction(Intent.ACTION_GET_CONTENT); // Start activity result startActivityForResult( Intent.createChooser(intent, "Select Video"), 100); } @Override public void onRequestPermissionsResult( int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult( requestCode, permissions, grantResults); // check condition if (requestCode == 1 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // When permission is granted // Call method selectVideo(); } else { // When permission is denied // Display Toast Toast .makeText(getApplicationContext(), "Permission Denied !", Toast.LENGTH_SHORT) .show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); // Check condition if (requestCode == 100 && resultCode == RESULT_OK && data != null) { // When result is ok // Initialize Uri Uri uri = data.getData(); // Set video uri // Initialize file File file = new File( Environment.getExternalStorageDirectory() .getAbsolutePath()); // Create compress video method new CompressVideo().execute( "false", uri.toString(), file.getPath()); } } private class CompressVideo extends AsyncTask<String, String, String> { // Initialize dialog Dialog dialog; @Override protected void onPreExecute() { super.onPreExecute(); // Display dialog dialog = ProgressDialog.show( uploadved.this, "", "Compressing..."); } @Override protected String doInBackground(String... strings) { // Initialize video path String videoPath = null; try { // Initialize uri Uri uri = Uri.parse(strings[1]); // Compress video videoPath = SiliCompressor.with(uploadved.this) .compressVideo(uri, strings[2]); } catch (URISyntaxException e) { e.printStackTrace(); } // Return Video path return videoPath; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); // Dismiss dialog dialog.dismiss(); // Visible all views // Initialize file File file = new File(s); // Initialize uri Uri uri = Uri.fromFile(file); // set video uri vedgetr.setVideoURI(uri); // start both video vedgetr.start(); // Compress video size float size = file.length() / 1024f; // Set size on text view Log.d("drivetestaa",String.format("Size : %.2f KB", size)); } }} الكود ده بيضغط معايا ملف الفيديو بس بيبقى من غير صوت