> Markdown version of [/magazine/621-efficiently-cut-huge-4k-videos-using-ffmpeg-and-php](https://www.wearedevelopers.com/magazine/621-efficiently-cut-huge-4k-videos-using-ffmpeg-and-php). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Efficiently Cut Huge 4K Videos Using FFMPEG and PHP **By:** [Chris Heilmann](https://www.wearedevelopers.com/@chris-heilmann) **Published:** August 20, 2025 What do you do when you face massive files you need to work with? Go back to the roots, in this case, the command line. The main stage at the WeAreDevelopers world congress has a lot of cameras that all record in 4K which results in footage stored in huge files: ![A folder full of video files ranging from 40 GB to 5 GB](https://wearedevelopers.imgix.net//magazine/articles/621/images/content/pCqinBVD0ZfElxNXc9Yo-1755603898.png?w=984&auto=compress,format) To create social media posts and shorts from the talks we needed to cut the recording of the whole stage into smaller videos of each talk without changing the resolution. So we needed a way to cut several huge files from one time stamp to another. Opening files that huge in an editor would be slow going, even on beefy machines and with streaming proxies. I neither had fancy editors nor more than a M2 Mac Mini. But I had the power of the command line and scripting skills. So here’s how you cut chunks out of several huge video files using PHP and [FFMPEG](https://ffmpeg.org/download.html). First, here is the command to FFMPEG to cut a part out of a video from timestamp to timestamp, for example from 1:22:00 to 1:56:00: ffmpeg -ss 1:22:00 -to 1:56:00 -i hugevideo.mp4 -c copy partvideo.mp4 Notice this is a copy command, there is no re-encoding or change to the video, which means it is pretty fast. Next I needed to loop over all the videos I wanted to edit. For this, I’m using PHP but you can also use Bash, Python or anything else you fancy. The script I ended up with was this: // Define FFMPEG as the tool and set it to only report errors, not log the whole process $tool = 'ffmpeg -hide_banner -loglevel error '; // The videos to batch edit - same recording from different angles $mp4s = array( "WaD25 Cam1_ch1_0106_0001.mp4", "WaD CamClean_ch4_0106_0001.mp4", "WaD25 Cam2_ch2_0106_0001.mp4", "WaD25 CamPGM_ch3_0106_0001.mp4", ); // run the FFMPEG command on each of them foreach ($mp4s as $mp4) { echo "Processing $mp4 \n\n"; $start = '1:22:00'; $end = '1:56:00'; $chunkname = str_replace('.mp4', '-chunked.mp4', $mp4); $cmd = $tool. "-ss $start -to $end -i '$mp4' -c copy '$chunkname'"; exec($cmd); } Here’s the script in action, cutting 6GB files from the 43GB ones in under a minute (sped up of course): ![the script in action showing how it creates shorter videos from the huge ones](https://wearedevelopers.imgix.net//magazine/articles/621/images/content/zRGTpCkVeArb36xWvZbY-1755603898.gif) If you ever find yourself having to edit massive files like that, this is one way of doing it. ## Related Articles - [Processing 175 WeAreDeveloper World Congress talk videos in 5 hours - with PHP?](https://www.wearedevelopers.com/magazine/466-processing-175-wearedeveloper-world-congress-talk-videos-in-5-hours-with-php) - [What Developers Really Need to Create Great Code Demos](https://www.wearedevelopers.com/magazine/658-what-developers-really-need-to-create-great-code-demos) - [5 Underrated Things You Can Do with Preview and QuickTime on Mac](https://www.wearedevelopers.com/magazine/612-5-underrated-things-you-can-do-with-preview-and-quicktime-on-mac) - [Create Videos Programmatically with React and Remotion](https://www.wearedevelopers.com/magazine/742-create-videos-programmatically-with-react-and-remotion) ## Related Videos - [Cat Herding with Lions and Tigers - Christian Heilmann](https://www.wearedevelopers.com/videos/1785-cat-herding-with-lions-and-tigers-christian-heilmann) - [Hate organising your photos? Try it with 5 Terabytes](https://www.wearedevelopers.com/videos/79-hate-organising-your-photos-try-it-with-5-terabytes) - [The Fundamentals of Online Video](https://www.wearedevelopers.com/videos/32-the-fundamentals-of-online-video) - [WeAreDevelopers LIVE – PHP Is Alive and Kicking and More](https://www.wearedevelopers.com/videos/1797-wearedevelopers-live-php-is-alive-and-kicking-and-more) ## Related Jobs - [Remote Senior Full-Stack Engineer](https://www.wearedevelopers.com/jobs/ext/356164-remote-senior-full-stack-engineer) at **Edge Impulse** - [Remote Senior Full-Stack Engineer](https://www.wearedevelopers.com/jobs/ext/679408-remote-senior-full-stack-engineer) at **Edge Impulse** - [Remote Senior Full-Stack Engineer](https://www.wearedevelopers.com/jobs/ext/683045-remote-senior-full-stack-engineer) at **Edge Impulse** - [Remote Senior Full-Stack Engineer](https://www.wearedevelopers.com/jobs/ext/639235-remote-senior-full-stack-engineer) at **Edge Impulse** - [Embedded Software Developer zur Entwicklung von Diagnoselösungen für den Sondermaschinenbau](https://www.wearedevelopers.com/jobs/ext/391912-embedded-software-developer-zur-entwicklung-von-diagnoselosungen-fur-den-sondermaschinenbau) at **Rosenxt Group** - [Remote Senior Full-Stack Engineer](https://www.wearedevelopers.com/jobs/ext/645320-remote-senior-full-stack-engineer) at **Edge Impulse**