duanhong169 / Camera

📸 Use Android camera to take pictures and videos, based on `camera2` api.
Apache License 2.0
130 stars 45 forks source link

video codec not supported #2

Closed FidanBacaj closed 5 years ago

FidanBacaj commented 5 years ago

When I make a video with this library ( com.github.duanhong169:camera:1.0.3 ) and when i click to play this video ,video not played just voice and writes "video codec not supported"

Can you help me for this problem how to fix ?

duanhong169 commented 5 years ago

Hi @FidanBacaj :

You can find the default video recorder config here:

https://github.com/duanhong169/Camera/blob/6077681d059eb5f8f01ffbf373ebc35ed01e3def/camera/src/main/java/top/defaults/camera/Camera2Photographer.java#L851-L870

As you can see, the default video format & codec is:

mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

So the problem is that the video player your phone provided may not support the H264 codec, so it cannot play the video for you.

There are two ways to solve the issue:

  1. Install a video player which support the H264 codec.
  2. Configure the video codec by passing in a Photographer.MediaRecorderConfigurator object when you calling Photographer.startRecording(MediaRecorderConfigurator configurator), and set another video codec which your currently using video player supported:
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); // for example

You may find these two classes helpful:

FidanBacaj commented 5 years ago

Thank you @duanhong169 for quick answer !

duanhong169 commented 5 years ago

@FidanBacaj Always welcome! BTW, it will be fine if you give this project a star, then more people can reach here! 😊