Reputation: 8214
I want to crop the audio and video based on length to show a sample of about 30 seconds along with saving the original audio or video file.
I am using this gem in Rails Paperclip-FFMPEG to generate the thumbnail image for videos.
But I also want to crop the video to a max length and also generate a sample audio for the audio by taking the first 30 seconds of the audio.
I looked at the docs but was not able to find any documentations or questions like this on Stackoverflow.
Does anyone know a solution on how to do this with paperclip-ffmpeg or another gem?
Thanks in advance.
Upvotes: 3
Views: 1302
Reputation: 11
I converted the ffmpeg commands above into a paperclip extension, hope this's useful.
https://github.com/jentzheng/paperclip_audio_crop
Upvotes: 0
Reputation: 3868
With paper clip you should use the following command of ffmpeg
to generate the crop audio/video:
ffmpeg -ss 0 -i file.mp3 -t 20 file.wav
Look at the -t
and -ss
arguments, it will do what you want:
-t duration
Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.
-ss position
Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.
For example, ffmpeg -ss 0 -t 20 -i inputfile.mp3 -acodec copy outputfile.mp3
It's start the video / audio from 0-20 seconds
-ss 0 - Start at 0 seconds
-t 30 - Capture 30 seconds (from 0, so 0:00 - 0:30). If you want 1 minute of audio, use -t 60.
-acodec copy - Stream copy (re-mux) the audio instead of re-encode it.
file.mp3 - Input file
file.wav - output file
Hope this will solve your problem.
Upvotes: 4