x264enc

This element encodes raw video into H264 compressed data, also otherwise known as MPEG-4 AVC (Advanced Video Codec).

The pass property controls the type of encoding. In case of Constant Bitrate Encoding (actually ABR), the bitrate will determine the quality of the encoding. This will similarly be the case if this target bitrate is to obtained in multiple (2 or 3) pass encoding. Alternatively, one may choose to perform Constant Quantizer or Quality encoding, in which case the quantizer property controls much of the outcome, in that case bitrate is the maximum bitrate.

The H264 profile that is eventually used depends on a few settings. If dct8x8 is enabled, then High profile is used. Otherwise, if cabac entropy coding is enabled or bframes are allowed, then Main Profile is in effect, and otherwise Baseline profile applies. The high profile is imposed by default, which is fine for most software players and settings, but in some cases (e.g. hardware platforms) a more restricted profile/level may be necessary. The recommended way to set a profile is to set it in the downstream caps.

If a preset/tuning are specified then these will define the default values and the property defaults will be ignored. After this the option-string property is applied, followed by the user-set properties, fast first pass restrictions and finally the profile restrictions.

Some settings, including the default settings, may lead to quite some latency (i.e. frame buffering) in the encoder. This may cause problems with pipeline stalling in non-trivial pipelines, because the encoder latency is often considerably higher than the default size of a simple queue element. Such problems are caused by one of the queues in the other non-x264enc streams/branches filling up and blocking upstream. They can be fixed by relaxing the default time/size/buffer limits on the queue elements in the non-x264 branches, or using a (single) multiqueue element for all branches. Also see the last example below. You can also work around this problem by setting the tune=zerolatency property, but this will affect overall encoding quality so may not be appropriate for your use case.

Example pipeline

 gst-launch-1.0 -v videotestsrc num-buffers=1000 ! x264enc qp-min=18 ! \
   avimux ! filesink location=videotestsrc.avi

This example pipeline will encode a test video source to H264 muxed in an AVI container, while ensuring a sane minimum quantization factor to avoid some (excessive) waste. You should ideally never put H264 into an AVI container (or really anything else, for that matter) - use Matroska or MP4/QuickTime or MPEG-TS instead.

 gst-launch-1.0 -v videotestsrc num-buffers=1000 ! x264enc pass=quant ! \
   matroskamux ! filesink location=videotestsrc.mkv

This example pipeline will encode a test video source to H264 using fixed quantization, and muxes it in a Matroska container.

 gst-launch-1.0 -v videotestsrc num-buffers=1000 ! x264enc pass=5 quantizer=25 speed-preset=6 ! video/x-h264, profile=baseline ! \
   qtmux ! filesink location=videotestsrc.mov

This example pipeline will encode a test video source to H264 using constant quality at around Q25 using the 'medium' speed/quality preset and restricting the options used so that the output is H.264 Baseline Profile compliant and finally multiplexing the output in Quicktime mov format.

 gst-launch-1.0 -v videotestsrc num-buffers=1000 ! tee name=t ! queue ! videoconvert ! autovideosink \
   t. ! queue ! x264enc rc-lookahead=5 ! fakesink

This example pipeline will encode a test video source to H.264 while displaying the input material at the same time. As mentioned above, specific settings are needed in this case to avoid pipeline stalling. Depending on goals and context, other approaches are possible, e.g. tune=zerolatency might be configured, or queue sizes increased.

Hierarchy

GObject
    ╰──GInitiallyUnowned
        ╰──GstObject
            ╰──GstElement
                ╰──GstVideoEncoder
                    ╰──x264enc

Implemented interfaces

Factory details

Authors: – Josef Zlomek , Mark Nauwelaerts

Classification:Codec/Encoder/Video

Rank – primary

Plugin – x264

Package – GStreamer Ugly Plug-ins

Pad Templates

sink

video/x-raw:
      framerate: [ 0/1, 2147483647/1 ]
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
         format: { Y444, Y42B, I420, YV12, NV12, GRAY8, Y444_10LE, I422_10LE, I420_10LE }

Presencealways

Directionsink

Object typeGstPad


src

video/x-h264:
      framerate: [ 0/1, 2147483647/1 ]
          width: [ 1, 2147483647 ]
         height: [ 1, 2147483647 ]
  stream-format: { (string)avc, (string)byte-stream }
      alignment: au
        profile: { (string)high-4:4:4, (string)high-4:2:2, (string)high-10, (string)high, (string)main, (string)baseline, (string)constrained-baseline, (string)high-4:4:4-intra, (string)high-4:2:2-intra, (string)high-10-intra }

Presencealways

Directionsrc

Object typeGstPad


Properties

analyse

“analyse” GstX264EncAnalyse *

Partitions to consider

Flags : Read / Write

Default value : (none)


aud

“aud” gboolean

Use AU (Access Unit) delimiter

Flags : Read / Write

Default value : true


b-adapt

“b-adapt” gboolean

Automatically decide how many B-frames to use

Flags : Read / Write

Default value : true


b-pyramid

“b-pyramid” gboolean

Keep some B-frames as references

Flags : Read / Write

Default value : false


bframes

“bframes” guint

Number of B-frames between I and P

Flags : Read / Write

Default value : 0


bitrate

“bitrate” guint

Bitrate in kbit/sec

Flags : Read / Write

Default value : 2048


byte-stream

“byte-stream” gboolean

Generate byte stream format of NALU

Flags : Read / Write

Default value : false


cabac

“cabac” gboolean

Enable CABAC entropy coding

Flags : Read / Write

Default value : true


dct8x8

“dct8x8” gboolean

Adaptive spatial transform size

Flags : Read / Write

Default value : false


frame-packing

“frame-packing” GstX264EncFramePacking *

Set frame packing mode for Stereoscopic content

Flags : Read / Write

Default value : auto (-1)


insert-vui

“insert-vui” gboolean

Insert VUI NAL in stream

Flags : Read / Write

Default value : true


interlaced

“interlaced” gboolean

Interlaced material

Flags : Read / Write

Default value : false


intra-refresh

“intra-refresh” gboolean

Use Periodic Intra Refresh instead of IDR frames

Flags : Read / Write

Default value : false


ip-factor

“ip-factor” gfloat

Quantizer factor between I- and P-frames

Flags : Read / Write

Default value : 1.4


key-int-max

“key-int-max” guint

Maximal distance between two key-frames (0 for automatic)

Flags : Read / Write

Default value : 0


mb-tree

“mb-tree” gboolean

Macroblock-Tree ratecontrol

Flags : Read / Write

Default value : true


me

“me” GstX264EncMe *

Integer pixel motion estimation method

Flags : Read / Write

Default value : hex (1)


multipass-cache-file

“multipass-cache-file” gchararray

Filename for multipass cache file

Flags : Read / Write

Default value : x264.log


nal-hrd

“nal-hrd” GstX264EncNalHrd *

Signal Hypothetical Reference Decoder information.

Required for Blu-ray streams, television broadcast and a few other specialist areas.

It can be used for instance to force true CBR, and will cause the encoder to output NULL padding packets.

Flags : Read / Write

Default value : none (0)

Since : 1.26


noise-reduction

“noise-reduction” guint

Noise reduction strength

Flags : Read / Write

Default value : 0


option-string

“option-string” gchararray

String of x264 options (overridden by element properties) in the format "key1=value1:key2=value2".

Flags : Read / Write


pass

“pass” GstX264EncPass *

Encoding pass/type

Flags : Read / Write

Default value : cbr (0)


pb-factor

“pb-factor” gfloat

Quantizer factor between P- and B-frames

Flags : Read / Write

Default value : 1.3


psy-tune

“psy-tune” GstX264EncPsyTune *

Preset name for psychovisual tuning options

Flags : Read / Write

Default value : none (0)


qp-max

“qp-max” guint

Maximum quantizer

Flags : Read / Write

Default value : 51


qp-min

“qp-min” guint

Minimum quantizer

Flags : Read / Write

Default value : 10


qp-step

“qp-step” guint

Maximum quantizer difference between frames

Flags : Read / Write

Default value : 4


quantizer

“quantizer” guint

Constant quantizer or quality to apply

Flags : Read / Write

Default value : 21


rc-lookahead

“rc-lookahead” gint

Number of frames for frametype lookahead

Flags : Read / Write

Default value : 40


ref

“ref” guint

Number of reference frames

Flags : Read / Write

Default value : 3


sliced-threads

“sliced-threads” gboolean

Low latency but lower efficiency threading

Flags : Read / Write

Default value : false


speed-preset

“speed-preset” GstX264EncPreset *

Preset name for speed/quality tradeoff options (can affect decode compatibility - impose restrictions separately for your target decoder)

Flags : Read / Write

Default value : medium (6)


sps-id

“sps-id” guint

SPS and PPS ID number

Flags : Read / Write

Default value : 0


subme

“subme” guint

Subpixel motion estimation and partition decision quality: 1=fast, 10=best

Flags : Read / Write

Default value : 1


sync-lookahead

“sync-lookahead” gint

Number of buffer frames for threaded lookahead (-1 for automatic)

Flags : Read / Write

Default value : -1


threads

“threads” guint

Number of threads used by the codec (0 for automatic)

Flags : Read / Write

Default value : 0


trellis

“trellis” gboolean

Enable trellis searched quantization

Flags : Read / Write

Default value : true


tune

“tune” GstX264EncTune *

Preset name for non-psychovisual tuning options

Flags : Read / Write

Default value : (none)


vbv-buf-capacity

“vbv-buf-capacity” guint

Size of the VBV buffer in milliseconds

Flags : Read / Write

Default value : 600


weightb

“weightb” gboolean

Weighted prediction for B-frames

Flags : Read / Write

Default value : false


Named constants

GstX264EncAnalyse

Members

i4x4 (0x00000001) – i4x4
i8x8 (0x00000002) – i8x8
p8x8 (0x00000010) – p8x8
p4x4 (0x00000020) – p4x4
b8x8 (0x00000100) – b8x8

GstX264EncFramePacking

Members

auto (-1) – Automatic (use incoming video information)
checkerboard (0) – checkerboard - Left and Right pixels alternate in a checkerboard pattern
column-interleaved (1) – column interleaved - Alternating pixel columns represent Left and Right views
row-interleaved (2) – row interleaved - Alternating pixel rows represent Left and Right views
side-by-side (3) – side by side - The left half of the frame contains the Left eye view, the right half the Right eye view
top-bottom (4) – top bottom - L is on top, R on bottom
frame-interleaved (5) – frame interleaved - Each frame contains either Left or Right view alternately

GstX264EncMe

Members

dia (0) – dia
hex (1) – hex
umh (2) – umh
esa (3) – esa
tesa (4) – tesa

GstX264EncNalHrd

Signal HRD information. Required for Blu-ray streams, television broadcast and a few other specialist areas.

Members

none (0) – None
vbr (1) – Variable bitrate
cbr (2) – Constant bitrate

Since : 1.26


GstX264EncPass

Members

cbr (0) – Constant Bitrate Encoding
quant (4) – Constant Quantizer
qual (5) – Constant Quality
pass1 (17) – VBR Encoding - Pass 1
pass2 (18) – VBR Encoding - Pass 2
pass3 (19) – VBR Encoding - Pass 3

GstX264EncPreset

Members

None (0) – No preset
ultrafast (1) – ultrafast
superfast (2) – superfast
veryfast (3) – veryfast
faster (4) – faster
fast (5) – fast
medium (6) – medium
slow (7) – slow
slower (8) – slower
veryslow (9) – veryslow
placebo (10) – placebo

GstX264EncPsyTune

Members

none (0) – No tuning
film (1) – Film
animation (2) – Animation
grain (3) – Grain
psnr (4) – PSNR
ssim (5) – SSIM

GstX264EncTune

Members

stillimage (0x00000001) – Still image
fastdecode (0x00000002) – Fast decode
zerolatency (0x00000004) – Zero latency

The results of the search are