Currently, I am trying to play a video from the web. I tried many ways to play a video from the web but nothing worked. I first used videoView and I was always saying that the video file can not be played. The link doesn't really have to be from Drive or to use the method I use right now. I just need to make it work.
Here is what the code looks like right now:
String url = "https://drive.google.com/file/d/1CRJ8tL-DyjD0Nwd7ezkboGm6570zMf4C/view?usp=sharing";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starter_yoga);
findViewById(R.id.backY).setOnClickListener(v -> {
onBackPressed();
});
SimpleExoPlayer simpleExoPlayer = new SimpleExoPlayer.Builder(this).build();
PlayerView playerView = findViewById(R.id.SY);
playerView.setPlayer(simpleExoPlayer);
MediaItem mediaItem = MediaItem.fromUri(url);
simpleExoPlayer.addMediaItem(mediaItem);
simpleExoPlayer.prepare();
simpleExoPlayer.play();
}
Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
android:usesCleartextTraffic="true"
Error:
2021-08-30 15:37:32.662 4582-6879/? E/TaskPersister: File error accessing recents directory
(directory doesn't exist?).
2021-08-30 15:37:35.676 4130-4254/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl
is
netid 0
2021-08-30 15:37:35.708 4130-4260/? E/Netd: getNetworkForDns: getNetId from enterpriseCtrl is netid 0
2021-08-30 15:37:35.778 4164-4184/? E/HYPER-HAL: [Request.cpp]acquire(): Request:: id :
10586920, No Resource to set
2021-08-30 15:37:36.179 4219-4242/? E/BufferQueueProducer:
[com.example.diligent/com.diligent_app.diligent.yoga.Yoga$_20925#0](id:107b0000491d,api:0,p:-1,c:4219) disconnect: not connected
2021-08-30 15:37:36.526 3933-3933/? E/vold: getUsedF2fsFileNode -> Cannot Get Used FileNode Number (errno=25 Inappropriate ioctl for device)
2021-08-30 15:37:36.718 20925-23908/com.example.diligent E/ExoPlayerImplInternal: Playback error
com.google.android.exoplayer2.ExoPlaybackException: Source error
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:624)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:594)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:246)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, Mp3Extractor, JpegExtractor) could read the stream.
at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92)
at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1025)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:409)
Replace the URL format like this:
String videoURL = "https://drive.google.com/u/1/uc?id=1hMzertAC6ap31Xup6_B0fJP-fbZP7GFX&export=download";
Where 1hMzertAC6ap31Xup6_B0fJP-fbZP7GFX is your video ID.
From the error, the problem is likely that the device does not support the video encoding.
From ffprobe (https://ffmpeg.org/ffprobe.html):
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/y_v_starter_yoga.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:06:00.02, start: 0.000000, bitrate: 860 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1080x2260 [SAR 1:1 DAR 54:113], 839 kb/s, 20 fps, 20 tbr, 10240 tbn, 40 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 14 kb/s (default)
Metadata:
handler_name : SoundHandler
You can see it is using 'High' Profile which many Android devices will not support - see here for the standard media support:
https://developer.android.com/guide/topics/media/media-formats
If you can re encode it using baseline profile you can verify this is the issue.
If you want to see working examples of ExoPlayer playing web video, ExoPlayer's own sample player includes these. You can also edit the samples JSON Media list to add in your own video links and test them directly with the ExoPlayer sample player.
Related
This question already has answers here:
Encoding a readable movie by QuickTime using FFMPEG
(2 answers)
FFmpeg converting image sequence to video results in blank video [closed]
(1 answer)
Closed 2 years ago.
I have some old videos collected using a canon camera, they are in avi format. I am not able to play the files on android though the audio works fine, it says Can't play video, videocodec not supported. I tried the following but it still doesn't work:
ffmpeg -i ip.avi -c:v libx264 -c:a aac -movflags +faststart op.mp4
Original avi video info:
Input #0, avi, from 'ip.avi'
Metadata:
creation_time : 2012-11-17 11:38:53
encoder : CanonMVI03
Duration: 00:01:39.90, start: 0.000000, bitrate: 16256 kb/s
Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 14844 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Converted mp4 video info:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'op.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:01:39.92, start: 0.000000, bitrate: 2048 kb/s
Stream #0:0(und): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuvj422p(pc), 640x480, 1911 kb/s, 30 fps, 30 tbr, 1000k tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
From posts here and here the following worked:
ffmpeg -i ip.avi -c:v libx264 -c:a aac op.mp4
ffmpeg -i op.mp4 -vf "scale=2*trunc(iw/2):-2,setsar=1" -profile:v main -pix_fmt yuv420p newop.mp4
This question already has answers here:
ffmpeg add watermark libx264 width not divisible by 2 (853x480)
(1 answer)
FFMPEG (libx264) "height not divisible by 2"
(7 answers)
Closed 4 years ago.
I am trying to overlay a video on an image using the below command.
String[]sepCmd=new String[]{"-loop","1","-i",uri,"-i",overlayUri,"-filter_complex","[1:v]colorkey=0x000000:0.5:0.5[ckout];[0:v][ckout]overlay[out]","-map","[out]","-acodec","libfaac","-c:a", "copy",outputPath};
When I run the above command, I get the error as shown below
Input #0, png_pipe, from '/storage/emulated/0/snowflake.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, gray(pc), 304x345 [SAR 11811:11811 DAR 304:345], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/FilterVideos/vintage1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.12.100
Duration: 00:00:05.08, start: 0.000000, bitrate: 447 kb/s
Stream #1:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 306 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 (png) -> overlay:main
Stream #1:0 (h264) -> colorkey
overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[swscaler # 0xee29d000] deprecated pixel format used, make sure you did set range correctly
[swscaler # 0xee2a8000] No accelerated colorspace conversion found from yuv420p to argb.
[libx264 # 0xf125ba00] height not divisible by 2 (304x345)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
I have an existing mp4 file and want to add an audio track to it using ffmpeg (the audio track is a wav file recorded from the device's microphone).
I'm executing the following command but it's not generating any output. It seems that fmpeg simply hangs:
String[] command = new String[]{"-i", audioFilePath, "-i", videoFilePath, "-codec", "copy", "-shortest", outputFilePath};
The logs are:
Input #0, wav, from '/data/user/0/android.com.app/cache/30930595321169630261385.audio':
Duration: 00:00:02.03, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Android/data/android.com.app/cache/4632127da0955d4a461dfd622c78233e':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.41.100
Duration: 00:00:02.04, start: 0.000000, bitrate: 728 kb/s
Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 500x280 [SAR 1:1 DAR 25:14], 724 kb/s, 16.67 fps, 16.67 tbr, 166667 tbn, 33.33 tbc (default)
Metadata:
handler_name : VideoHandler
After this, there are no more log statements.
Any ideas what could be causing this?
Use below given Command in FFmpeg Android
String[] command = {"-i", yourVideoPath, "-i", yourAudioPath, "-c:v", "copy", "-c:a", "aac", "-map", "0:v:0", "-map", "1:a:0", "-shortest", file.getAbsolutePath()}
in my iOS app I create mp4 videos with these details:
IPHONE
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp41mp42isom
creation_time : 2015-05-23 05:59:42
Duration: 00:00:02.10, start: 0.000000, bitrate: 1109 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt709/bt709), 320x320, 1053 kb/s, 24.19 fps, 30 tbr, 30 tbn, 60 tbc (default)
Metadata:
creation_time : 2015-05-23 05:59:42
handler_name : Core Media Video
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 61 kb/s (default)
Metadata:
creation_time : 2015-05-23 05:59:42
handler_name : Core Media Audio
However Android devices cannot play this video and I don't understand exactly why and what I should change.
According to this Android Developer - Supported Media Formats I expected it to be supported
Any ideas?
I am trying to record from the video camera in my application. I have removed try/catch blocks and things of that nature to show an example of how to record:
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.reset();
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
CamcorderProfile mCamcorderProfile = CamcorderProfile.get(CameraInfo.CAMERA_FACING_FRONT, CamcorderProfile.QUALITY_720P);
mediaRecorder.setProfile(mCamcorderProfile);
/*
mediaRecorder.setVideoEncodingBitRate(8000000);
mediaRecorder.setVideoEncodingBitRate(5000000);
mediaRecorder.setVideoEncodingBitRate(3000000);
*/
mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecFile = File.createTempFile("Video", ".mp4", mRecVideoPath);
mediaRecorder.setOutputFile(mRecFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
I record the video and it plays perfectly on the phone. Then I pull the video file off and I play it on a PC and the audio/video is slightly out of sync on a short 10 second clip. This only happens when recorded with a Samsung Note 3.
Just to be thorough, here is what I have tried:
Works perfectly on a Nexus 7
Works perfectly on a Samsung S3
Tried recording on two different Note 3
Tried various bitrates
For playing the out of sync video from the Note 3:
Played video on a Macbook pro, Chrome browser
Played video on a Macbook pro, quicktime
Played video on a Win7 pc
Out of sync on all of them.
When recording a video on the Note 3 with the stock camera app there is NO sync issue!
Update that I forgot: Using the highest quality setting I recorded a video with my app and one video with the stock camera. I inspected both videos and this is the output. I forget now which was which but the output is identical as far as I can tell.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20140719_155219.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2014-07-19 20:52:24
Duration: 00:00:04.97, start: 0.000000, bitrate: 16674 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17093 kb/s, 29.92 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2014-07-19 20:52:24
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 117 kb/s (default)
Metadata:
creation_time : 2014-07-19 20:52:24
handler_name : SoundHandle
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20140719160307.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2014-07-19 21:03:07
Duration: 00:00:06.61, start: 0.000000, bitrate: 16530 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 16473 kb/s, 29.92 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2014-07-19 21:03:07
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 117 kb/s (default)
Metadata:
creation_time : 2014-07-19 21:03:07
handler_name : SoundHandle