如何使用 FFmpeg 在视频上使文本在单行中滚动而不使用额外的行?

问题描述 投票:0回答:1

如何使用 FFmpeg 在视频上使文本在单行中滚动而不使用额外的行?

在 Android 上使用 FFmpeg 使文本在视频上单行滚动,但文本显示其他行
我的代码

     downloadProgressDialog.show()

outputPath =
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + "/$fileName.mp4"

        var videoPath = videoPath!!
        var text = bottomTextScroll!!
        var fontPath = fontPath!!
 
        val query = ffmpegQueryExtension.addScrollingTextToVideo(
            videoPath,
            text,
            fontPath,
            outputPath!!

        )
        CallBackOfQuery().callQuery(query, object : FFmpegCallBack {

            override fun success() {
                downloadProgressDialog.clearProgress()
                downloadProgressDialog.dismiss()
                Toast.makeText(
                    this@MainActivity,
                    "Video Download Success",
                    Toast.LENGTH_SHORT
                )
                    .show()
                var notificationText = "Your video has been successfully downloaded."
                showNotification(notificationText)


                var i = Intent(this@MainActivity, VideoShareActivity::class.java)
                i.putExtra("outputPath", outputPath)
                startActivity(i)
                finish()


            }

            override fun cancel() {
                downloadProgressDialog.dismiss()
                Toast.makeText(
                    this@MainActivity,
                    "Video Download Cancel",
                    Toast.LENGTH_SHORT
                )
                    .show()
            }

            override fun failed() {
                downloadProgressDialog.dismiss()
                Toast.makeText(
                    this@MainActivity,
                    "Video Download Fail",
                    Toast.LENGTH_SHORT
                ).show()

                var notificationText = "Your video download Fail."
                showNotification(notificationText)
            }

            //get video download progress
            override fun updateProgress(progress: Int) {
                val duration = getVideoDuration(videoPath!!)  // get video duration

                downloadProgressDialog.updateProgress(progress, duration)
            }

        })
fun addScrollingTextToVideo(
    videoPath: String,
    text: String,
    fontPath: String,
    outputPath: String
): Array<String> {
    val inputs: ArrayList<String> = ArrayList()
    val scrollSpeed = 5
    val textSize = 40

    inputs.apply {
        add("-i")
        add(videoPath)
        add("-vf")
        add("drawtext=fontfile=$fontPath:text='$text':fontsize=$textSize:fontcolor=white:x=w-(mod($scrollSpeed*n\\,w+tw)):y=h-text_h-105")
        add("-c:a")
        add("copy")
        add(outputPath)
    }

    return inputs.toArray(arrayOfNulls(inputs.size))
}

在 Android 上使用 FFmpeg 在视频上使长文本在单行中滚动,但文本在

中显示其他行

请给我解决方案

java android kotlin ffmpeg
1个回答
0
投票

错误灵魂完成 下面是我的代码工作文本显示单行

    fun addScrollingTextToVideo(
    videoPath: String,
    text: String,
    fontPath: String,
    outputPath: String
): Array<String> {
    val inputs: ArrayList<String> = ArrayList()
    val scrollSpeed = 5
    val textSize = 40
    val cleanedText = text.replace("\n", " ")
    inputs.apply {
        add("-i")
        add(videoPath)
        add("-vf")
        add("drawtext=fontfile=$fontPath:text='$cleanedText':fontsize=$textSize:fontcolor=white:x=w-(mod($scrollSpeed*n\\,w+tw)):y=h-text_h-105")
        add("-c:a")
        add("copy")
        add(outputPath)
    }

    return inputs.toArray(arrayOfNulls(inputs.size))
}
© www.soinside.com 2019 - 2024. All rights reserved.