W3C home > Mailing lists > Public > public-media-fragment@w3.org > March 2009

Action 53 - Check whether ffmpeg can be used from clipping and cropping

From: Jack Jansen <Jack.Jansen@cwi.nl>
Date: Wed, 25 Mar 2009 14:58:03 +0100
Message-Id: <E5A2A573-8997-4D4C-B79A-74D05E2674E9@cwi.nl>
To: Media Fragment <public-media-fragment@w3.org>
I've investigated using ffmpeg for clipping and cropping, and the  
results are largely positive.

Why positive:
- ffmpeg can do temporal clipping
- ffmpeg can do spatial clipping
- ffmpeg can do track selection
- ffmpeg can usually[*] read from a pipe and write to a pipe (on Unix/ 
Linux/OSX), making it relatively easy to integrate.

Why largely (as opposed to unqualified positive):
- [*] reading from a pipe does not always work. For me, it worked for  
ogg/vorbis/theora but not for mpeg-4/h264/aac.
- the current ffmpeg (built from their subversion repository) appears  
to have a glitch: some things I tried gave an error (such as  
unsupported conversion or so) but re-running the exact same command  
would make it work.
- using this still requires some knowledge of the media file, as can  
be seen from the examples below[**]

Here's how I configured an ffmpeg that could be used for cropping/ 
clipping both ogg/vorbis/theora and mpeg-4/h264/aac
- Build and install libfaad, libfaac, libx64, libogg, libvorbis,  
libtheora (or make sure they're available, or fix the configure below,  
at the expense of not being able to do both formats)
- Configure ffmpeg with
	./configure --enable-gpl --enable-libfaad --enable-libx264 --enable- 
libvorbis --enable-libtheora

Here's how to use it. I'm using the examples from our "existing  
technology" wikipage, creating a temporal clip from 12.3s to 21.16s,  
and a spatial crop to l=25%, t=25%, w=50%, h=50%:

Simplest, copy file-to-file, do a temporal clip
	ffmpeg -i fragf2f.ogv -ss 12.3 -t 8.86 fragf2f-clipped.ogv
Same, but using pipes for input/output
	cat fragf2f.ogv | ./ffmpeg -i - -ss 12.3 -t 8.86 -acodec libvorbis  - 
f ogg - > fragf2f-clipped.ogv
Same, but also do spatial cropping:
	cat fragf2f.ogv | ./ffmpeg -i - -ss 12.3 -t 8.86 -acodec libvorbis - 
croptop 120 -cropbottom 120 -cropleft 160 -cropright 160 -f ogg - >  
Same, selecting only video stream:
	cat fragf2f.ogv | ./ffmpeg -i - -ss 12.3 -t 8.86 -an -croptop 120 - 
cropbottom 120 -cropleft 160 -cropright 160 -f ogg - > fragf2f-clipped- 

[**] As you can see from these examples, code using ffmpeg to do  
clipping and cropping will still need some knowledge of the media. For  
example, the -cropXXX parameters cannot be computed from our media  
fragment without knowing the native video size. Also, parameters like  
"-acodec libvorbis" and "-f ogg" depend on the source/destination  
media format. Also,
the video stream selection example depends on knowing there's only one  
audio stream and one video stream in the source material.

There's also an options to specify times in hh:mm:ss format, but I  
don't think it's frame-accurate, I haven't investigated fully.

All in all, if you would want to use this in a production system there  
would still be a lot of things that would need more investigation, but  
for the proof-of-concept implementations we're thinking of ffmpeg  
should be good enough.
Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma  
Received on Wednesday, 25 March 2009 13:58:45 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:27:42 UTC