[FFmpeg-user] Possible to speed up/down video while keeping audio pitch?
Bo Berglund
bo.berglund at gmail.com
Mon Mar 25 16:22:02 EET 2024
On Mon, 25 Mar 2024 07:04:37 +0100, Bo Berglund <bo.berglund at gmail.com> wrote:
>I found the syntax as an example at
>
>http://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
>
>so I made a test.
>
>Note: Newsreader is doing the line wrap, it is on a single line of course:
>
>ffmpeg -hide_banner -i input.mp4 -filter_complex
>"[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
>
>It took 6 s to encode a 76 s mp4 video into a 38 s sped up video.
>
>So it seems like one must apply the inverse factor on setpts and atempo, i.e.
>change audio tempo by the inverse of the video speed.
>
>I tested it with speedups of 2.0 and 1.25 and both worked OK.
>
>So I will package this into a speedchange script among the other video utilities
>scripts I have created.
So while this works it takes a pretty long time to process. :(
Question:
Can this be integrated in the download script I use to retrieve the video in the
first place?
I have included a tweak to get the keyframes synced to whole seconds etc already
so the video can be edited on 1 s borders without getting artifacts at the
borders. It looks like this for download (again one single line command):
ffmpeg -hide_banner ${MODE} -i \"${M3U8URL}\" -r 30 -vf scale=w=-4:h=${VIDEORES}
-c:v libx264 -preset fast -crf 26 -x264-params keyint=30:scenecut=0:open-gop=0
-c:a aac -t ${CAPTURETIME} ${TARGETFILE}
Where
MODE="-referer \"${VIDEOURL}\""
M3U8URL=the m3u8 streaming URL of the source
VIDEORES="480"
CAPTURETIME=the time in seconds to capture the video
TARGETFILE=the output result mp4 file
Can the speedchange be pushed into this such that everything can happen while
the video downloads? In that case the processing time does not matter since the
transfer speed is low anyway.
I.e. how to pipe the output of the download function into the following
processing before landing in the output file:
-filter_complex"[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]"
--
Bo Berglund
Developer in Sweden
More information about the ffmpeg-user
mailing list