您当前的位置:年会直播网 > 技术教程 >

[ffmpeg]Encoding HLS with ffmpeg编码

时间:2016-10-30 来源:酷播 点击:

[ffmpeg]Encoding HLS with ffmpeg

  1. For starters here is the command to create a stream that is GOP aligned, that is has keyframes at regular intervals that can be nicely segmented. It is recommended to pull down and compile the latest version of ffmpeg for this as some of the distros can be a bit out of date. 
  2.  
  3. ffmpeg -y -i %(filename)s -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r %(fps)s -profile:v baseline -b:v %(bitrate)sk -maxrate %(bitrate)sk  -force_key_frames %(keyframe_str)s -s %(width)sx%(height)s %(target_dir)s%(newFile)s 
  4.  
  5. The s%(filename) are in Python format where the %s(var) bit gets replaced with your value. 
  6.  
  7. For example: 
  8.  
  9. ffmpeg -y -i infile.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 2000k -maxrate 2500k  -force_key_frames 50s -s 640×360 /tmp/newfile.ts 
  10.  
  11. I like to do segmenting as a second step just to keep the whole process a bit cleaner, especially if you want to produce multiple formats off the same initial encode: 
  12.  
  13. ffmpeg -y -i %(target_dir)s%(filename)s -codec copy -map 0 -f segment -segment_list %(target_dir)sindex_%(bitrate)s.m3u8 -segment_time %(segment_size)s  -segment_list_type m3u8 %(filenameNoExt)s_%(count)s.ts 
  14.  
  15. Or you could wrap it all into one command e.g. 
  16.  
  17. ffmpeg -y -i %(filename)s -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r %(fps)s -profile:v baseline -b:v %(bitrate)sk -maxrate %(bitrate)sk  -force_key_frames %(keyframe_str)s -s %(width)sx%(height)s %-f segment -segment_list %(target_dir)sindex_%(bitrate)s.m3u8 -segment_time %(segment_size)s  -segment_list_type m3u8 %(filenameNoExt)s_%(count)s.ts 
  18.  
  19. Working example: 
  20.  
  21. ffmpeg -y -i infile.mp4 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -maxrate 2000k -force_key_frames 50 -s 640×360 -map 0 -flags -global_header -f segment -segment_list /tmp/index_1500.m3u8 -segment_time 10 -segment_format mpeg_ts -segment_list_type m3u8 /tmp/segment%05d.ts 
  22.  
  23. Here is an example of capturing from the desktop Linux and streaming straight to a local web server configured for low latency: 
  24.  
  25. ffmpeg -f x11grab -s `xdpyinfo | grep ‘dimensions:’|awk ‘{print $2}’` -r 25 -i :0.0 -pix_fmt yuv420p -vcodec libx264 -acodec libfaac -r 25 -profile:v baseline -b:v 1500k -x264opts keyint=25 -s 640×360 -map 0 -flags -global_header -f segment -segment_list index_1500.m3u8 -segment_time 1 -segment_format mpeg_ts -segment_list_type m3u8 -segment_list_flags +live -segment_list_size 2 segment%05d.ts 
  26.  
  27. Tested with: 
  28.  
  29. ffmpeg version N-51554-g1c0d8f2 Copyright (c) 2000-2013 the FFmpeg developers 
  30.  
  31.   built on Apr  7 2013 18:35:14 with llvm-gcc 4.2.1 (LLVM build 2336.11.00) 
  32.  
  33.   configuration: —enable-libx264 —enable-libfaac —enable-nonfree —enable-gpl 
  34.  
  35.   libavutil      52. 24.100 / 52. 24.100 
  36.  
  37.   libavcodec     55.  2.100 / 55.  2.100 
  38.  
  39.   libavformat    55.  1.100 / 55.  1.100 
  40.  
  41.   libavdevice    55.  0.100 / 55.  0.100 
  42.  
  43.   libavfilter     3. 49.100 /  3. 49.100 
  44.  
  45.   libswscale      2.  2.100 /  2.  2.100 
  46.  
  47.   libswresample   0. 17.102 /  0. 17.102 
  48.  
  49.   libpostproc    52.  2.100 / 52.  2.100 
  50.  
  51. Hyper fast Audio and Video encoder 

 

标签: 年会直播 保利威视直播 企业级云直播 保利威视 企业级云视频 在线教育平台 视频云服务 PlaySafe 视频版权保护 视频加密 视频直播
实名验证 360网站安全检测