CS-FreeStyle / 10000-How-To-Do-in-CS

1 stars 0 forks source link

learn ffmpeg #89

Open liuty10 opened 4 years ago

liuty10 commented 4 years ago

https://www.wowza.com/blog/streaming-protocols

https://github.com/leandromoreira/ffmpeg-libav-tutorial

RTSP: https://github.com/agsh/rtsp-ffmpeg/blob/master/example/ffmpeg-streaming-command-line.md https://blog.csdn.net/yeshennet/article/details/96993036

Different streaming protocols: https://news.mistserver.org/news/71/An+introduction+to+encoding+and+pushing+with+ffmpeg

liuty10 commented 4 years ago

Examples

FLV file Input to MP4 file, copy codecs

ffmpeg -i INPUT.flv -c copy OUTPUT.mp4

In all the examples below we'll assume you do not know the codecs and will want to replace them with H264/AAC.

RTMP stream Input to FLV file, reencode

ffmpeg -i rtmp://IP:PORT/live/STREAMNAME -c:a aac -strict -2 -c:v h264 OUTPUT.flv

MP4 file Input to RTMP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

HLS stream input to RTMP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

MP4 file input to RTSP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f rtsp -rtsp_transport tcp rtsp://IP:PORT/STREAMNAME

HLS stream input to RTSP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac -strict -2 -c:v h264 -f rtsp -rtsp_transport tcp rtsp://IP:PORT/STREAMNAME

RTSP stream input over TCP to RTMP stream, copy

*Using ffmpeg to ingest over TCP instead of UDP makes sure you don't have the packet loss problem that UDP has and gives a better and more stable picture for your stream. -rtsp_transport tcp -i CameraURL -c copy -f flv rtmp://IP:PORT/live/STREAMNAME Creating a multibitrate stream from a single input

This one is a bit advanced, but often asked for so I've opted to include it. In order to fully understand the command you'll need some explanation however. It's important to keep in mind that you will need to tell ffmpeg how many video/audio tracks you want and which track should be used as source for the options later on. First you start with mapping and selecting input tracks then you describe the encoder settings per track.

ffmpeg -i INPUT -map a:0 -map v:0 -map v:0 -c:a:0 copy -c:v:0 copy -c:v:1 h264 -b:v:1 250k -s:v:1 320x240 OUTPUT

To explain all of those options in more detail:

INPUT can be either a file or a stream for input
OUTPUT can be either a file or a stream for output
-map a:0 selects the first available audio track from the source
-map v:0 selects the first available video track from the source
-map v:0 selects the first available video track from the source a second time
-c:a:0 copy tells ffmpeg to copy the audio track without re-encoding it
-c:v:0 copy tells ffmpeg to copy the video track without re-encoding it
-c:v:1 h264 tells ffmpeg to also re-encode the video track in h264
-b:v:1 250k tells ffmpeg that this second video track should be 250kbps
-s:v:1 320x240 tells ffmpeg that this second video track should be at 320x240 resolution
liuty10 commented 4 years ago

https://blog.csdn.net/weixin_30716725/article/details/99430303

https://blog.csdn.net/qq_25005909/article/details/79098152

https://blog.csdn.net/weixin_42462202/article/details/98986535

https://blog.csdn.net/yangguangmeng/article/details/49977821

https://blog.csdn.net/weixin_30551963/article/details/96260503

https://blog.csdn.net/weixin_42462202/article/details/99068041

https://blog.csdn.net/bingqingsuimeng/article/details/79184948

liuty10 commented 4 years ago

webrtc https://webrtc.org.cn/category/basic/

https://www.cnblogs.com/SingleCat/p/11315349.html

https://zhuanlan.zhihu.com/p/86751078

liuty10 commented 4 years ago

HLS( HTTP Live Streaming)苹果公司提出的流媒体协议,直接把流媒体切片成一段段,信息保存到 m3u 列表文件中,可以将不同速率的版本切成相应的片。播放器可以直接使用 HTTP 协议请求流数据,可以在不同速率的版本间自由切换,实现无缝播放,省去使用其他协议的烦恼。缺点是延迟大小受切片大小影响,不适合直播,适合视频点播。 hls直播系统 https://www.cnblogs.com/tocy/p/using-ffmpeg-build-hls-live-system.html

RTSP (Real-Time Stream Protocol)由 Real Networks 和 Netscape 共同提出的,基于文本的多媒体播放控制协议。RTSP 定义流格式,流数据经由 RTP 传输。RTSP 实时效果非常好,适合视频聊天、视频监控等方向。

RTMP(Real Time Message Protocol) 由 Adobe 公司提出,用来解决多媒体数据传输流的多路复用(Multiplexing)和分包(packetizing)的问题,优势在于低延迟,稳定性高,支持所有摄像头格式,浏览器加载 Flash 插件就可以直接播放。

总结: HLS 延迟大,适合视频点播;RTSP 虽然实时性最好,但是实现复杂,适合视频聊天和视频监控;RTMP 强在浏览器支持好,加载Flash 插件后就能直接播放,所以非常火,相反在浏览器里播放 RTSP 就很困难了。

liuty10 commented 4 years ago

https://segmentfault.com/a/1190000020705277

liuty10 commented 4 years ago

https://www.cnblogs.com/dwj192/p/7068431.html

liuty10 commented 4 years ago

https://blog.csdn.net/FPGATOM/article/details/98782202

https://blog.csdn.net/hoyjam1/article/details/51281679

liuty10 commented 4 years ago

rtsp stream successfully: set up:

  1. install rtsp server: https://github.com/revmischa/rtsp-server
  2. install ffmpeg: https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

RUN:

  1. start rtsp server: sudo ./rtsp-server.pl

  2. stream a video: ffmpeg -re -i /home/tianyiliu/Desktop/output.avi -pix_fmt yuv420p -vcodec libx264 -maxrate 1M -bufsize 2M -tune zerolatency -preset faster -f rtsp rtsp://127.0.0.1:5545/stream

  3. pull the video: ffplay rtsp://127.0.0.1:554/stream

liuty10 commented 4 years ago

ffmpeg -i /home/tianyiliu/Desktop/USVA6833.MP4 -codec:v h264 -codec:a aac -s 1280x720 OUTPUT.mp4

liuty10 commented 4 years ago

ffmpeg -i ../OUTPUT.mp4 $filename%03d.bmp

liuty10 commented 4 years ago

ls -d -1 "$PWD/"*.* > bmp.txt

liuty10 commented 4 years ago

GPU supported Video operations: https://developer.nvidia.com/ffmpeg https://developer.nvidia.com/nvidia-video-codec-sdk/download https://devblogs.nvidia.com/nvidia-ffmpeg-transcoding-guide/ https://github.com/NVIDIA/video-sdk-samples https://www.cnblogs.com/shenxingping/articles/11387680.html

nvidia streaming https://www.nvidia.cn/geforce/broadcasting/

intel gpu accelerate video: https://mp.weixin.qq.com/s/VMbV_gf-IU5m3iUI6HyBMA https://mp.weixin.qq.com/s/q5afVBSiUzSt1nb_vmH0hg

stream framebuffer: https://superuser.com/questions/1240804/is-there-a-tool-for-broadcasting-a-video-from-the-linux-framebuffer

liuty10 commented 3 years ago

source code: https://blog.csdn.net/asd501823206/article/details/97013677