I love new web tech, and was excited to see ffmpeg ported to WebAssembly so decided to build a free tool that uses it to:
- Clip/trim videos
- Overlay text and images
- Resize
- Create GIFs or convert to a web-friendly MP4
All of this done in your browser, without ever uploading a file to a web server! (* Except Safari, it doesn't support SharedArrayBuffers)
A little more:
I've been building a video creation app with my cofounder, and being a 2-man team, we wanted to think outside of the box on an "eng as marketing" strategy.
As a techy on a budget, ffmpeg.wasm sounded like the perfect library to make a powerful free tool without requiring a ton of server resources.
So we looked up some common tasks people want to do with videos and set out to build a quick tool to accomplish them.
I think there's a ton more we can build into this - it's been about a 2 week project, but thought it was cool enough to do an initial release now.
Hope you like it, and have suggestions on what we can improve!
Very cool! I see that SharedArrayBuffers are enabled again, after they were disable due to spectre!?
I have previously tinkered with ffmpeg in the browser and implemented a workaround[1] for the (then) missing pthread support. It turned out quite clunky, but worked.
Yeah, SharedArrayBuffers have been back and forth!
- First they were disabled due to Spectre.
- Chrome reenabled them.
- New HTTP headers were added for cross-origin resource partitioning.
- FF/Chrome are both requiring those headers (FF now, Chrome next month)
That's awesome that you've played around with this, too. It was quite a bit of fun :)
The first time, I moved it from auto-loading to when the user clicks convert to save on bandwidth.
The second time, I moved it to after a file is selected. That gives it time to load while users are presented with options before converting.
It's definitely a trade-off. For us, the choice was easy-ish because we want to keep the budget down as Indie Hackers, so we can't just offer a free tool that costs a ton in backend/serverless charges.
I agree it makes a lot of sense for stuff that could never be offered as a free back-end service. FFmpeg is a complex app as well, I tried to measure the the size of the binary + all shared libraries on my linux system and I came up with almost 180MB. I couldn't tell if the .WASM file was being transferred compressed either, it should compress more than 2x.
(This is how I tried to measure FFmpeg binary size, I have no idea if it is correct:
I'd be curious what difference it makes. Supposedly fastly compiles wasm down to native first, so it should run faster. Obviously fetch time would be faster since it's sitting on their hard drives. Data transfer would obviously be video file size and bandwidth dependent. A lot of variables there, but still it would be interesting to see even for your particular bandwidth and distance from a fastly server, for what file size the break even point is (for a few different operations).
I record little screencasts/demos regularly for embedding them on webpages and currently always convert them with the ffmpeg CLI to WEBM, but it's really cumbersome and hard to remember all the command line flags you need to use (especially with 2 passes). I don't really like online cloud converters though because each video needs to both be uploaded and downloaded again and I'm worried they do a lossy compression on the video behind the scenes. A simple to use, trustworthy, client-based webapp to do this would be amazing.
And end up with really good results out the other end. When I was rendering with pre-VP9 I needed a few more flags (stuff like crf) to maintain quality, but this works fine for most things. And has been really impressive on the filesize side of things.
The main reason why I use ffmpeg/edit videos is to take my 3440x1440 screen recordings and crop+resize them in a format friendly for twitter, otherwise twitter will do its own (additional?) resizing and compression which just destroys videos
Amy advice for someone trying to write code against the ffmpeg api for the first time? It's...esoteric and the "correct" way seems to be reading a bunch of ten year old blog posts by random uncertain people. Even the python binding devs have a disclaimer they aren't confident they understand everything they document, despite doing their best to read the source.
I'm using ffmpeg.wasm, it's basically ffmpeg compiled for the browser, and it's a simple layer where you basically treat it like the ffmpeg command, eg:
True! When I first started building a video creation app, I was flailing around with google searches to find snippets to use. It was such a relief to spend an hour reading ffmpeg docs to understand how it works.
I have managed to try it now, and indeed it is almost perfect for my use case :
Often I find videos on youtube for example which I want to show snippet to someone or save it. So I download it easily with youtube-dl but then clipping is never really easy (especially on linux).
To improve the tool it would be nice to play the part clipped with the sound to check if it's ok.
Also the tool failed to load one video.
Hey, this feedback is great! And it isn't even too difficult to add - we have live clipped playback in our main app.
When it failed to load the video, did it show a convert option that failed to load it as well? I think there are some limitations to the ffmpeg.wasm compile. Do you know the extension, or any details of the codecs, etc?
Oh that tool is neat, and they have a super slick UI!
Our tool definitely isn't as slick, but I think that has its benefits too. Like our trim interface doesn't look as nice, but shows a live preview of where you're at in the video.
Its amazing what we can do with modern browsers today.
Our app plug:
7 years back we did a quick tool to shrink JPG's in browser (Again needs Chrome or Firefox) without uploading images to server: http://shrinkjpeg.com
Seriously! We were trying to build our video editor in the same style (eg like tinypng and GIF optimizers).
It's so cool to do it all in the browser!
I even built a simple landing page creator that let you change text and images, then created a zip file that you could extract to your web host - no backend needed!
I think for me, CORS is the biggest hindrance to some of my ideas, esp. around editing, creation, and working with the content.
"You might have come across .mov while working with Apple softwares such as QuickTime, it was introduced in 1998 and uses a top secret compression algorithm. It is often quoted as the catalyst to Apple bringing feature length movie quality to their devices."
There are some pretty crazy security restrictions (no external scripts!) just to get ffmpeg running. I can't imagine the additional security precautions that would prevent exploits for WebGPU.
50 comments
[ 4.7 ms ] story [ 115 ms ] threadHi HN,
I love new web tech, and was excited to see ffmpeg ported to WebAssembly so decided to build a free tool that uses it to:
- Clip/trim videos - Overlay text and images - Resize - Create GIFs or convert to a web-friendly MP4
All of this done in your browser, without ever uploading a file to a web server! (* Except Safari, it doesn't support SharedArrayBuffers)
A little more:
I've been building a video creation app with my cofounder, and being a 2-man team, we wanted to think outside of the box on an "eng as marketing" strategy.
As a techy on a budget, ffmpeg.wasm sounded like the perfect library to make a powerful free tool without requiring a ton of server resources.
So we looked up some common tasks people want to do with videos and set out to build a quick tool to accomplish them.
I think there's a ton more we can build into this - it's been about a 2 week project, but thought it was cool enough to do an initial release now.
Hope you like it, and have suggestions on what we can improve!
I have previously tinkered with ffmpeg in the browser and implemented a workaround[1] for the (then) missing pthread support. It turned out quite clunky, but worked.
[1] https://phoboslab.org/files/ffmpeg-mt-fixed/
- First they were disabled due to Spectre. - Chrome reenabled them. - New HTTP headers were added for cross-origin resource partitioning. - FF/Chrome are both requiring those headers (FF now, Chrome next month)
That's awesome that you've played around with this, too. It was quite a bit of fun :)
We had to "optimize" loading it twice.
The first time, I moved it from auto-loading to when the user clicks convert to save on bandwidth.
The second time, I moved it to after a file is selected. That gives it time to load while users are presented with options before converting.
It's definitely a trade-off. For us, the choice was easy-ish because we want to keep the budget down as Indie Hackers, so we can't just offer a free tool that costs a ton in backend/serverless charges.
(This is how I tried to measure FFmpeg binary size, I have no idea if it is correct:
178092232)
I've been really happy with the results so far!
My ffmpeg which I compiled as follows (with my own filter)
is 21,387,880 bytesRunning with your command reports an additional 18,273,624 bytes
linux-vdso.so.1 (0x00007ffcbcdfd000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff60391b000) libmp3lame.so.0 => /usr/lib/x86_64-linux-gnu/libmp3lame.so.0 (0x00007ff6036a4000) libx264.so.152 => /usr/lib/x86_64-linux-gnu/libx264.so.152 (0x00007ff6032ff000) libx265.so.146 => /usr/lib/x86_64-linux-gnu/libx265.so.146 (0x00007ff60267e000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff60245f000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff60206e000) /lib64/ld-linux-x86-64.so.2 (0x00007ff605d14000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff601e6a000) libnuma.so.1 => /usr/lib/x86_64-linux-gnu/libnuma.so.1 (0x00007ff601c5f000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff6018d6000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff6016be000)
I guess it depends what you compile in.
https://github.com/ffmpegwasm/ffmpeg.wasm-core/blob/n4.3.1-w...
Overall I think the wasm size is pretty good, maybe even smaller than the non-wasm binaries to a first approximation.
If the tool is popular long term, we might do a serverless option to make it accessible to Safari users or something though.
Even our mp4s aren't very well-optimized right now.
If you work with video a bit and think this tool might be helpful to you, let me know!
We're trying to keep this tool super simple for our end users, but I think we might be able to add a webm preset.
If you'd like me to look into it, drop me an email: andrew@<domain in link> and show me a sample command :)
That sounds like a great use case for us to handle! Although I think ffmpeg in the browser loses some efficiency over the command line.
I think we added cropping as a possible future feature. I'll bet ffmpeg makes that really easy to do.
I think we should also work on optimizing the output size. I think we use a pretty high (err, low) -crf, which can result in ridiculous file sizes.
Thanks for the comment! Appreciate hearing use cases :)
I'm using ffmpeg.wasm, it's basically ffmpeg compiled for the browser, and it's a simple layer where you basically treat it like the ffmpeg command, eg:
ffmpeg.run(['-i', 'input.gif', ..., 'output.gif').then(() => { // handle output file })
And I'm still learning a ton :)
EDIT: working again now, looks pretty cool!
Might need to delete and repost later?
Unfortunately, of course, they then want to get paid during playback, but that's the reality for everyone already.
But also get it if you mean you're not in a good place to test the tool at the moment haha
To improve the tool it would be nice to play the part clipped with the sound to check if it's ok. Also the tool failed to load one video.
Good job !
When it failed to load the video, did it show a convert option that failed to load it as well? I think there are some limitations to the ffmpeg.wasm compile. Do you know the extension, or any details of the codecs, etc?
Our tool definitely isn't as slick, but I think that has its benefits too. Like our trim interface doesn't look as nice, but shows a live preview of where you're at in the video.
I want their UI and style haha
Would love to chat about what you guys doing.Potentially collab and improve both our products!
Reach out rahul@modfy.video
Our app plug: 7 years back we did a quick tool to shrink JPG's in browser (Again needs Chrome or Firefox) without uploading images to server: http://shrinkjpeg.com
It's so cool to do it all in the browser!
I even built a simple landing page creator that let you change text and images, then created a zip file that you could extract to your web host - no backend needed!
I think for me, CORS is the biggest hindrance to some of my ideas, esp. around editing, creation, and working with the content.
I haven't checked the exact hit, but that's mostly because our focus for this tool was on people who would never touch ffmpeg or a command line.
Also, the alternative for us would've been to upload remotely and run on Lambda or similar, which I think would lack hardware acceleration as well.
This description is absolutely killing me.
Adding the ability to loop the gif back and forth would be great!
https://donatstudios.com/GifAsZoomBackground
There are some pretty crazy security restrictions (no external scripts!) just to get ffmpeg running. I can't imagine the additional security precautions that would prevent exploits for WebGPU.