Skip to content
streamneo.
Streaming Settings12 min read

How to Preserve Video Aspect Ratio in a GStreamer YouTube Loop Stream

Keep a GStreamer loop stream from stretching or cropping unexpectedly with aspect-ratio checks, explicit square-pixel caps and a pre-stream test.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

To keep a video from stretching or losing important edges in a GStreamer YouTube loop stream, scale it to the intended output canvas while preserving its display geometry. If the source and canvas have different aspect ratios, add borders to retain the whole picture or crop only when losing some edge content is acceptable.

Set the output dimensions and square-pixel aspect ratio explicitly, then inspect the negotiated caps and the actual preview before you begin the broadcast. Neither a scaling mode nor YouTube itself should be expected to correct a stretched or cropped picture automatically.

Identify the source and output aspect ratios

Start with the source file, not a guess based on its filename or how it looks in a media player. Record its width and height, then find out whether it has a non-square pixel aspect ratio or other display metadata that affects how it should appear. Pixel dimensions alone do not always describe the displayed shape.

For ordinary square-pixel footage, the aspect ratio is width divided by height. A 1280-by-720 image is 16:9; a 1440-by-1080 image is 4:3. These examples describe the shape, not a recommendation that every channel must use those resolutions. A portrait video, a recording with unusual pixel geometry, or a file intended to be shown inside a designed frame needs its own check.

Next, decide the shape of the output canvas. It should be the frame you intend viewers to see, rather than merely the dimensions that happen to be easiest to type into a pipeline. Compare the source ratio with the canvas ratio before choosing any scaling or crop step. If those ratios match, you can scale the picture to the output dimensions without creating empty areas or removing edges, subject to your source's display geometry and the formats supported downstream.

If the ratios differ, write down what matters in the shot. For a bhajan recording, the full harmonium or a line of lyrics at the bottom may be important. In a local news loop, the presenter's face and the channel's lower-third captions may sit near the sides or bottom. A lofi scene might tolerate a crop on one edge but not a title card. This simple review turns an abstract ratio mismatch into an editorial choice.

Do not confuse changing the canvas with changing the picture's proportions. If you stretch a 4:3 image until it fills a 16:9 frame, people and objects become wider. If you scale it proportionally, some canvas space remains unless you crop or add a designed background. The GStreamer pipeline settings used for a nonstop playlist are a separate concern from this geometry decision: a loop can run continuously and still have the wrong framing.

Choose fit-with-borders or crop

When the source and output ratios do not match, choose between keeping the entire source visible and filling the canvas by removing part of the source. These operations are not interchangeable. The right choice depends on what the video contains, and a channel may make a different choice for one programme than another.

Treatment What the viewer sees Main trade-off Use it when
Fit with borders The complete source picture, scaled proportionally inside the canvas Unused canvas space appears on one or two sides Edges, captions, instruments or scene context must stay visible
Crop to fill A proportional part of the source, cut to the canvas ratio Content beyond the crop is lost The remaining frame is more important than the edges
Stretch to fill The whole frame forced to unrelated dimensions Shapes are distorted Avoid it for normal footage

GStreamer's videoconvertscale element has an add-borders property that is true by default. When borders are needed to preserve display aspect ratio, it can add black borders so the picture fits inside the requested dimensions. That is a useful starting point when you cannot afford to lose any of the source. Read the element documentation for the property and supported behaviour in the version installed on your system.

Black borders are not always the final design you want. They may be acceptable for a lecture or a devotional recording, but a channel may prefer a background colour or a static visual treatment. That is a separate compositing decision: first preserve the source geometry, then decide what should appear in the remaining canvas space. Do not solve empty space by stretching the source unless distortion is genuinely intended.

Cropping is appropriate when the edges are expendable and filling the frame matters more. GStreamer's aspectratiocrop element crops to a requested ratio; its documented example converts 4:3 input to 16:9 by cutting part of the picture. See the official crop element documentation. Before using a crop, check the entire loop, including title cards, credits, embedded captions and any scene where a person moves towards an edge.

A practical crop check is to pause on the widest or busiest shot, then inspect the intended output frame. If a face, a line of text or an instrument is near an edge, test the crop with that shot rather than a centred scene. Cropping does not become safe merely because it looks acceptable on one frame. If edge content changes through the loop, inspect those scenes too.

Scale with videoconvertscale

A typical raw-video branch places videoconvertscale after decoding and before the encoder. It can handle scaling and pixel-format conversion in one element. The documentation says it tries to negotiate the same dimensions where possible, avoiding a scaling operation when one is not needed. That does not mean every combination of source, caps and encoder will behave identically; negotiation depends on the installed elements and downstream requirements.

For a fit-with-borders treatment, the relevant pattern is:

... . videoconvertscale add-borders=true . video/x-raw,width=1280,height=720,pixel-aspect-ratio=1/1 . ...encoder...

This is an illustrative branch, not a complete or tested YouTube pipeline. Replace the example canvas dimensions with the frame you intend to send, and confirm that the downstream encoder accepts the negotiated raw format. The caps filter constrains the media properties that can negotiate beyond it; it does not by itself guarantee that a source will be framed as you intended.

With the default border behaviour enabled, a source of a different ratio can fit within the requested canvas without stretching. If you disable add-borders, do not assume the element will instead crop to fill: inspect the resulting behaviour and use an explicit crop stage if that is your deliberate choice. Keep the transformation legible in the pipeline so that the next person maintaining it can tell whether the intention is preserve, crop or something else.

For an intentional crop-to-fill workflow, put the crop operation before scaling to the target dimensions, for example:

... . aspectratiocrop aspect-ratio=16/9 . videoconvertscale . video/x-raw,width=1280,height=720,pixel-aspect-ratio=1/1 . ...encoder...

This illustrates the order of operations rather than asserting that it is the right setting for every source. Choose the crop ratio to match the target canvas and verify that the crop element is available in your installation. Then check the result visually. A crop which is mathematically correct can still cut off a channel logo or captions.

Do not stack transformations casually. If an earlier part of the pipeline has already changed dimensions or display geometry, a later scale may preserve the altered frame rather than the original source. Trace the decoded raw-video branch and understand where caps are applied. If you are using a loop pipeline rather than a single clip, confirm that each item has compatible dimensions and framing; a setting that suits the first file may not suit the next. The continuous recorded-service workflow is a useful reminder that repeated playback and correct presentation are separate jobs.

Set output dimensions and square-pixel caps

Choose an output width and height whose ratio matches the canvas you have selected. For example, 1280 by 720 is a 16:9 canvas, while 1920 by 1080 is also 16:9 at a larger pixel count. These are examples, not requirements. The appropriate dimensions depend on the material, encoder and upload capacity you can sustain.

Make the pixel aspect ratio explicit in the raw-video caps, such as pixel-aspect-ratio=1/1. This says that each pixel is square. YouTube's live encoder guidance recommends square pixels and progressive scan; consult the current YouTube live encoder settings rather than relying on an old preset or a value copied from another pipeline. YouTube publishes other ingest recommendations as well, including codec, frame rate, bitrate and keyframe interval. Those are separate from aspect-ratio handling, but they matter to whether a live stream can be ingested reliably.

A caps fragment can therefore include width, height and pixel aspect ratio together:

video/x-raw,width=1280,height=720,pixel-aspect-ratio=1/1

Include a frame rate where your pipeline needs to constrain it, and check that it agrees with the decoder, encoder and intended stream. Avoid inserting a value merely because it appears in an example: caps must be compatible with the actual elements. The caps filter communicates a requirement; if upstream cannot provide it, negotiation may fail or produce a different arrangement than you expected.

The output canvas ratio and pixel aspect ratio answer different questions. Width and height describe the number of pixels in the frame. Pixel aspect ratio describes the shape of each pixel when displayed. Setting the canvas to a 16:9 width and height but leaving an unintended non-square pixel ratio can change the displayed geometry. Conversely, square pixels do not make a 4:3 canvas become 16:9. Check both.

Resolution also has a practical cost. Higher output dimensions require the encoder and connection to carry more data, and the bitrate must suit the upload available at the stream location. YouTube's published guidance gives bitrate recommendations by resolution, frame rate and codec; treat those as recommendations from YouTube, not a promise of quality or an automatic fit for your connection. Run an upload speed test and test with audio and movement similar to the actual stream. If your use case is a Hindi podcast with a still image, the always-on podcast stream setup can inform the wider workflow, but the image still needs correct output geometry.

Check negotiated caps before streaming

Do not wait for a viewer to report a stretched picture. First inspect what GStreamer actually negotiated, because a caps filter in the text of a pipeline is not proof that the final raw-video stream has the properties you intended. Negotiation happens across connected elements, and an encoder or converter may affect the formats available at each point.

For a basic pipeline test, run it with verbose output using gst-launch-1.0 -v. GStreamer's tutorial and tool documentation describe using verbose output to inspect caps produced by a pipeline; see the GStreamer launch tool documentation. Look at the raw-video caps immediately before encoding and confirm the width, height, frame rate and pixel-aspect-ratio. Check that the dimensions describe your intended canvas and that the pixel aspect ratio is square.

A concise pre-stream checklist is:

  • Does the final raw-video branch report the intended output width and height?
  • Does the output caps show pixel-aspect-ratio=1/1?
  • Is the negotiated frame rate the one you planned to use?
  • Did the pipeline negotiate successfully through the encoder, rather than only through the converter?
  • Does the output look proportionate, with the expected borders or crop?

If the values differ from the caps you requested, investigate rather than assuming the encoder or YouTube will repair the mismatch. Verify that the correct branch has the caps filter, that the element names and properties are supported by your installed GStreamer build, and that the source's display geometry is understood. Check the caps again after you make a change.

gst-launch-1.0 is useful for basic pipeline checks and debugging. It is not a substitute for building a production application around GStreamer's API; the project directs application developers towards the API and gst_parse_launch(). A small test pipeline is still valuable even if your long-running loop is launched by an application, because it can expose a caps mismatch before you send a live broadcast.

Verify framing in the output

Caps tell you what the pipeline negotiated, not whether the picture is composed well. Watch the actual output in a local preview or a private test stream before a public broadcast. Inspect the live preview in YouTube Live Control Room and check its stream-health messages. YouTube recommends testing in advance and monitoring stream health during an event; its guidance is worth checking again when you prepare the stream.

Use a representative sample rather than a single convenient frame. Check the beginning, middle and end of the loop, plus scenes where people or graphics approach the edge. With borders, confirm that the full source is visible and the bars are placed as intended. With a crop, verify that the lost area is genuinely unimportant. A still frame can miss movement that carries a face or caption into the cropped region.

If the preview is stretched, go back to the source and output geometry, then inspect the caps through the raw-video branch. If the output is cropped, distinguish between a deliberate aspectratiocrop step and an unexpected source or display-ratio interpretation. If borders appear on the wrong sides or are unexpectedly large, check the ratio values and whether a previous element has already scaled the picture.

Keep a copy of the last known-good pipeline and record which file or sample you tested with it. This is especially helpful for a 24/7 playlist where files are replaced over time. Test a changed source in the same output path before switching it into the loop. A pipeline can negotiate correctly while a particular file has a different ratio, embedded display metadata or edge-sensitive content.

Aspect ratio is one part of ingest readiness, not a guarantee that the stream will remain healthy overnight. The encoder, frame rate, bitrate, audio and network path also need testing. For a broader comparison of whether to keep a nonstop stream on a local computer or move it off-site, see the Mac mini versus cloud cost comparison. If the operational burden is repeatedly checking and restarting a stream when your own computer is off, StreamNeo removes that specific chore by taking an uploaded video and running it as a YouTube live stream from the cloud, with monitoring and automatic restarts.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

Should I add borders or crop a 4:3 source for a 16:9 stream?

Add borders when the whole 4:3 picture must remain visible; use a crop when the edges can be discarded and filling the 16:9 canvas matters more. Check the content near the edges before deciding, especially captions and faces. Neither choice is right for every source.

Does videoconvertscale preserve aspect ratio automatically?

Its add-borders property is true by default and adds borders when needed to keep display aspect ratio. Confirm the property and negotiated caps in your installed version, then inspect the output. Do not infer the final framing from the element name alone.

What caps should I check for YouTube?

Check the raw-video width, height, frame rate and pixel-aspect-ratio before the encoder. YouTube recommends square pixels, so an explicit pixel-aspect-ratio=1/1 is a useful part of the output caps. Also test the encoded stream and its preview before going live.

Will YouTube fix a stretched or cropped stream?

Do not rely on YouTube to correct your framing. Set the geometry in your pipeline and verify the actual output before streaming. A live preview can reveal presentation problems that negotiated caps alone cannot.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Streaming Settings guides ↗ · All topics ↗