Skip to main content

Media stream over HTTP

The Media stream over HTTP API provides the information that makes it possible to call for and obtain a media stream in a container format over HTTP using the features detailed below:

  • Create and configure URL requests and retrieve media data streams from your Axis devices with media.cgi .
  • Use standard media players and tools such as VLC and FFmpeg.

Media streams can be returned as either a Matroska or MP4 and supports both video and audio. Additionally, MP4 is compatible with the media container format supported by web browsers and can be rendered as a HTML5 video element.

Identification

  • API Discovery: id=media-cgi

Use cases

Live streaming

This example will show you how to use a client application to live stream video and audio from a camera.

1. Request a live stream.

ffplay 'http://<IP>/axis-cgi/media.cgi'

API references

media.cgi

Download a playable file

This example will show you how to download and save a live media clip from a camera.

1. Download a 5–second clip.

curl --output file.mkv --max-time 5 'http://<IP>/axis-cgi/media.cgi'

2. Play the clip.

vlc file.mkv

API references

media.cgi

Fetch an encrypted stream

This example will show you how to use a client application to download an encrypted media stream from a camera.

1. Use HTTPS for encrypted communication and download the media stream.

curl --output file.mkv 'https://<IP>/axis-cgi/media.cgi'

API references

media.cgi

API specifications

media.cgi

This method should be used when you want to fetch a media stream packaged in a specific container format.

Request

  • Security level: Viewer
  • Method: GET
http://<IP>/axis-cgi/media.cgi?<argument>=<data>[&<argument>=<data>[&...]]
URL optionValid valuesDefault valueDescription
audio1 (Audio) 0 (No audio)Audio.A#.EnabledSpecifies whether the audio should be included in the stream. Please note that you also need to enable audio support for the audio source with AudioSource.A#.AudioSupport=yes.
audiobitrateIntegerAudioSource.A#.BitRateThe audio bit rate.
audiochannel1Audio.A#.SourceThe audio source. Please note that it can not be used together with audiodeviceid and audioinputid.
audiocodecaac opusaacThe audio codec.
audiodeviceid0 ...Audio.A#.SourceThe audio device ID. Please note that it can not be used together with audiochannel.
audioinputid0 ...Audio.A#.SourceThe audio input ID. Please note that it can not be used together with audiochannel.
audionbrofchannels1 (Mono) 2 (Stereo)Audio.A#.NbrOfChannelsCan be either mono or stereo sound.
audiosamplerateIntegerAudioSource.A#.SampleRateThe audio sample rate.
camera1... quad1Selects the video source. Please note that this argument is only valid on Axis products with more than one video source, i.e. cameras with multiple view areas or video encoders with multiple video channels.
containermatroska mp4matroskaThe container format.
compression0...100Image.I#.Appearance.CompressionAdjusts the compression level of the image. Using a higher value corresponds to a higher compression, i.e. a lower quality and smaller image size.
fpsIntegerImage.I#.Stream.FPSSelects the frame rate. 0 means unlimited.
h264profilehigh main baseline([^1])Image.I#.MPEG.H264.ProfileThe H.264 profile that should be used.
mirror1 (Mirrored) 0 (Not mirrored)Image.I#.Appearance.MirrorEnabledSpecifies whether the image should be mirrored.
color1 (Color) 0 (Monochrome)Image.I#.Appearance.ColorEnabledSpecifies whether the image should be in color or monochrome.
resolutionStringImage.I#.Appearance.ResolutionThe resolution of the retrieved image. Use the parameter Properties.Image.Resolutions for a list of supported resolutions.
rotation0 90 180 270Product dependantRotates the image clockwise. The rotation alternatives on an Axis device is defined by the parameters Properties.Image.Rotation and Properties.Image.I#.Rotation. Please note that the URL option rotation is only valid on products without source rotation. Check if the parameter ImageSource.I#.SourceRotation=yes and if that is the case, use ImageSource.I#.Rotation instead.
streamprofileStringN/AThe name of a saved stream profile.
squarepixel0 1Image.I#.Appearance SquarePixelEnabledEnable/disable square pixel (aspect ratio) correction. The device will adjust the aspect ratio to make it appear as intended if the parameter is set to 1.
video1 (Video) 0 (No video)1Specify if video should be included in the stream.
videoabrmaxbitrateIntegerImage.I#.RateControl ABR.MaxBitrateThe maximum bitrate when bitrate mode is ABR.
videoabrretentiontimeIntegerImage.I#.RateControl ABR.RetentionTimeRetention time when bitrate mode is ABR.
videoabrtargetbitrateIntegerImage.I#.RateControl ABR.TargetBitrateTarget bitrate when bitrate mode is ABR.
videobitratemodeabr mbr vbrImage.I#.RateControl ModeThe bitrate mode.
videobitrateprioritynone framerate quality fullframerateImage.I#.RateControl PriorityThe bitrate priority.
videocodech264 h265h264The video codec.
videoframeskipmodedrop emptyImage.I#.MPEG.FrameSkipModeDetermines what should happen when either the rate controller or Zipstream skips a frame. drop: The frame won’t be transmitted. empty: An empty frame will be sent instead of the actual frame.
videomaxbitrateIntegerImage.I#.RateControl MaxBitrateThe maximum bitrate when bitrate mode is MBR.
videozfpsmodefixed dynamicImage.I#.MPEG.ZFpsModeThe Zipstream fps mode. fixed: The FPS will have its default value set for the stream. This value might vary between devices due to rate control limitations. dynamic: FPS changes will be triggered by motions in the scene.
videozgopmodefixed dynamicImage.I#.MPEG.ZGopModeThe Zipstream GOP mode. fixed: The GOP length is fixed and set to the product’s default value. dynamic: Unnecessary I-frames are removed to further reduce the bit rate. The default GOP lengths and configurable maximum GOP lengths (videozmaxgoplength) may vary between Axis products. The maximum GOP length is used in scenes with little to no motion, while the default GOP length is used for busy scenes.
videozmaxgoplengthIntegerImage.I#.MPEG.ZMaxGopLengthThe Zipstream maximum GOP length.
videozstrengthoff InterImage.I#.MPEG.ZStrengthThe Zipstream strength.

[1]: Please note that baseline is not available on all products. For a list of available values, see the parameter Properties.Image.H264.Profiles.

Return value - Success

note

The codecs={codecs} parameters listed with the Content-Types below should contain a comma-separated list of compatible codec strings detailed in RFC 6381.

  • HTTP Code: 200 OK

  • Content-Type(s)

    video/x-matroska; codecs={codecs}

  • video/mp4; codecs={codecs}

  • audio/x-matroska; codecs={codecs}

  • audio/mp4; codecs={codecs}

  • Video-Metadata-Transform

    A transformation matrix relative to the default rotation that describes how stream coordinates relates to the sensor coordinates. The matrix uses the following format: x1,y1,z1;x2,y2,z2;x3,y3,z3.

  • Video-Sensor-Transform

    An unrotated transformation matrix describing how stream coordinates relate to sensor coordinates.

  • Response body: The media in a container format (in this case a chunked HTTP transfer encoding).

Return value - Error

  • HTTP code: An error code found in the table below

  • Content-type

    text/html

  • Response body: An HTML code describing the error

Error codes

HTTP codeDescription
400Bad Request
401Unauthorized
403Forbidden
404Not Found
500Server Error
503Service Unavailable