bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.56k stars 1.58k forks source link

1920x1440 or higher video couldn't play on Samsung devices, indicating that the file type is not supported #1899

Closed s2g090123 closed 1 year ago

s2g090123 commented 2 years ago

I am trying to create video via FFmpegFrameRecorder. The video size is 1920x1440 but it doesn't play on Samsung devices. The file type is not supported. I have tried 1920x1080 and 1024x768, both work. Or what codec should I set?

Below is my sample code

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        create()
    }

    private fun create() {
        val file = File(getExternalFilesDir("video"), "test.mp4")
        if (file.exists()) {
            file.delete()
        }
        val recorder = FFmpegFrameRecorder(file, 1920, 1440)
        recorder.format = "mp4"
        val converter = AndroidFrameConverter()
        val bitmap = Bitmap.createBitmap(1920, 1440, Bitmap.Config.ARGB_8888)
        recorder.start()
        recorder.record(converter.convert(bitmap))
        converter.close()
        recorder.stop()
        recorder.release()
    }
}

Thank you so much!

saudet commented 2 years ago

You may want to try to use the "main" profile instead of "baseline" as pointed out by @vonabe at issue https://github.com/bytedeco/javacv/issues/1885#issuecomment-1241019473.

s2g090123 commented 2 years ago

Sorry, I didn't understand what you said.

Replace FF_PROFILE_H264_CONSTRAINED_BASELINE with FF_PROFILE_H264_MAIN in video_c.profile(AVCodecContext.FF_PROFILE_H264_CONSTRAINED_BASELINE)?

saudet commented 1 year ago

Actually, there is no need to add anything to JavaCV to get this working. I've confirmed that, for example, calling setVideoOption("profile", "main") before start() does set the profile to "main", see https://trac.ffmpeg.org/wiki/Encode/H.264#Profile.