ffmpeg - how to split a .aac audio-file into small parts, exactly 4.00 seconds in size (so ignoring keyframes)

Unix & Linux Asked by s3n0 on December 1, 2020

How can I split the audio file .aac into small parts of exactly 4.0 seconds, ie. with ignoring keyframes?

The original video file was in .mp4 format. From this video file I got an .aac audio file. But the new parts of the split audio file always have 3.4 seconds and I need 4.0 seconds of audio. The problem is probably in key frames.


cd $DIR_IN
for file in *.mp4
    echo "Extracting the whole audio-track from $file to $DIR_TMP/${file%.mp4}.aac"
    ffmpeg -i "$file" -vn -acodec copy $DIR_TMP/"${file%.mp4}.aac"

    echo "Splitting the large video-file $file to a smaller audio-files '${file%.mp4}'XXX.aac"
    ffmpeg -i $DIR_TMP/"${file%.mp4}.aac" -c copy -f segment -segment_time 4 $DIR_TMP/"${file%.mp4}%03d.aac"

    rm -f $DIR_TMP/"${file%.mp4}.aac"

2 Answers

ffmpeg -i sourcefile.aac -f segment -segment_time 4 -c copy out%03d.aac will generate files of 4 seconds like out000.acc, out001.acc and so on. Note that last file may have time less than or equal to 4 seconds.

Reference: 'Split an audio stream at specified segment rate' example from

Answered by Abdul Rauf on December 1, 2020

Problem solved:

ffmpeg -i "$avfile" -c:v libx264 -crf 23 -map 0 -segment_time 4 -g 4 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*4)" -f segment /tmp/output/"${avfile%.mp4}%03d.mp4"

Answered by s3n0 on December 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP