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.
Thanks.
cd $DIR_IN
for file in *.mp4
do
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"
done
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 https://gist.github.com/protrolium/e0dbd4bb0f1a396fcb55
Answered by Abdul Rauf on December 1, 2020
Problem solved:
#!/bin/bash
avfile=/tmp/video.mp4
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP