ffmpeg

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

README

Debugging

ffmpeg can be used to debug SRTP streaming by using ffmpeg and ffplay. Install ffmpeg and ffplay via brew install ffmpeg --with-ffplay.

RTSP Streaming

  1. Create an RTSP stream

1.1. Raspberry Pi

ffmpeg -re -f video4linux2 -i /dev/video0 -map 0:0 -vcodec h264_omx -pix_fmt yuv420p -r 20 -f rawvideo -tune zerolatency -b:v 1500k -bufsize 1500k -payload_type 99 -ssrc 16132552 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params omz31e5SiZSneUySvSsIaFfu+NW2uWUl9+FHs3HD "srtp://192.168.0.14:58536?rtcpport=58536&localrtcpport=58536&pkt_size=1378"

1.2. Mac

ffmpeg -re -f avfoundation -i "1" -map 0:0 -vcodec libx264 -pix_fmt yuv420p -r 20 -f rawvideo -tune zerolatency -b:v 1500k -bufsize 1500k -payload_type 99 -ssrc 16132552 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params omz31e5SiZSneUySvSsIaFfu+NW2uWUl9+FHs3HD "srtp://192.168.0.14:58536?rtcpport=58536&localrtcpport=58536&pkt_size=1378"
  1. Create sdp file on receiver
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.0.14
t=0 0
a=tool:libavformat 58.17.101
m=video 58536 RTP/AVP 99
b=AS:300
a=rtpmap:99 H264/90000
a=fmtp:99 packetization-mode=1
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:omz31e5SiZSneUySvSsIaFfu+NW2uWUl9+FHs3HD
  1. Receive stream
ffplay -i <path-to-sdp-file> -protocol_whitelist file,udp,rtp

Bitrate

FFMPEG cannot set the bitrate on Rasbperry Pi, we have to do it manually with v4l2-ctl --set-ctrl video_bitrate=300000.

Streaming issues

ffmpeg only sends one H264 keyframe at the beginning of a RTP stream on the RPi because of https://video.stackexchange.com/a/21245 If we open the stream after it has been started using ffplay, we missed the keyframe and never get one – results in error: decode_slice_header error.

Therefore we have to start ffplay before starting streaming.

Documentation

Overview

Package ffmpeg lets you access the camera via ffmpeg to stream video and to create snapshots.

This package requires the `ffmpeg` command line tool to be installed. Install by running - `apt-get install ffmpeg` on linux - `brew install ffmpeg` on macOS

HomeKit supports multiple video codecs but h264 is mandatory. So make sure that a h264 decoder for ffmpeg is installed too. Audio streaming is currently not supported.

If you are running a RPi with Raspbian, it is recommended to use a v4l2 loopback device instead of access the camera via `/dev/video0` directly.

Index

Constants

This section is empty.

Variables

View Source
var Stderr = ioutil.Discard
View Source
var Stdout = ioutil.Discard

Functions

func EnableVerboseLogging

func EnableVerboseLogging()

EnableVerboseLogging enables verbose logging of ffmpeg to stdout.

func New

func New(cfg Config) *ffmpeg

New returns a new ffmpeg handle to start and stop video streams and to make snapshots. If cfg specifies a video loopback, ffmpeg configures a loopback to support simultaneous access to the video device.

func NewLoopback

func NewLoopback(inputDevice, inputFilename, loopbackFilename string) *loopback

NewLoopback returns a new video loopback.

Types

type Config

type Config struct {
	InputDevice      string
	InputFilename    string
	LoopbackFilename string
	H264Decoder      string
	H264Encoder      string
	MinVideoBitrate  int
	MultiStream      bool
}

Config contains ffmpeg parameters

type FFMPEG

type FFMPEG interface {
	PrepareNewStream(rtp.SetupEndpoints, rtp.SetupEndpointsResponse) StreamID
	Start(StreamID, rtp.VideoParameters, rtp.AudioParameters) error
	Stop(StreamID)
	Suspend(StreamID)
	Resume(StreamID)
	ActiveStreams() int
	Reconfigure(StreamID, rtp.VideoParameters, rtp.AudioParameters) error
	Snapshot(width, height uint) (*image.Image, error)
}

FFMPEG lets you interact with camera stream.

type StreamID

type StreamID string

StreamID is the type of the stream identifier

type StreamNotFoundError

type StreamNotFoundError struct {
	// contains filtered or unexported fields
}

func (*StreamNotFoundError) Error

func (e *StreamNotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL