轉自:http://blog.csdn.net/simongyley/article/details/9984167php
一、將h264文件解碼爲yuv文件html
ffmpeg -i file.h264 file.yuvhtml5
ffmpeg 轉換linux
D:\ffmpeg\bin>ffmpeg.exe -i C:\Users\pc\Desktop\sp.mp4 -vf scale=500:-1 -t 100 ss.flvios
C:\Users\pc\Desttop\sp.mp4 是所須要轉換的文件地址web
scale=500:-1 表示準換後的視頻的寬度爲500px -1表示高度自適應,也能夠寫成500:500,表示寬度和高度都是500pxubuntu
-t 100 表示截取的視頻的時間爲100毫秒,bash
ss.flv表示命名的新文件名,文件存放在D盤.網絡
ffmpeg 截圖app
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秒之間的內容。
https://trac.ffmpeg.org/wiki/How to capture a webcam input
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
=
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/