视频剪切我意外的发现上一次的视频压缩的代码能够运行FFmpeg视频剪切的命令,但是不能做视频合并的命令,因为不能读取记录了几个视频的路径的txt文件。

这里我就说直说视频剪切的过程,不说代码,只说log,毕竟我也不清楚代码往哪运行了


上一次的项目地址
https://github.com/979451341/FFmpegCompress

首先我们需要将项目代码里改一下,将runCommand函数传入的参数改成下面这样

                    int ret = FFmpegNativeBridge.runCommand(new String[]{"ffmpeg",
"-ss", "00:00:00",
"-t","00:00:10",
"-i", et_input.getText().toString(),
"-vcodec", "copy",
"-acodec", "copy",
et_output.getText().toString()});

开始就是解析命令

读取开始时间,就是-ss后面的"00:00:00",你也可以写成0

03-10 14:19:55.430 21706-22256/org.voiddog.ffmpeg D/TAG: Splitting the commandline.
03-10 14:19:55.430 21706-22256/org.voiddog.ffmpeg D/TAG: Reading option '-ss' ...
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as option
'ss' (set the start time offset) with argument ’00:00:00'.

读取结束时间,就是-t后面的时间,你也可以写成10

03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Reading option '-t' ...
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as option
't' (record or transcode "duration" seconds of audio/video) with
argument ’00:00:10'.

设置输入视频文件,就是切割这个视频文件的前10秒形成新的视频

03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Reading option '-i' ...
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as input
url with argument '/storage/emulated/0/pauseRecordDemo/video/video.mp4'.

复制视频流

03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Reading option '-vcodec' ...
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as option
'vcodec' (force video codec ('copy' to copy stream)) with argument
'copy'.

复制音频流

03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Reading option '-acodec' ...
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as option
'acodec' (force audio codec ('copy' to copy stream)) with argument
'copy'.

最后就是选择输出视频文件路径

03-10 14:19:55.431
21706-22256/org.voiddog.ffmpeg D/TAG: Reading option
'/storage/emulated/0/pauseRecordDemo/video/compress6.mp4' ...
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG:  matched as output url.
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Finished splitting the commandline.
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Parsing a group of options: global .
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.

开始创建并配置输出视频文件

03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Parsing a group of
options: input url /storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Applying option ss (set the start time offset) with argument 00:00:00.
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Applying option t
(record or transcode "duration" seconds of audio/video) with argument
00:00:10.
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.

然后打开它

03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Opening an input
file: /storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10
14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Opening
'/storage/emulated/0/pauseRecordDemo/video/video.mp4' for reading
03-10 14:19:55.431 21706-22256/org.voiddog.ffmpeg D/TAG: Setting default whitelist 'file,crypto'
03-10 14:19:55.434 21706-22256/org.voiddog.ffmpeg D/TAG: Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
03-10 14:19:55.434 21706-22256/org.voiddog.ffmpeg D/TAG: ISO: File Type Major Brand: mp42

解析输出视频文件的头部,不知道啥用

03-10 14:19:55.441 21706-22256/org.voiddog.ffmpeg D/TAG: stts: 0 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55.441 21706-22256/org.voiddog.ffmpeg D/TAG: stts: 3753 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55.441 21706-22256/org.voiddog.ffmpeg D/TAG: stts: 7507 ctts: 7507, ctts_index: 0, ctts_count: 699
03-10 14:19:55.441 21706-22256/org.voiddog.ffmpeg D/TAG: stts: 11260 ctts: 15015, ctts_index: 1, ctts_count: 699
03-10 14:19:55.441 21706-22256/org.voiddog.ffmpeg D/TAG: stts: 15014 ctts: 7508, ctts_index: 2, ctts_count: 699

获取编码器,和获取输入视频文件的媒体格式信息

03-10
14:19:55.600 21706-22256/org.voiddog.ffmpeg D/TAG: Parsing MediaFormat
{image-data=java.nio.HeapByteBuffer[pos=0 lim=104 cap=104],
mime=video/raw, crop-top=0, crop-right=1279, slice-height=720,
color-format=21, height=720, width=1280, crop-bottom=719, crop-left=0,
stride=1280}
03-10 14:19:55.601 21706-22256/org.voiddog.ffmpeg I/TAG:
Output crop parameters top=0 bottom=719 left=0 right=1279, resulting
dimensions width=1280 height=720
03-10 14:19:55.601 21706-22256/org.voiddog.ffmpeg D/TAG: MediaCodec 0xe4998b40 started successfully
03-10 14:19:55.601 21706-22256/org.voiddog.ffmpeg I/TAG: MediaCodec started successfully, ret = 0

获取输入视频文件的相关数据

03-10
14:19:55.643 21706-22256/org.voiddog.ffmpeg D/TAG: After
avformat_find_stream_info() pos: 1343 bytes read:93574 seeks:2 frames:4
03-10
14:19:55.643 21706-22256/org.voiddog.ffmpeg I/TAG: Input #0,
mov,mp4,m4a,3gp,3g2,mj2, from
'/storage/emulated/0/pauseRecordDemo/video/video.mp4':
03-10 14:19:55.643 21706-22256/org.voiddog.ffmpeg I/TAG:   Metadata:
03-10 14:19:55.643 21706-22256/org.voiddog.ffmpeg I/TAG:     major_brand     :
03-10 14:19:55.643 21706-22256/org.voiddog.ffmpeg I/TAG: mp42
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     minor_version   :
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 512
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     compatible_brands:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: isomiso2avc1mp41
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     encoder         :
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: HandBrake 0.10.0 2014112200
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:   Duration:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 00:00:31.81
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: , start:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 0.083000
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: , bitrate:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 1878 kb/s
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     Stream #0:0
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: (und)
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: , 3, 1/90000
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: : Video: h264 (avc1 / 0x31637661), nv12, 1280x720, 1728 kb/s
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: ,
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 23.98 fps,
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 23.98 tbr,
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 90k tbn,
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: 90k tbc
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:  (default)
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     Metadata:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:       handler_name    :
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: VideoHandler
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     Stream #0:1
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: (und)
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: , 1, 1/48000
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 146 kb/s
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:  (default)
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:     Metadata:
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG:       handler_name    :
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg I/TAG: Stereo
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Successfully opened the file.

配置输出视频文件的相关数据

03-10
14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Parsing a group of
options: output url
/storage/emulated/0/pauseRecordDemo/video/compress6.mp4.
03-10
14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Applying option
vcodec (force video codec ('copy' to copy stream)) with argument copy.
03-10
14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Applying option
acodec (force audio codec ('copy' to copy stream)) with argument copy.
03-10 14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.
03-10
14:19:55.644 21706-22256/org.voiddog.ffmpeg D/TAG: Opening an output
file: /storage/emulated/0/pauseRecordDemo/video/compress6.mp4.
03-10 14:19:55.648 21706-22256/org.voiddog.ffmpeg D/TAG: Setting default whitelist 'file,crypto'
03-10 14:19:55.649 21706-22256/org.voiddog.ffmpeg D/TAG: Successfully opened the file.
03-10
14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: Output #0, mp4, to
'/storage/emulated/0/pauseRecordDemo/video/compress6.mp4':
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:   Metadata:
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     major_brand     :
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: mp42
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     minor_version   :
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: 512
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     compatible_brands:
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: isomiso2avc1mp41
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     encoder         :
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: Lavf57.73.100
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     Stream #0:0
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: (und)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg D/TAG: , 0, 1/90000
03-10
14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: : Video: h264
([33][0][0][0] / 0x0021), nv12, 1280x720, q=2-31, 1728 kb/s
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: ,
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: 23.98 fps,
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: 23.98 tbr,
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: 90k tbn,
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: 90k tbc
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:  (default)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     Metadata:
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:       handler_name    :
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: VideoHandler
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     Stream #0:1
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: (und)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg D/TAG: , 0, 1/48000
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: : Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 146 kb/s
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:  (default)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:     Metadata:
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:       handler_name    :
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: Stereo

将输入视频文件的音视频流的前10秒数据复制到输出视频文件
明明是最重要的部分,却只有这点log

03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: Stream mapping:
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:   Stream #0:0 -> #0:0
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:  (copy)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:   Stream #0:1 -> #0:1
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG:  (copy)
03-10 14:19:55.650 21706-22256/org.voiddog.ffmpeg I/TAG: Press [q] to stop, [?] for help

统计出之前复制的数据的包

03-10
14:19:55.725 21706-22256/org.voiddog.ffmpeg I/TAG: frame=  244 fps=0.0
q=-1.0 Lsize=    2522kB time=00:00:10.06 bitrate=2052.0kbits/s speed=
136x    
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg I/TAG:
video:2280kB audio:233kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead:
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg I/TAG: 0.355927%
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: Input file #0 (/storage/emulated/0/pauseRecordDemo/video/video.mp4):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Input stream #0:0 (video):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: 245 packets read (2343932 bytes);
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Input stream #0:1 (audio):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: 474 packets read (238991 bytes);
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Total: 719 packets (2582923 bytes) demuxed
03-10
14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: Output file #0
(/storage/emulated/0/pauseRecordDemo/video/compress6.mp4):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Output stream #0:0 (video):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: 244 packets muxed (2335158 bytes);
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Output stream #0:1 (audio):
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG: 473 packets muxed (238407 bytes);
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg V/TAG:   Total: 717 packets (2573565 bytes) muxed
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg D/TAG: 0 frames successfully decoded, 0 decoding errors
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg D/TAG: Statistics: 60 seeks, 764 writeouts
03-10 14:19:55.725 21706-22256/org.voiddog.ffmpeg D/TAG: Statistics: 2662503 bytes read, 2 seeks

效果

这个compress6.mp4就是从video.mp4切割出来的,video.mp4是31秒,compress6.mp4是10秒的时长,他们的体积大小吻合时间比例。

 
博客首发地址
http://blog.csdn.net/z979451341

Android 音视频深入 二十一 FFmpeg视频剪切的更多相关文章

  1. Android 音视频深入 二十 FFmpeg视频压缩(附源码下载)

    项目源码https://github.com/979451341/FFmpegCompress 这个视频压缩是通过类似在mac终端上输入FFmpeg命令来完成,意思是我们需要在Android上达到能够 ...

  2. Android学习笔记(二十一)——实战:程序数据共享

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 我们继续在Database项目的基础上继续开发,通过内容提供器来给它加入外部访问接口.首先将 MyDataba ...

  3. android 项目学习随笔二十一(IM、语音识别、机器人、统计、扫描二维码、条形码)

    语音识别:科大讯飞语音云 http://www.xfyun.cn/ 语音机器人模拟 public class TalkBean { public String text; public boolean ...

  4. Android开发实战(二十一):浅谈android:clipChildren属性

    实现功能: 1.APP主界面底部模块栏 2.ViewPager一屏多个界面显示 3......... 首先需要了解一下这个属性的意思 ,即 是否允许子View超出父View的返回,有两个值true . ...

  5. Android核心分析之二十一Android应用框架之AndroidApplication

    Android Application Android提供给开发程序员的概念空间中Application只是一个松散的表征概念,没有多少实质上的表征.在Android实际空间中看不到实际意义上的应用程 ...

  6. Android学习路线(二十一)运用Fragment构建动态UI——创建一个Fragment

    你能够把fragment看成是activity的模块化部分.它拥有自己的生命周期,接受它自己的输入事件,你能够在activity执行时加入或者删除它(有点像是一个"子activity&quo ...

  7. Android开发系列(二十一):Spinner的功能和使用方法以及实现列表选择框

    Spinner是一个列表选择框.相当于弹出一个菜单供用户进行选择. Spinner继承AdapterView Spinnet支持的XML的属性: android:entries:使用数组资源设置该下拉 ...

  8. Android学习路线(二十四)ActionBar Fragment运用最佳实践

    转载请注明出处:http://blog.csdn.net/sweetvvck/article/details/38645297 通过前面的几篇博客.大家看到了Google是怎样解释action bar ...

  9. Android 音视频深入 十一 FFmpeg和AudioTrack播放声音(附源码下载)

    项目地址,求starhttps://github.com/979451341/AudioVideoStudyCodeTwo/tree/master/FFmpeg%E6%92%AD%E6%94%BE%E ...

随机推荐

  1. Literal绑定数据

    前台: <asp:Literal ID = "ChiCunShow" runat = "server"></asp:Literal> 后 ...

  2. ColumnStore完整验证指南之安装与启动停止

    官方文档https://mariadb.com/kb/en/library/mariadb-columnstore/ 推荐使用最新1.2.x最新版本. 先决条件 yum -y install boos ...

  3. 【POJ 2176】Folding

    [原题链接]传送门 [题面大意] 一个字符串,可以将它改写成循环节带括号的形式进行压缩,输出压缩长度最小的字符串. [题解思路] 1.没思路没思路,不知道怎么乱搞,大概就可以想到动态规划. 2.套路区 ...

  4. HDU 1074 Doing Homework【状压DP】

    Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...

  5. linux服务基础(一)之CentOS6编译安装httpd2.4

    安装http-2.4 Http依赖于apr-1.4+,apr-util-1.4+ CentOS6上默认是apr-1.3,apr-util1.3 先编译安装apr-1.5,apr-util-1.5 开始 ...

  6. 支持向量机(Support Vector Machine):对偶

    前言 学SVM看到对偶问题的时候很难受,因为看不懂,数学知识真的太重要了.后来在B站看到某up主的精彩推导,故总结如下. SVM基本型 由之前最大化间隔的计算可得SVM的基本型为: $\underse ...

  7. C++_day9am

    dynamic_cast static_cast reinterpret_cast #include <iostream> using namespace std; class A{ pu ...

  8. vitual dom实现(转)

    1. 通过JavaScript来构建虚拟的DOM树结构,并将其呈现到页面中: 2. 当数据改变,引起DOM树结构发生改变,从而生成一颗新的虚拟DOM树,将其与之前的DOM对比,将变化部分应用到真实的D ...

  9. MySQL优化查询 5.7版本

    1. 变更参数 : query_cache_type 如果何配置查询缓存: query_cache_type 这个系统变量控制着查询缓存工能的开启的关闭.query_cache_type=0时表示关闭 ...

  10. linux批量配置ip

    获取使用的网卡接口 ip a 2.查看系统版本 cat /etc/redhat-release 3.执行配置脚本 wget  http://d.sshby.com/biaozhun.tar&& ...