I send a video file(capture from camera) to my PHP server using Retrofit 2,the video is successfully uploaded to a folder in server(I checked with FileZilla, the video exists in the folder),I assign the video to a URL,I go to the same Url(using browser) it cant play the video.
It just appears like this in Url(example: mydomain.cc/video/VID_2014.mp4)
So I test with a random video, send it via postman, the URL of that video is able to playback.
Like so:
My video file path in Android that I get in onActivityResult
after capturing video looks like this
/storage/emulated/0/DCIM/ABC/VID_20171008_183129.mp4
Here is my code for sending video file
private void uploadVideoToServer(String pathToVideoFile){
File videoFile = new File(pathToVideoFile);
RequestBody videoBody = RequestBody.create(MediaType.parse("video/*"), videoFile);
MultipartBody.Part vFile = MultipartBody.Part.createFormData("video", videoFile.getName(), videoBody);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(SERVER_PATH)
.addConverterFactory(GsonConverterFactory.create())
.build();
VideoInterface vInterface = retrofit.create(VideoInterface.class);
Call<ResultObject> serverCom = vInterface.uploadVideoToServer(vFile);
serverCom.enqueue(new Callback<ResultObject>() {
@Override
public void onResponse(Call<ResultObject> call, Response<ResultObject> response) {
ResultObject result = response.body();
if(!TextUtils.isEmpty(result.getSuccess())){
Toast.makeText(MainActivity.this, "Result " + result.getSuccess(), Toast.LENGTH_LONG).show();
Log.d(TAG, "Result " + result.getSuccess());
}
}
@Override
public void onFailure(Call<ResultObject> call, Throwable t) {
Log.d(TAG, "Error message " + t.getMessage());
}
});
}
VideoInterface.java
public interface VideoInterface {
@Multipart
@POST("video.php")
Call<ResultObject> uploadVideoToServer(@Part MultipartBody.Part video);
}
So my question is, why video capture from the Android camera not able to playback in Url? Does this matter?
Cause I worried later I need to display back to my app by using the Url, if matter how to solve this?
So somebody please give me a complete solution for doing this..
EDIT: I checked the codec by using the ffmpeg, here is the result..
The audio and video codecs used by your videos matter; not all codecs are supported by all players. Mozilla has a nice table of supported codecs by platform and player. Based on this table, I think you want:
You can check the codecs using the popular vlc media player, or ffmpeg.
After capturing your video, you may need to convert to suitable web codecs. ffmpeg is a free tool for converting codecs and containers.
The ffmpeg documentation example for converting to webm is:
ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -c:a libvorbis output.webm
You may need to tweak the bitrate 1M for your quality/size preferences.
Video MP4 store the metadata needed to play it at the and of the file. Did you wait for the complete download of video before give up ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With