zoukankan      html  css  js  c++  java
  • ffmpeg 有用命令 (转载)

      转自:http://blog.csdn.net/simongyley/article/details/9984167

      

      1、将h264文件解码为yuv文件

           ffmpeg -i file.h264 file.yuv

    ffmpeg 转换

    D:ffmpegin>ffmpeg.exe -i C:UserspcDesktopsp.mp4 -vf scale=500:-1 -t 100 ss.flv

    C:UserspcDesttopsp.mp4 是所需要转换的文件地址

    scale=500:-1 表示准换后的视频的宽度为500px -1表示高度自适应,也可以写成500:500,表示宽度和高度都是500px

    -t 100 表示截取的视频的时间为100毫秒,

    ss.flv表示命名的新文件名,文件存放在D盘.

    ffmpeg 截图

    ffmpeg -i demo.mp4 -ss 10.1 -t 0.001 1.jpg

    截取demo.mp4的视频 从10.1秒开始 -t 0.001表示截取10.1秒的这张图片 保存为 1.jpg

    ffmpeg 裁剪

    ffmpeg -i demo.mp4 -filter:v "crop=10:20:100:100" out.mp4

    crop里的参数依次为: 左边距:右边距:宽度:高度

    ffmpeg 相同分辨率转flv

    ffmpeg -i demo.mp4 -vcodec copy -acodec copy out.flv

    Ipad 可以直接播放mp4,可以用html5的video标签

    <video width="555" height="315" controls preload="auto" src="demo.mp4"></video>

    ffmpeg 视频合成

    因为 ffmpeg 是支持切分 mp4 视频的,所以我就理所当然的以为 ffmpeg 是支持视频合并。直到今天同事找我问方法,才发现一直以为的方法是错误的, mp4 不支持直接 concate(丢人了。。。),赶紧补了一下能量,从网上抓来了多种实现。

    注: 这里的 mp4 指的是网上最多见的 h264+aac mpeg4 容器的方式

    ffmpeg + ts

    这个的思路是先将 mp4 转化为同样编码形式的 ts 流,因为 ts流是可以 concate 的,先把 mp4 封装成 ts ,然后 concate ts 流, 最后再把 ts 流转化为 mp4。

    1
    2
    3
    ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
    ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
    ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4

      

    将 aif 文件转换为 16 位有符号数,小端存储模式,8000 Hz 采样率:

    ffmpeg -i test.aif -f s16le -ar 8000 test.pcm


    将 44.1KHz 双声道 16 位有符号数小端存储的 PCM 数据编码为 AAC:

    ffmpeg -f s16le -ar 44100 -ac 2 -i test.pcm -acodec aac -strict experimental test.aac 


    将 4:2:0 的 YUV 文件编码为 H.264 ES 流(必须启用 ffmpeg 的 libx264 组件,即配置 ffmpeg 时:--enable-libx264):

    ffmpeg -pix_fmt yuv420p -s 176x144 -i test.yuv -f h264 test.264

    ffmpeg -pix_fmt yuv420p -s 176x144 -i test.yuv test.h264


    将 H.264 ES 流解码为 YUV 文件(必须启用 ffmpeg 的 rawvideo 组件,即配置 ffmpeg 时:--enable-encoder=rawvideo):

    ffmpeg -i test.264 test.yuv


    将 4:2:0 QCIF 大小的 YUV 文件转换为 4:2:2 CIF 大小的 YUV 文件:

    ffmpeg -pix_fmt yuv420p -s 176x144 -i foreman_qcif.yuv -pix_fmt yuv422p -s 352x288 test.yuv


    将一幅 4:2:0 QCIF 大小的 YUV 图像转换为 CIF 大小的 BMP 文件:

    ffmpeg -pix_fmt yuv420p -s 176x144 -i foreman_qcif.yuv -pix_fmt rgb24 -s 352x288 test.bmp


    将 y4m 格式的图像序列转换为 4:2:0 的 YUV 图像序列:

    ffmpeg -f yuv4mpegpipe -i test.y4m -pix_fmt yuv420p test.yuv


    将 AVI 文件转换为 H.264 视频 + AC3 音频的 MP4 文件,码率为 4M,视频量化区间为[10,45](必须启用 ffmpeg 的 libx264 组件,即配置 ffmpeg 时:--enable-libx264):

    ffmpeg -i test.avi -vcodec libx264 -b 4096000 -qmin 10 -qmax 45 -acodec ac3 test.mp4


    将 YUV 和 PCM 文件经过编码后输出成为 MPEG PS 文件:

    ffmpeg -pix_fmt yuv420p -s 720x576 -r 25 -b 8000000 -i test.yuv -f s16le -ac 2 -ar 48000 -ab 384000 -i test.pcm -f vob test.vob


    Linux 下采集视频并编码为 H.263 ES 流:

    ffmpeg -f video4linux2 -s 352*288 -r 25 -t 30 -i /dev/video0 -vcodec h263 -f h263 test.263


    录音(mp3或amr):
    ffmpeg -f oss -i /dev/dsp wheer.mp3
    ffmpeg -f oss -i /dev/dsp -ar 8000 -ab 10200 wheer.amr
    当然你还可以设一堆参数,如调节音量-vol 1024(256是默认值), 设定采样率-ar 8000,设定比特率-ab 122000等等。。。至于你想在麦克和声卡之间切换当然就可以求助于aumix了
    另外,在~/.bashrc中定义alias amrec='ffmpeg -f oss -vol 1024 -i /dev/dsp -ar 8000 -ab 10200',以后就用amrec file.amr录音了,压缩率极高,一小时音频才5M多:)

    屏幕录像:
    ffmpeg -f x11grab -s xga -r 60 -i :0.0+0+0 wheer.avi
    其中-f指定x11grab表示屏幕录像(*编译时必须加上--enable-x11grab选项*),-s设定尺寸,写成缩写或 1024x768格式均 可,-r设定fps,-i中的:0.0表示你的x11屏幕,+0,0表示偏移,如果你想录制某个小窗口,可以用xwininfo -frame来找到具体坐标。
    另外还有一堆参数可设,如比特率-b 200000,-vcodec为视频编码,还可加上-f oss -i /dev/dsp同时录音,用aumix将录音源调成麦克风就可以配音了,声音太小了用-vol改~~


    视频剪切:
    ffmpeg -ss 01:02:30 -t 00:10:00 -i test.mov -vcodec copy -acodec copy out.mov
    将视频文件 test.mov 从第1小时2分30秒开始截取10分钟时长,即截取 test.mov 中第1小时2分30秒到第1小时12分30秒之间的内容。


    How to capture a webcam input

    https://trac.ffmpeg.org/wiki/How to capture a webcam input

    Linux

    On Linux, we can use video4linux2(or shortly "v4l2") input device to capture live input (such as webcamera), like this:

    ffmpeg -f video4linux2 -r 25 -s 640x480 -i /dev/video0 out.avi
    

    or

    ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi
    

    If you need to set some specific parameters of your camera, youcan do that using ​v4l2-ctltool.

    You can find it in the fedora/ubuntu/debian package namedv4l-utils.

    Most probably you'll want to know what frame sizes / frame ratesyour camera supports and you can do that using: v4l2-ctl--list-formats-ext

    Also, you might want to correct brightness, zoom, focus, etc.with:

    v4l2-ctl -L
    

    and

    v4l2-ctl -c 
    

    =

    Streaming a simple RTP audio stream from FFmpeg

    https://trac.ffmpeg.org/wiki/StreamingGuide

    FFmpeg can stream a single stream using the ​RTPprotocol. In order to avoid buffering problems on the otherhand, the streaming should be done through the -re option, whichmeans that the stream will be streamed in real-time (i.e. it slowsit down to simulate a live streaming source.

    For example the following command will generate a signal, andwill stream it to the port 1234 on localhost:

    ffmpeg -re -f lavfi -i aevalsrc="sin(400*2*PI*t)" -ar 8000 -f mulaw -f rtp rtp://127.0.0.1:1234
    

    To play the stream with ffplay, run the command:

    ffplay rtp://127.0.0.1:1234
    

    Note that rtp by default uses UDP, which, for large streams, cancause packet loss. See the "point to point" section in thisdocument for hints if this ever happens to you.

    关于页面视频播放的一些总结

    1.如果文件比较大的话一般只能播放流媒体格式的文件,比如flv格式,采用边下载边播放的形式,所以如果文件不是flv格式的话需要按照上面所介绍的转换方式进行转换。

    2.文件的码率会影响下载的速度,如果当前网络为1M,那么想要流畅的播放视频文件的话,播放的文件的码率必须在1024Kbps以下,否则就需要进行转换,以达到最佳播放效果。

    更多关于Ffmpeg的介绍 http://ffmpeg.org/

    更多关于Jplayer的介绍 http://www.jplayer.org/

  • 相关阅读:
    luogu 1865 数论 线性素数筛法
    洛谷 2921 记忆化搜索 tarjan 基环外向树
    洛谷 1052 dp 状态压缩
    洛谷 1156 dp
    洛谷 1063 dp 区间dp
    洛谷 2409 dp 月赛题目
    洛谷1199 简单博弈 贪心
    洛谷1417 烹调方案 dp 贪心
    洛谷1387 二维dp 不是特别简略的题解 智商题
    2016 10 28考试 dp 乱搞 树状数组
  • 原文地址:https://www.cnblogs.com/lance-ehf/p/4167456.html
Copyright © 2011-2022 走看看