🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 6 Min Lesezeit
0

Create a Smaller Video File with H.264 Encoding

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In the previous post, we created our first video file using GStreamer. The pipeline worked correctly, but there was one major problem: the generated file was very large.



The reason is simple. We stored every video frame as raw, uncompressed image data. While this is easy to understand, it is highly inefficient for storage and distribution.



In this post, we will introduce video compression using the H.264 codec and see how dramatically it reduces file size.






What You Will Learn




  • How to create a video file using H.264 encoding

  • The purpose of new GStreamer elements in the pipeline

  • The basics of video compression

  • Why encoded video files are much smaller than raw video files









Creating an H.264 Video File



The following pipeline generates a test video, compresses it using H.264, and stores it inside a Matroska (.mkv) container.




CODE
gst-launch-1.0 -e \
videotestsrc num-buffers=90 ! \
video/x-raw,width=1280,height=720,framerate=30/1 ! \
x264enc ! \
h264parse ! \
matroskamux ! \
filesink location=test.mkv






After the pipeline finishes, play the file using VLC, MPV, or any media player that supports H.264 video.




CODE
vlc test.mkv






The video should look identical to the one generated in the previous post.



Now let's inspect the file size:




CODE
ls -lh test.mkv






Example output:




CODE
-rw-r--r-- 821K test.mkv






The file is only 821 KB.



In the previous post, the same video stored as raw frames was approximately 159 MB.




















Format File Size
Raw Video ~159 MB
H.264 Encoded ~821 KB


This means the encoded file is roughly 193 times smaller while maintaining visually similar quality.



That is the power of video compression.









Understanding the Pipeline



Let's examine the new elements that were added.






videotestsrc






CODE
videotestsrc






Generates synthetic video frames.



These frames are still raw, uncompressed images.









x264enc






CODE
x264enc






This is the H.264 encoder.



It receives raw video frames and compresses them into the H.264 bitstream format.



Without this element, every frame would be written as raw pixel data, producing a very large file.









h264parse






CODE
h264parse






The parser analyzes and organizes the encoded H.264 stream.



Its responsibilities include:




  • Formatting the stream correctly

  • Extracting metadata

  • Preparing the stream for storage in a container

  • Improving compatibility with downstream elements



Think of it as a cleanup and packaging step between the encoder and the container.









matroskamux






CODE
matroskamux






A muxer (multiplexer) combines encoded streams into a container format.



In this case, it creates an MKV file.



The container stores:




  • Video data

  • Audio data (if present)

  • Metadata

  • Timing information



The container is not the codec.



A common beginner mistake is confusing:
























Component Example
Codec H.264
Container MKV
File Extension .mkv


The video is compressed using H.264 and then stored inside an MKV container.









What Is Video Encoding?



Video encoding converts raw video frames into a compressed representation.



Raw video contains enormous amounts of information.



For example, a single 1280×720 frame contains:




CODE
1280 × 720 × 3 bytes
≈ 2.6 MB






At 30 frames per second:




CODE
2.6 MB × 30
≈ 78 MB/s






Storing every frame directly would quickly consume hundreds of megabytes or even gigabytes.



Video encoders reduce this size by finding redundancy between frames.



Instead of storing every pixel of every frame, the encoder stores only the information that changes.









I, P, and B Frames



H.264 achieves high compression by categorizing frames into different types.






I-Frames (Intra Frames)



An I-frame contains a complete image.



It can be decoded independently without any other frame.



Think of it as a full snapshot.




CODE
Frame 1 (I)












P-Frames (Predicted Frames)



A P-frame stores only the differences from a previous frame.




CODE
Frame 1 (I)
Frame 2 (P)
Frame 3 (P)






If most of the image remains unchanged, the amount of stored data becomes much smaller.









B-Frames (Bi-directional Frames)



A B-frame can reference both previous and future frames.




CODE
Frame 1 (I)
Frame 2 (B)
Frame 3 (P)






This often provides even better compression efficiency.









What Is H.264?



H.264, also known as Advanced Video Coding (AVC), is one of the most widely used video compression standards ever created.



Its popularity comes from its ability to provide:




  • High compression ratios

  • Good visual quality

  • Broad hardware support

  • Compatibility across operating systems and devices



Although newer codecs exist, H.264 remains the default choice for many streaming, recording, and video storage applications.









Other Popular Video Codecs



H.264 is not the only option.



Some common alternatives are:




























Codec Notes
H.264 (AVC) Most widely supported
H.265 (HEVC) Better compression, higher complexity
VP9 Open-source codec developed by Google
AV1 Modern codec with excellent compression efficiency


Each codec makes different trade-offs between:




  • Compression ratio

  • Encoding speed

  • Decoding speed

  • Hardware support









Software vs Hardware Encoders



Not all encoders are implemented the same way.






Software Encoder



Our example uses:




CODE
x264enc






This runs entirely on the CPU.



Advantages:




  • Excellent quality

  • Highly configurable



Disadvantages:




  • Higher CPU usage

  • Slower encoding









Hardware Encoder



Modern GPUs and CPUs often contain dedicated video encoding hardware.



Examples include:




  • NVIDIA NVENC

  • Intel Quick Sync Video

  • AMD Video Coding Engine (VCE)

  • AMD Video Core Next (VCN)



A hardware encoder can often encode video several times faster than a software encoder while using significantly less CPU.



For NVIDIA GPUs, GStreamer provides hardware-accelerated encoders such as:




CODE
nvh264enc






or on DeepStream platforms:




CODE
nvv4l2h264enc






Hardware encoders are commonly used for:




  • Video streaming

  • Video conferencing

  • Real-time recording

  • AI video analytics pipelines









Exercises






Exercise 1



Generate a 10-second video at 1920×1080 resolution.



Measure the resulting file size.




CODE
video/x-raw,width=1920,height=1080






How much larger is it than the 1280×720 version?









Exercise 2



Replace the encoder with a hardware encoder if your system supports one.



Examples:




CODE
nvh264enc






Compare:




  • Encoding speed

  • CPU usage

  • File size









Exercise 3



Increase the number of generated frames:




CODE
num-buffers=300






How does the file size change?



Is the increase proportional to the number of frames?









Exercise 4



Try a different codec such as H.265 if available.



Compare:




  • File size

  • Encoding time

  • Playback compatibility









Summary



In this post, we moved from raw video storage to compressed video using H.264.



We learned:




  • Why raw video files are extremely large

  • How the x264enc element compresses video

  • The role of h264parse and matroskamux

  • The difference between codecs and containers

  • How H.264 uses I, P, and B frames to reduce file size

  • Why hardware encoders are important for real-time applications



Most real-world video pipelines use compressed formats because storing raw video is rarely practical. H.264 is often the first codec developers encounter, and understanding it provides a strong foundation for exploring more advanced codecs and streaming technologies.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Create a Smaller Video File with H.264 Encoding

Thematisch verwandte Begriffe: Create, Smaller, Video, File · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...