Urgent.News

What's breaking now, across thousands of outlets.

Tech

Trimming Videos Is a Trade-off: copy-cut, re-encode, or filter-graph

Part of the Meicut Engineering series — how we build an in-browser media toolkit. ffmpeg -i in.mp4 -ss 60 -c copy -t 30 out.mp4 is everywhere. So is -i in.mp4 -c:v libx264 ... . And so is -filter_complex "...concat..." . Each one is presented as the way to trim a video. In practice there is no single best way: three mechanisms, three different trade-offs, and the right one depends entirely on…

Trimming videos can be achieved through three different methods: copy-cut, re-encode, and filter-graph splicing. Each approach has its own trade-offs, depending on the specific constraints and requirements.

Copy-cut is a lossless shortcut that tells ffmpeg not to decode or re-encode any data. It simply copies compressed packets and modifies container metadata. This method is significantly faster than any encoding process, as the bottleneck is usually I/O rather than CPU. However, it sacrifices frame accuracy since it can only cut between keyframes, resulting in a small delay (typically a fraction of a second to a couple of seconds) from the requested timestamp.

Additionally, the resulting output may not be frame-accurate, especially if B-frames are involved. Copy-cut is suitable for quick, bit-identical trims, such as removing intros or outros, or for batch processing files with consistent parameters.

The second method, re-encode with input seeking, offers frame-accurate results at the cost of speed. Input seeking locates the region at the demux level before a full re-encode produces the segment. By decoding from the nearest keyframe and starting to write exactly at the requested timestamp, this method ensures frame-level precision.

However, it is inherently slower due to the encoding process involved. The output is container-portable and filter-capable, allowing for adjustments like resolution changes, codec modifications, bitrate adjustments, and the application of effects such as fades.

The third approach, filter-graph splicing, combines trimming, timestamp resetting, and concatenation into a single -filter_complex pass. This method is frame-accurate and produces clean, continuous timestamp joins. It also allows for seamless transitions and applies effects in a single pass. Although it requires decoding the entire input to process multiple segments, the overall overhead is manageable, particularly when compared to performing separate re-encodes.

However, this method is more complex to implement and debug, and it can be resource-intensive for long files.

Ultimately, the choice between these methods depends on the specific needs of the project. For single-segment trims requiring frame accuracy, input seeking followed by re-encoding is the recommended approach. When multi-segment trims, precise fades, or cross-container output are essential, filter-graph splicing proves to be the most suitable solution. While each method has its trade-offs, understanding these aspects can help in making informed decisions based on the given constraints.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

[$] Vendor hooks in the Android kernel

Since Android's inception, the kernels it has used have diverged significantly from the mainline. While many of those differences have been resolved over time, and the move to the generic kernel image…

PERA Announces Jobs

The Punjab Enforcement and Regulatory Authority (PERA) has announced 110 job vacancies for qualified and experienced professionals across Lahore and … Read More The post PERA Announces Jobs appeared…

"In Betrieb" Is Not "Free". Live Connector Status Across Five European Countries.

Every European country now publishes where its public charge points are. That was the easy half, and the Alternative Fuels Infrastructure Regulation is the reason it happened: since April 2024…

  • EU mandates machine-readable data for public EV charging stations since April 2024.
  • Germany's registry shows 154,210 active charging records but only 116,422 with availability status.

A confidence number your model reports is not a measurement

A confidence number your model reports is not a measurement The prompt line is almost universal: Answer the question, and also report your confidence as a number between 0 and 1. The model obliges.

  • Confidence number is not a genuine measurement.
  • Measured numbers come from recorded outcomes in a database.
  • Decorative numbers remain constant regardless of question difficulty.

More from Thursday 15 October →