pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.56k stars 773 forks source link

How to set outputFileformat? #202

Closed prashantgunit closed 5 years ago

prashantgunit commented 6 years ago

I have an issue regarding out file format. Recorded file format change to 3gp in my micromax phone. Otherwise it is working fine in my other phones. Please help me out.

pedroSG94 commented 6 years ago

If you try reproduce any mp4 file in your device, it works fine? Can you share me device model and api version?

prashantgunit commented 6 years ago

Device Model is Micromax E484 android version is 5.1 by default camera is recording in .3gp format and file is shown in sdcard like this in image device-2018-07-17-092724

pedroSG94 commented 6 years ago

Write a log in this conditional to make sure your encoder create key frame and start record video: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/base/Camera1Base.java#L619

prashantgunit commented 6 years ago

It is not working when i changed file format to mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_3GPP); Is there any workaround to resolve the issue?

pedroSG94 commented 6 years ago

Did you try write a log to know if your device start mediamuxer? https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/base/Camera1Base.java#L619

prashantgunit commented 6 years ago

Hi, I have write the log and mediaMuxer is not getting started. What should i do now?

pedroSG94 commented 6 years ago

It means that your encoder never mark a keyframe so mediamuxer never start. Try record 2mins video and see if sometime your encoder mark some keyframe. I will try find a way to force mark that frame but I don't know if I can do it. What mode and view are you using? (rtmpcamera1 with surfaceview for example, rtmcamera1 with lightopengl, etc)

prashantgunit commented 6 years ago

i am using rtmpcamera1 with surfaceview. 2 mins recording does not capture any frame.

prashantgunit commented 6 years ago

when i remove this condition

 if (info.flags == MediaCodec.BUFFER_FLAG_KEY_FRAME
          && !canRecord
          && videoFormat != null
          && audioFormat != null) {
}

Got this error in logcat

 java.lang.IllegalStateException: Muxer is not initialized.
        at android.media.MediaMuxer.addTrack(MediaMuxer.java:265)
        at com.pedro.rtplibrary.base.Camera1Base.getH264Data(Camera1Base.java:623)
        at com.pedro.encoder.video.VideoEncoder.getDataFromEncoderAPI21(VideoEncoder.java:422)
        at com.pedro.encoder.video.VideoEncoder.access$800(VideoEncoder.java:31)
        at com.pedro.encoder.video.VideoEncoder$1.run(VideoEncoder.java:247)
        at java.lang.Thread.run(Thread.java:818)
07-21 15:41:43.653 13121-13500/ E/MPEG4Writer: There are no sync frames for video track
pedroSG94 commented 6 years ago

Go to: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/encoder/src/main/java/com/pedro/encoder/video/VideoEncoder.java#L415 Replace:

if (buffers != null) {
              getH264Data.onSPSandPPS(buffers.first, buffers.second);
              spsPpsSetted = true;
}

To:

if (buffers != null) {
              getH264Data.onVideoFormat(videoEncoder.getOutputFormat());
              videoInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME;
              getH264Data.onSPSandPPS(buffers.first, buffers.second);
              spsPpsSetted = true;
            }
prashantgunit commented 6 years ago

Not working. Same result with 0 bytes file

pedroSG94 commented 6 years ago

Last 2 shoot. I haven't more ideas for now. If no work I only can think that your device can't record mp4 because your native camera can't do it. Try force hardware and software video encoders.

//hardware
rtmpCamera1.setForce(CodecUtil.Force.HARDWARE, CodecUtil.Force.FIRST_COMPATIBLE_FOUND);
//software
rtmpCamera1.setForce(CodecUtil.Force.SOFTWARE, CodecUtil.Force.FIRST_COMPATIBLE_FOUND);

If no work try use lightopenglview instead of surfaceview. Also combine it with both previous suggestions.

prashantgunit commented 6 years ago

Now i am gettting this in my logcat

E/VideoEncoder: Valid encoder not found
07-21 17:46:09.378 27017-27017E/VideoEncoder: Valid encoder not found
07-21 17:46:09.384 27017-27017 E/VideoEncoder: VideoEncoder need be prepared, VideoEncoder not enabled
pedroSG94 commented 6 years ago

When you force hardware, software or using lightopenglview?

prashantgunit commented 6 years ago

when i use software and surfaceview

pedroSG94 commented 6 years ago

Try hardware and lightopenglview. If no work I don't know more ways to solve it.