FFmpeg 7.0.2
Since* 7.0
#

Generate a QR code using the libqrencode library (see https://fukuchi.org/works/qrencode/), and overlay it on top of the current frame.

To enable the compilation of this filter, you need to configure FFmpeg with --enable-libqrencode.

The QR code is generated from the provided text or text pattern. The corresponding QR code is scaled and overlayed into the video output according to the specified options.

In case no text is specified, no QR code is overlaied.

This filter accepts the following options:

qrcode_width, q, padded_qrcode_width, Q

Specify an expression for the width of the rendered QR code, with and without padding. The qrcode_width expression can reference the value set by the padded_qrcode_width expression, and vice versa. By default padded_qrcode_width is set to qrcode_width, meaning that there is no padding.

These expressions are evaluated for each new frame.

See the qrencode_expressionsqrencode Expressions section for details.

x, y

Specify an expression for positioning the padded QR code top-left corner. The x expression can reference the value set by the y expression, and vice.

By default x and y are set set to 0, meaning that the QR code is placed in the top left corner of the input.

These expressions are evaluated for each new frame.

See the qrencode_expressionsqrencode Expressions section for details.

case_sensitive, cs

Instruct libqrencode to use case sensitive encoding. This is enabled by default. This can be disabled to reduce the QR encoding size.

level, l

Specify the QR encoding error correction level. With an higher correction level, the encoding size will increase but the code will be more robust to corruption. Lower level is L.

It accepts the following values:

  • L
  • M
  • Q
  • H
expansion

Select how the input text is expanded. Can be either none, or normal (default). See the qrencode_text_expansionqrencode Text expansion section below for details.

text, textfile

Define the text to be rendered. In case neither is specified, no QR is encoded (just an empty colored frame).

In case expansion is enabled, the text is treated as a text template, using the qrencode expansion mechanism. See the qrencode_text_expansionqrencode Text expansion section below for details.

background_color, bc, foreground_color, fc

Set the QR code and background color. The default value of foreground_color is "black", the default value of background_color is "white".

For the syntax of the color options, check the "Color" section in the ffmpeg-utils manual.

#

qrencode Expressions

The expressions set by the options contain the following constants and functions.

dar

input display aspect ratio, it is the same as (w / h) * sar

duration

the current frame’s duration, in seconds

hsub, vsub

horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.

main_h, H

the input height

main_w, W

the input width

n

the number of input frame, starting from 0

pict_type

a number representing the picture type

qr_w, w

the width of the encoded QR code

rendered_qr_w, q, rendered_padded_qr_w, Q

the width of the rendered QR code, without and without padding.

These parameters allow the q and Q expressions to refer to each other, so you can for example specify q=3/4*Q.

rand(min, max)

return a random number included between min and max

sar

the input sample aspect ratio

t

timestamp expressed in seconds, NAN if the input timestamp is unknown

x, y

the x and y offset coordinates where the text is drawn.

These parameters allow the x and y expressions to refer to each other, so you can for example specify y=x/dar.

#

qrencode Text expansion

If expansion is set to none, the text is printed verbatim.

If expansion is set to normal (which is the default), the following expansion mechanism is used.

The backslash character \, followed by any character, always expands to the second character.

Sequences of the form %{...} are expanded. The text between the braces is a function name, possibly followed by arguments separated by ’:’. If the arguments contain special characters or delimiters (’:’ or ’}’), they should be escaped.

Note that they probably must also be escaped as the value for the text option in the filter argument string and as the filter argument in the filtergraph description, and possibly also for the shell, that makes up to four levels of escaping; using a text file with the textfile option avoids these problems.

The following functions are available:

n, frame_num

return the frame number

pts

Return the presentation timestamp of the current frame.

It can take up to two arguments.

The first argument is the format of the timestamp; it defaults to flt for seconds as a decimal number with microsecond accuracy; hms stands for a formatted [-]HH:MM:SS.mmm timestamp with millisecond accuracy. gmtime stands for the timestamp of the frame formatted as UTC time; localtime stands for the timestamp of the frame formatted as local time zone time. If the format is set to hms24hh, the time is formatted in 24h format (00-23).

The second argument is an offset added to the timestamp.

If the format is set to localtime or gmtime, a third argument may be supplied: a strftime C function format string. By default, YYYY-MM-DD HH:MM:SS format will be used.

expr, e

Evaluate the expression’s value and output as a double.

It must take one argument specifying the expression to be evaluated, accepting the constants and functions defined in qrencode_expressions.

expr_formatted, ef

Evaluate the expression’s value and output as a formatted string.

The first argument is the expression to be evaluated, just as for the expr function. The second argument specifies the output format. Allowed values are x, X, d and u. They are treated exactly as in the printf function. The third parameter is optional and sets the number of positions taken by the output. It can be used to add padding with zeros from the left.

gmtime

The time at which the filter is running, expressed in UTC. It can accept an argument: a strftime C function format string. The format string is extended to support the variable %[1-6]N which prints fractions of the second with optionally specified number of digits.

localtime

The time at which the filter is running, expressed in the local time zone. It can accept an argument: a strftime C function format string. The format string is extended to support the variable %[1-6]N which prints fractions of the second with optionally specified number of digits.

metadata

Frame metadata. Takes one or two arguments.

The first argument is mandatory and specifies the metadata key.

The second argument is optional and specifies a default value, used when the metadata key is not found or empty.

Available metadata can be identified by inspecting entries starting with TAG included within each frame section printed by running ffprobe -show_frames.

String metadata generated in filters leading to the qrencode filter are also available.

rand(min, max)

return a random number included between min and max

#

Examples

  • Generate a QR code encoding the specified text with the default size, overalaid in the top left corner of the input video, with the default size:

    qrencode=text=www.ffmpeg.org
  • Same as below, but select blue on pink colors:

    qrencode=text=www.ffmpeg.org:bc=pink@0.5:fc=blue
  • Place the QR code in the bottom right corner of the input video:

    qrencode=text=www.ffmpeg.org:x=W-Q:y=H-Q
  • Generate a QR code with width of 200 pixels and padding, making the padded width 4/3 of the QR code width:

    qrencode=text=www.ffmpeg.org:q=200:Q=4/3*q
  • Generate a QR code with padded width of 200 pixels and padding, making the QR code width 3/4 of the padded width:

    qrencode=text=www.ffmpeg.org:Q=200:q=3/4*Q
  • Make the QR code a fraction of the input video width:

    qrencode=text=www.ffmpeg.org:q=W/5
  • Generate a QR code encoding the frame number:

    qrencode=text=%{n}
  • Generate a QR code encoding the GMT timestamp:

    qrencode=text=%{gmtime}
  • Generate a QR code encoding the timestamp expressed as a float:

    qrencode=text=%{pts}