GithubHelp home page GithubHelp logo

veizhang / androidffmpeg Goto Github PK

View Code? Open in Web Editor NEW
37.0 3.0 8.0 123.62 MB

FFmpeg命令 [ffmpeg] [ffprobe] 在Android中的使用

Java 100.00%
ffmpeg ffmpeg-command android-command android-ffmpeg ffprobe

androidffmpeg's Introduction

FFmpeg for Android

Download

  • 完整引用

    // 完整引用,集成所有CPU架构的可执行文件
    implementation 'com.excellence:ffmpeg:_latestVersion'
    
  • 部分引用

    implementation 'com.excellence:ffmpeg-java:_latestVersion'
    
    // ffmpeg部分引用,使用想要的CPU架构的可执行文件
    implementation 'com.excellence:ffmpeg-arm64-v8a:_latestVersion'
    implementation 'com.excellence:ffmpeg-armv7a:_latestVersion'
    implementation 'com.excellence:ffmpeg-x86:_latestVersion'
    implementation 'com.excellence:ffmpeg-x86_64:_latestVersion'
    
    // ffprobe部分引用,使用想要的CPU架构的可执行文件
    implementation 'com.excellence:ffprobe-arm64-v8a:_latestVersion'
    implementation 'com.excellence:ffprobe-armv7a:_latestVersion'
    implementation 'com.excellence:ffprobe-x86:_latestVersion'
    implementation 'com.excellence:ffprobe-x86_64:_latestVersion'
    

基于AndroidExec项目,FFmpeg命令执行

FFmpeg&FFprobe使用

// 初始化,默认:不限制并发线程数;指令超时10s终止
FFmpeg.init(context);
FFprobe.init(context);

// 自定义初始化参数:超时1s终止
FFmpeg.init(context, new CommanderOptions.Builder().setTimeOut(1000).build())
FFprobe.init(context, new CommanderOptions.Builder().setTimeOut(1000).build())

// 获取FFmpeg工具路径
FFmpeg.checkFFmpeg()
FFprobe.checkFFmpeg()

// 创建执行命令
推荐方式:new CommandTask.Builder().command(FFmpeg.checkFFmpeg()).command(cmd).build().deploy(IListener);

丢弃方式:FFmpeg.addTask(cmd, new IListener() {
    @Override
    public void onPre(String command) {
        Log.i(TAG, "onPre: " + command);
    }

    @Override
    public void onProgress(String message) {
        Log.i(TAG, "onProgress: " + message);
    }

    @Override
    public void onError(Throwable t) {
        t.printStackTrace();
    }

    @Override
    public void onSuccess(String message) {
        Log.i(TAG, "onSuccess: " + message);
    }
});

// 终止命令
CommandTask.discard()

// 终止所有命令
FFmpeg.destroy()
FFprobe.destroy()

FFmpeg命令

FFMpeg官网

Windows工具下载,解压后,把FFmpeg加入到环境变量中,可在Windows上使用FFmpeg

命令选项

  • 选项参数

    基本语法格式:

    ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
    
  • 常用选项

    -version:   显示版本信息。
    
    -formats:   显示所有有效的格式。
    
    -decoders:  显示所有有效解码器。
    
    -encoders:  显示所有有效的编码器。
    
    -bsfs:      显示有效的数据流滤镜。
    
    -pix_fmts:  显示有效的像素格式。
    
  • 主要选项

    -f fmt(input|output):      指定输入或者输出文件格式,可依据扩展名自动指定。
    
    -i filename(input):        指定输入文件。
    
    -y (global):               默认自动覆盖输出文件。
    
    -n (global):               不覆盖输出文件,如果输出文件已存在则立即退出。
    
    -t duration(input|output): 限制输入/输出的时间。
                               如果用于输入选项,就是限定从输入中读取多少时间的数据;
                               如果用于输出选项,则表示写入多少时间数据后就停止。
                               duration 可以是以秒为单位的数值活着 hh:mm:ss[.xxx] 格式的时间值。
                               -to 和 -t 是互斥的,-t 有更高的优先级。
    
    -to time_stop(output):     写入 time_stop 时间后就停止。
                               time_stop 可以是以秒为单位的数值或者 hh:mm:ss[.xxx] 格式的时间值。
    
    -fs limit_size(output):    设置输出文件大小限制,单位是字节(bytes)。
    
    -ss time_off(input|output): 指定输入文件或输出文件的开始位置。
    
  • 视频选项

    -vframes number(output): 设置输出文件的帧数。
    
    -r rate(input|output):   设置帧率(Hz 值)。
    
    -s size(input|output):   设置帧的尺寸。数据格式是 WxH,即宽度值x高度值。
    
    -aspect aspect(output):  指定视频的长宽显示比例。格式为浮点数字符串或者 num:den 格式字符串。
                             如"4:3","16:9","1.333"等。
    
    -vcodec codec(output):   设置视频编码器。
    
  • 音频选项

    -aframes number(output): 设置输出文件的帧数。
    
    -ar rate(input|output): 设置音频的采样率,单位为 Hz。
    
    -aq quality(output): 设置音频品质(编码指定为 VBR)。
    
    -ac channels(input|output): 设置音频通道数。
    
    -af filtergraph(output): 对音频使用 filtergraph 滤镜效果。
    

常用命令

  • 获取视频信息

    ffprobe -v quiet -print_format json -show_format -show_streams inputfile
    
  • 视频截图

    ffmpeg -i input_file -y -f mjpeg -ss 1 -t 0.001 -s widthxheight output_file
    
    i: 源文件
    y: 覆盖输出文件
    f: 截图格式
    ss: 起始位置,单位秒
    t: 截图时间,单位秒
    s: 图片宽x高
    
  • 每隔 1 秒截一张图

    ffmpeg -i input.mp4 -f image2 -vf fps=fps=1 out%d.jpg
    
  • 每隔 20 秒截一张图

    ffmpeg -i input.mp4 -f image2 -vf fps=fps=1/20 out%d.jpg
    
  • 将视频的前 30 帧转换成一个 Gif

    ffmpeg -i input.mp4 -vframes 30 -y -f gif output.gif
    
  • 从视频中生成 Gif

    ffmpeg -i input.mp4 -t 10 -pix_fmt rgb24 output.gif
    
  • 转换视频为图片(每帧一张图)

    ffmpeg -i input.mp4 out%d.jpg
    
  • 图片转换为视频

    ffmpeg -f image2 -i out%d.jpg -r 25 video.mp4
    
  • 提取视频的关键帧

    ffmpeg -i input.mp4 -vf select='eq(pict_type\,I)' -vsync 2 -s 160x90 -f image2 out-%02d.jpeg
    
  • 分解视频音频流

    // 分离视频流
    ffmpeg -i input_file -vcodec copy -an output_file_video
    
    // 分离音频流
    ffmpeg -i input_file -vcodec copy -vn output_file_audio
    
  • 视频转码

    // 转码为码流原始文件
    ffmpeg -i input.mp4 -vcodec h264 -an -f m4v test.264
    
  • 视频封装

    ffmpeg -i video_file -i audio_file -vcodec copy -acodec copy output_file
    
  • 视频录制

    // 录制视频流
    ffmpeg -i rtsp://hostname/stream -vcodec copy output.avi
    
    // 通过电脑摄像头录制
    ffmpeg -f avfoundation -framerate 30 -i "0" -f mpeg1video -b 500k -r 20 -vf scale=640:360 output.avi
    

FFprobe命令

  • 查看多媒体包信息

     ffprobe -show_packets input.mp4
    

版本更新

版本 描述
1.2.6 增加ffprobe脚本 2022-6-1
1.2.5 增加OpenSSL 2021-8-23
1.2.4 每次初始化更新FFmpeg 2021-6-29
1.2.3 增加CPU架构 2021-5-30
1.2.2 修复任务偶尔不执行 2019-8-15
1.2.1 设置armeabi为默认的CPU架构 2019-5-29
1.2.0 新增armeabi架构,分离ffmpeg可执行文件 2019-5-21
1.1.1 更新ffmpeg可执行文件,修改低版本机型中任务销毁时导致的阻塞 2019-4-29
1.1.0 使用Builder模式创建命令任务,修复崩溃异常 2018-9-3
1.0.0 集成FFmpeg命令行执行 2018-8-17

感谢

androidffmpeg's People

Contributors

veizhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

androidffmpeg's Issues

引用

在引用方法会出现错误ERROR: Failed to resolve: com Affected Modules: app问题。
我的项目没有问题,但在引用你这个后出现错误,去除引用后恢复正常

64bit support?

Hello and many thanks for your ffmpeg library for Android.

After reading about the new 64bit requirement for Android of native libraries, I noted that your library is not stored in Libs but in Assets. Instructions from Google says to verify for the presence of 64bit by looking at the Directory-names. If I unzip, it only contains Arm and x86 directories and does not give an indication if 64 libs is included.

See this:
https://developer.android.com/distribute/best-practices/develop/64-bit

Can you confirm that your library is OK with Google's new requirements?

Thanks.

没有启用h264

不知道是没有编译libx264库,还是编译了没有启用!反正涉及到h264的都不能用!会报错:Unknown encoder 'h264'

如何减小库的大小?

你好兄弟,
我使用了你的库,它与我的项目完美配合。但是库的大小太大了,有没有办法减小这个库的大小?

谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.