用mac版的ffmpeg可以直接支持h264编码,

用ubuntu的版本默认是不带h264压缩编码,只支持解码。

要像制作h264的文件,需要编译相关的源码。

参考的文章:

http://stackoverflow.com/questions/5678695/ffmpeg-usage-to-encode-a-video-to-h264-codec-format

I believe that by now the above answers are outdated (or at least unclear) so here's my little go at it. I tried compiling ffmpeg with the option --enable-encoders=libx264 and it will give no error but it won't enable anything (I can't seem to find where I found that suggestion).

Anyways step-by-step, first you must compile libx264 yourself because repository version is outdated:

  wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2tar --bzip2 -xvf last_x264.tar.bz2cd x264-snapshot-XXXXXXXX-XXXX/sudo ./configuresudo makesudo make install

And then get and compile ffmpeg with libx264 enabled. I'm using the latest release which is "Happiness":

wget http://ffmpeg.org/releases/ffmpeg-0.11.2.tar.bz2
tar --bzip2 -xvf ffmpeg-0.11.2.tar.bz2
cd ffmpeg-0.11.2/
sudo ./configure --enable-libx264 --enable-gpl
sudo make
sudo install

Now finally you have the libx264 codec to encode, to check it you may run

ffmpeg -codecs | grep h264

and you'll see the options you have were the first D means decoding and the first E means encoding

然后即使这样做,还是会在configure ffmpeg时出现找不到x264 lib的问题,然后幸好有人补充说要安装x264的静态库。

I found that make install for libx264 installed only the executable x264 program, but not the libraries. After I used install-lib-dev install-lib-shared and install-lib-static it worked fine (I'm not sure which of these is necessary but I succeeded with all three). –  Leigh Caldwell Jan 3 '13 at 21:38 

他说不确定是安装共享库还是静态库,我可以告诉他是最后一个,因为我逐一尝试,只有装完最后一个才ok的。

使用的方法:

ffmpeg的参数非常多,但我们实际上不需要全面了解,我们是要他干活的,不是拿他来研究的。

ffmpeg -h

显示帮助信息

ffmpeg -i Downloads/宙斯之子2014-1080.mp4 -s 1916x796 -b:v 600k herculet.mp4

把一个mp4文件压缩成码率是600kbps的mp4文件,由于没有指定编码格式,系统会用mpeg4v2来编码,这不是我想要的,我希望用h264,但遇到了一点问题,就是系统没有默认安装。

ffmpeg -i /home/huziqin/hercule2014-1080.mp4 -vcodec libx264 -s 1916x796 -vb 3000k -acodec copy  /home/share/her-merge2.mp4

这条命令才是压制成h264格式的,但是压制成h264格式占有的CPU资源很大,12线程的CPU没秒钟才完成10帧左右。

======================================

压出来的视频在电脑上能播放,但在安卓上不能播放,

估计是需要加一些参数,例如:profile,preset,bufsize之类

用这条命令压缩前面2分钟然后停止,大概50M左右大小的文件,放进安卓机器是可以播放,问题是不知道压完之后还行不行,压完一个文件要一晚上,明天才知道。

ffmpeg -i /home/huziqin/hercule2014-1080.mp4 -codec:v libx264 -profile:v high -preset slow -b:v 3000k -maxrate 6000k -bufsize 1000k -vf scale=-1:796 -threads 0 -strict -2 -codec:a aac -b:a 128k /home/share/output_file3.mp4

这个问题经过分析播放器的log,发现播放器需要识别为matroska格式的容器才能打开,但如果压缩成mp4格式,则当文件比较小的时候能打开,但文件大了就打不开。

 bool CDVDDemuxFFmpeg::Open(CDVDInputStream*, bool, bool) - probing detected format [mov,mp4,m4a,3gp,3g2,mj2]
V/XBMC    ( 3275): Debug Print: bool CDVDDemuxFFmpeg::Open(CDVDInputStream*, bool, bool) - Error, could not open file /mnt/usbhost1/720P/her-merge-aac2.mp4
V/XBMC    ( 3275): Debug Print: static bool CDVDFileInfo::ExtractThumb(const string&, CTextureDetails&, CStreamDetails*) - Error creating demuxer
bool CDVDDemuxFFmpeg::Open(CDVDInputStream*, bool, bool) - probing detected format [matroska,webm]
V/XBMC    ( 3275): Debug Print: bool CDVDDemuxFFmpeg::Open(CDVDInputStream*, bool, bool) - avformat_find_stream_info starting
V/XBMC    ( 3275): Debug Print: bool CDVDDemuxFFmpeg::Open(CDVDInputStream*, bool, bool) - av_find_stream_info finished
V/XBMC    ( 3275): Debug Print: Openi

开始我不知道matroska是什么,后来查了才知道就是mkv格式。简单来说就是这个播放器只支持比较小的mp4,如果文件大的话超过2G,就要压成mkv才可以识别。

因此把原先压好的文件用ffmpeg重新封装一遍就可以了。

ffmpeg -i /home/share/output_file4.mp4 -c:v copy -c:a copy -f matroska /home/share/output_file5.mkv

ffmpeg使用记录--解决了压制的视频在安卓不播放的问题相关推荐

  1. iphone html5直播,【小技巧】解决iPhone中video视频的行内播放

    如果我们希望在一个 内播放 视频,我们可能会这么写: // CSS: video {width: 100%; height: auto;} // HTML: 这在Android系统的手机中可以完美实现 ...

  2. 微信播放在服务器视频无法播放音乐,【bug解决】ios微信浏览器中背景音乐无法播放...

    我记得之前在一次项目中,出现过浏览报错: 所以在这次H5的制作中,我使用了iframe来加载音频文件,使用这种方式后,电脑端是没有问题的,但是当上传至服务器上在手机上浏览时,会出现点击音乐旋转按钮无法 ...

  3. python中使用ffmpeg进行视频指定时长截断(解决剪切后音视频不同步的问题)

    1. 获取视频时长 有两种方式获取视频总时长: python-ffmpeg( 获取的是视频总秒数 ) video_time = float(ffmpeg.probe(video)['format'][ ...

  4. 使用ffmpeg根据开始和结束时间剪切视频

    本文翻译自:Cutting the videos based on start and end time using ffmpeg I tried to cut the video using the ...

  5. 最简单的基于FFmpeg的移动端例子:IOS 视频转码器

    ===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...

  6. 最简单的基于FFmpeg的移动端例子:IOS 视频解码器

    ===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...

  7. 最简单的基于FFmpeg的移动端例子:Android 视频转码器

    ===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...

  8. 最简单的基于FFmpeg的移动端例子:Android 视频解码器-单个库版

    ===================================================== 最简单的基于FFmpeg的移动端例子系列文章列表: 最简单的基于FFmpeg的移动端例子:A ...

  9. FFmpeg入门详解之117:视频监控的架构和流程

    几张架构图带您快速了解视频监控 图一 图二 图三 图四 视频监控系统的简介 视频监控 视频监控是安全防范系统的重要组成部分,英文Cameras and Surveillance.传统的监控系统包括前端 ...

最新文章

  1. 1030 Travel Plan (30 分) 【难度: 中 / 知识点: 最短路】
  2. PoW 本质上是个去中心化的时钟
  3. iOS打电话发短信发邮件总结
  4. 这可能是关于Pytorch底层算子扩展最详细的总结了!
  5. c++程序设计(第三版) pdf_【好课传送】C++语言程序设计基础入门视频
  6. mysql排序显示行数的语句_MySQL中sql语句count(*),orderby,随机数据展示。
  7. python属性和方法的区别_Python中几种属性访问的区别与用法详解
  8. java fileinputreader_java BufferedReader,FileInputStream实现文本文件读/写
  9. [译].NET 4 中玩耍内存映射文件
  10. 9-10 原生安装 2
  11. hadoop常用的端口配置
  12. 倾斜摄影在高速道路勘测中的应用-案例
  13. pycharm专业版下载及Local Terminal_Failed to start [powershell.exe]
  14. 微信小程序----第二天(小程序 - 模板与配置)
  15. 计算机图形学 绘制正四面体
  16. deepin网速慢 自己摸索 已解决
  17. Android Fragmnet-Fragment数据交换以及ListFragment的使用
  18. excel表格下拉选项怎么设置_让表格美观好看几个Excel设置技巧
  19. 深圳 不景气_为什么经济不景气会帮助社交网络
  20. Fiddler工具的弱网模拟2G/3G/4G

热门文章

  1. 基于智能合约的银行借贷方案设计与实现
  2. hd集成显卡 linux驱动,ati 集成显卡HD3200 驱动安装
  3. 用Keras构建神经网络的3种方法
  4. WebRTC开源项目-手把手教你搭建AppRTC
  5. supermap+openlayers距离和面积测算
  6. 机器学习-无监督学习-聚类:聚类方法(二)--- 基于密度的聚类算法【DBSCAN文本聚类算法,密度最大值文本聚类算法】
  7. c0604 旋转魔方阵
  8. CMMI 3级精简并行过程综述
  9. 企业做CMMI3级认证,不满足条件可以做吗?
  10. python中rgb颜色_Python 转换RGB颜色值的示例代码