FFMpeg:将图像与音频合并特定的持续时间 [英] FFMpeg: merge images with audio for specific duration

查看:464
本文介绍了FFMpeg:将图像与音频合并特定的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去7天,我一直在研究 FFMpeg .我需要在以下位置创建视频:

I have been working on FFMpeg from past 7 days. I am required to create a video where I need to perform following:

  1. Concat 几张图像转换成从android存储设备中选取的视频.
  2. 添加音乐文件(与从Android存储设备中选取的文件相同).
  3. 设置每个图像的持续时间,以在视频中显示.例如如果选择了3张图像,则视频的总时长应为用户选择的3 *持续时间.
  1. Concat few images into video picked from android storage.
  2. Add a music file [same picked from android storage].
  3. Set Duration per image to be shown in the video. e.g. if 3 images are picked then total duration of video should be 3*duration choosen by user.

我到目前为止所做的事情.

我正在为 FFmpeg 预构建二进制文件使用 implementation'nl.bravobit:android-ffmpeg:1.1.5'.以下是用于串联图像并设置持续时间的命令:

I am using implementation 'nl.bravobit:android-ffmpeg:1.1.5' for the FFmpeg prebuild binaries. Following is the command that has been used to concatenation the images and set the duration:

ffmpeg -r 1/duration_selected_by_user -f concat -safe 0 -i path_of_concat_file.txt -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p path_of_output_video_file.mp4 

注意:

  1. 通过添加用户选择的持续时间作为帧速率,我可以设置要显示的每个图像的持续时间.
  2. Concat效果很好,并且视频已合并到图像中.

问题:当我尝试在同一过程中添加音频时,通过使用以下命令,即使对于较小的音频,进度也会运行很长时间:

Problem: When I try to add audio in the same process, progress run for a long time even for small audio by using the following command:

ffmpeg -r 1/duration_selected_by_user -i path_of_audio_file.mp3 -f concat -safe 0 -i path_of_concat_file.txt -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p path_of_output_video_file.mp4

由于我对该技术不太熟悉和经验丰富,因此似乎在命令中存在一些问题.如何提高图像和音频合并的性能以获得更好的结果?

It looks like there is some issue in command as I am not much familiar and experienced with the technology. How can I improve the performance of merging images and audio to get the better results?

与上下文相关的重要链接:

https://github.com/bravobit/FFmpeg-Android

推荐答案

如评论中提到的@HB:

As @HB mentioned in the comments:

尝试在-pix_fmt yuv420p之后添加-preset ultrafast

Try adding -preset ultrafast after -pix_fmt yuv420p

预设是选项的集合,这些选项将提供一定的编码速度与压缩率.较慢的预设将提供更好的压缩(压缩是每个文件大小的质量).这意味着,例如,如果您以某个文件大小或恒定比特率为目标,则使用较慢的预设可获得更好的质量.同样,对于恒定质量的编码,只需选择较慢的预设即可简单地节省比特率.可用的速度降序预设为:

A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset. The available presets in descending order of speed are:

  • 超快
  • 超快
  • 非常快
  • 更快
  • 快速
  • 中-默认预设
  • 较慢
  • 非常慢
  • 安慰剂–忽略它,因为它没有用

参考: https://trac.ffmpeg.org/wiki/Encode/H.264#Preset

这篇关于FFMpeg:将图像与音频合并特定的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆