ffmpeg常用命令

1、列举设备

ffmpeg -list_devices true -f dshow -i dummy
 

2、最简单的抓屏:

ffmpeg -f gdigrab -i desktop out.mpg  
 

从屏幕的(10,20)点处开始,抓取640x480的屏幕,设定帧率为5:

ffmpeg -f gdigrab -framerate 5 -offset_x 10 -offset_y 20 -video_size 640x480 -i desktop out.mpg

录麦克风和桌面

E:\\ffmpeg.exe -f gdigrab -framerate 25 -video_size 1366x768 -i desktop -f dshow -i audio="麦克风 (Realtek High Definition Audio)" -vcodec libx264  -preset:v ultrafast -tune:v zerolatency -pix_fmt yuv420p -q:v 1 -ar 22050 -ac 1 -s 1366x768 -y e://out.mp4

 

gdigrab    http://www.ffmpeg.org/ffmpeg-devices.html  网页帮助   参数帮助


Win32 GDI-based screen capture device. 
 

This device allows you to capture a region of the display on Windows. 
There are two options for the input filename: desktop or title=window_title


The first option will capture the entire desktop, or a fixed region of the desktop. The second option will instead capture the contents of a single window, regardless of its position on the screen. 


For example, to grab the entire desktop using ffmpeg: 


ffmpeg -f gdigrab -framerate 6 -i desktop out.mpg


Grab a 640x480 region at position 10,20: 
ffmpeg -f gdigrab -framerate 6 -offset_x 10 -offset_y 20 -video_size vga -i desktop out.mpg


Grab the contents of the window named "Calculator" 
ffmpeg -f gdigrab -framerate 6 -i title=Calculator out.mpg
 

ffmpeg抓屏并推送流到rtmp服务器中

D:\BaiduYunDownload\ffmpeg-shared\ffmpeg-bin\ffmpeg.exe -f dshow -i video="Integrated Camera" -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -s 480x320 -f flv rtmp://192.168.1.124/live/livestream  
 

//延时比较大,有可能是缓冲区太大的原因

D:\BaiduYunDownload\ffmpeg-shared\ffmpeg-bin\ffplay -max_delay 100000 "rtmp://192.168.1.124/live/livestream live=1"  

//打开会有点慢,但是没有延时
D:\BaiduYunDownload\ffmpeg-shared\ffmpeg-bin\ffplay.exe  -fflags nobuffer -f flv  "rtmp://192.168.1.124/live/livestream live=1"
 

3、rtmpdump 可使用命令

直播流
rtmpdump.exe -o savename.flv -r rtmp://127.0.0.1/live/testlive -v
点播流
rtmpdump.exe -o savename.flv -r rtmp://127.0.0.1/vod/test.flv 
直播需要加-v参数
 

 

4、将yuv编码成h264   

ffmpeg -i  src_480x272.yuv  aa.h264  提示  Output file #0 does not contain any stream
应该是 ffmpeg -s 480x272  -i  src_480x272.yuv  aa.h264    而且必须是放在 -i之前,确定是输入参数,否则变成输出参数了

 

5、如何设置logo

   设置logo

ffmpeg -y -i input.mp4 -vf "movie='D\:\path\logo.png' [logo];[in][logo] overlay=10:10 [out]" output.mp4

 

    设置磨砂,马赛克:去除logo

ffmpeg -i JINUSEAN.mp4 -vf delogo=x=72:y=32:w=168:h=86:band=10 output.mp4

 

 

 

6、直播地址:

 

 

香港卫视,

rtmp://live.hkstv.hk.lxdns.com/live/hks

美国中文卫视  

rtmp://media3.sinovision.net:1935/live/livestream

 

7、录制桌面和摄像头 实现画中画   

ffmpeg -f gdigrab -i desktop  -f dshow -i video="Integrated Camera"  -r 25 -c:v libx264 -preset ultrafast -filter_complex overlay=main_w-overlay_w-10:main_h-overlay_h-10 -acodec mp3 -ar 44100 -ac 2  -t 30  d:/video/desktopAndCamera.mp4  -y  

 

//设置一下第二个文件输出的大小,此时没有音频输入

ffmpeg -f gdigrab -i desktop  -f dshow -i video="Integrated Camera" -filter_complex "[1:v]scale=w=150:h=150:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=H-h-10[out]" -map "[out]" -movflags faststart   -t 30  d:/video/desktopAndCamera.mp4  -y

 

//添加音频    -map 是用几个输出    -map "[out]"相当于输出的第1个流      -map 2 相当于将第二个输入作为输出的第2个流

ffmpeg -f gdigrab -i desktop  -f dshow -i video="Integrated Camera" -f dshow -i audio="External Microphone (Conexant SmartAudio HD)" -filter_complex "[1:v]scale=w=150:h=150:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=H-h-10[out]" -map "[out]" -map 2 -movflags faststart -acodec mp3 -ar 44100 -ac 2  -t 30  d:/video/desktopAndCamera.mp4  -y

如果录制摄像头的时候出现卡顿,提示[video input] too full or near too full(101% of size: 3041280 [rtbufsize parameter])! ..

可以设置-thread_queue_size 50,类似于设置缓冲区队列长度,默认是8

命令也就是 

ffmpeg -f gdigrab -thread_queue_size 50 -i desktop  -f dshow -thread_queue_size 50 -i video="Integrated Camera"  -r 25 -c:v libx264 -preset ultrafast -filter_complex overlay=main_w-overlay_w-10:main_h-overlay_h-10 -acodec mp3 -ar 44100 -ac 2  -t 30  d:/video/desktopAndCamera.mp4  -y  

8、设置混音,多个音频文件合并成一个文件 使用的filter中的 amix

主要是针对于16位的表示大小    

     原理是 将同一点的音频 相加,得到的就是该点的值            参考 :http://blog.csdn.net/xiaojun111111/article/details/52692077

     ffmpeg.exe -re -i 1234.mp4 -f dshow -i audio=”立体声混音 (Realtek High Definition ” -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -t 10 out.mp4 -y

9、 用ffmpeg创建多个program的ts  

   参考: http://blog.csdn.net/xiaojun111111/article/details/52467815

ffmpeg -i d:/video/wangfeng.mp-i d:/video/quwanting.mp-map 0:0  -map 0:1 -map 1:0 -map 1:-copy -programtitle=CCTV1:program_num=1:st=0:st=1-program title=CCTV2:program_num=2:st=2:st=3--f mpegts d:/video/multiProgram.ts
 

10、合并文件

ffmpeg -safe 0 -y -f concat -i concat.txt -c copy -strict experimental -f mp4 TEMP_123.mp4

concat.txt 文件格式:

file 3cac8f76b06d4af69695c3d00ec0795f_h2642000000nero_aac16-1.mp4
file 3cac8f76b06d4af69695c3d00ec0795f_h2642000000nero_aac16-2.mp4
file 3cac8f76b06d4af69695c3d00ec0795f_h2642000000nero_aac16-3.mp4

 

11、给视频(无音频流)添加音频流:

    ffmpeg -re -i rtmp://onairzb.cdvcloud.com/d5039f/4859cc -f lavfi -i "anullsrc=r=44100:cl=stereo" -vcodec copy -acodec aac -ar 44100 -ac 2 -strict -2 -f flv rtmp://192.168.0.95/live/123456 

    其中ffmpeg 官方文档中 有 Video Source 和 Audio Source, 需要和 -f lavfi  (代表使用虚拟设备) 

    37 Audio Sources

  • 37.1 abuffer
    • 37.1.1 Examples
  • 37.2 aevalsrc
    • 37.2.1 Examples
  • 37.3 anullsrc
    • 37.3.1 Examples
  • 37.4 flite
    • 37.4.1 Examples
  • 37.5 anoisesrc
    • 37.5.1 Examples
  • 37.6 sine
    • 37.6.1 Examples

 

 

       40 Video Sources

  • 40.1 buffer
  • 40.2 cellauto
    • 40.2.1 Examples
  • 40.3 coreimagesrc
    • 40.3.1 Examples
  • 40.4 mandelbrot
  • 40.5 mptestsrc
  • 40.6 frei0r_src
  • 40.7 life
    • 40.7.1 Examples
  • 40.8 allrgb, allyuv, color, haldclutsrc, nullsrc, rgbtestsrc, smptebars, smptehdbars, testsrc, testsrc2, yuvtestsrc
    • 40.8.1 Commands

 

     可以查看官方文档

 

12.叠加多张logo:

ffmpeg -i d:/video/wangfeng.mp4 -i d:/video/logo.png -i d:/video/logo.png -filter_complex "overlay=x=10:y=10,overlay=x=W-w-10:y=H-h-10"  d:/video/wangfenglogo.mp4

ffmpeg -i d:/video/wangfeng.mp4 -i d:/video/logo.png -i d:/video/logo.png -filter_complex "[0:v]scale=960:640[sout],[1:v]scale=100:100[logo1],[sout][logo1]overlay=x=10:y=10[lout1],[2:v]scale=100:100[logo2],[lout1][logo2]overlay=x=W-w-30:y=H-h-30"  d:/video/wangfenglogo.mp4

ffmpeg -i d:/video/wangfeng.mp4  -filter_complex "[0:v]scale=960:640[sout],movie='d\:/video/logo.png'[m1],[m1]scale=100:100[logo1],[sout][logo1]overlay=x=10:y=10[lout1],movie='d\:/video/logo.png'[m2],[m2]scale=100:100[logo2],[lout1][logo2]overlay=x=W-w-30:y=H-h-30"  d:/video/wangfenglogo.mp4
 

12.1添加timeline,logo可以阶段显示

ffmpeg -i d:/video/wangfeng.mp4  -filter_complex "[0:v]scale=960:640[sout],movie='d\:/video/logo.png'[m1],[m1]scale=100:100[logo1],[sout][logo1]overlay=x=10:y=10:enable=between(t\,10.0\,20.0)[lout1],movie='d\:/video/logo.png'[m2],[m2]scale=100:100[logo2],[lout1][logo2]overlay=x=W-w-30:y=H-h-30"  d:/video/wangfenglogo.mp4

 

12.2 logo使用gif,无限循环,使用loop,setpts,shortest,注意window的ffmpeg 卡死有问题

transcode -y -i 'ftp://scott:[email protected]/lxj/1.mp4' -filter_complex "[0:v]scale=640:360[s363],movie=filename=\'ftp://scott:[email protected]/lxj/logo.gif\':loop=0,setpts=N/(FRAME_RATE*TB)[logomovie363_0],[logomovie363_0]scale=100:100[logoscale363_0],[s363][logoscale363_0]overlay=x=10:y=10:shortest=1[out363]" -map [out363] -c:v h264 -b:v 500k -crf 23 -r 25.0 -g 250 -map 0:a -c:a aac -ab 32k -ac 1 -ar 22050  -strict experimental -f mp4 TEMP_text123.mp4
 

13叠加字幕:

ffmpeg -i d:/video/wangfeng.mp4 -filter_complex [0:v]drawtext="fontfile=simsun.ttc:text='Test Text':x=100:y=50:fontsize=24:[email protected]:box=1:[email protected]"[dt1];[dt1]drawtext="fontfile=simsun.ttf:text='hello world':x=100:y=100:fontsize=24:[email protected]:box=1:[email protected]"[vout]  -map [vout]  d:/video/wangfeng_drawtext.mp4
 

14.视频加密:

最新的ffmpeg支持hls_enc_key hls_enc_uri
transcode_has_dash.bak  -timeout -1 -y   -i 'ftp://scott:[email protected]/lxj/1.mp4' -filter_complex "[0:v]scale=640:360[out371]" -map [out371] -c:v h264 -b:v 500k -crf 23 -r 25.0 -g 250 -map 0:a -c:a aac -ab 32k -ac 1 -ar 22050  -strict experimental -f hls -hls_time 10 -hls_segment_filename text132.m3u8_%d.ts -hls_list_size 0 -hls_enc_key encryptionkey128 -hls_enc_key_url http://192.168.0.85/  text132.m3u8

相应参数:
   "extra_param":" -hls_enc 1 -hls_enc_key encryptionkey128 -hls_enc_key_url 'http://192.168.0.85/file.key' ",
   "format":"hls",

   "output_file" : "text143.m3u8"

 

15.文件循环推流:

ffmpeg循环推流,添加genpts,不能copy文件,时间戳不递增导致问题

    ffmpeg  -threads 2  -fflags +genpts -stream_loop -1 -re -i wangfeng1.mp4 -c:v h264 -c:a aac -f flv rtmp://192.168.0.95/live/12345

 

你可能感兴趣的:(FFmpeg/FFplay)