AnswerBun.com

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.

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

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 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

Add your own answers!

Related Questions

upgrade qt 5.6 to 5.9 in centos 7

1  Asked on November 26, 2021 by junius-l

     

how to send special characters in expect script?

1  Asked on November 26, 2021 by user2925298

       

How to define OpenVPN network in haproxy ACLs

1  Asked on November 26, 2021 by zili

       

How to install clang-10 on Ubuntu 20.4

4  Asked on November 26, 2021

       

Systemd service does not save changes to disk

1  Asked on November 26, 2021 by ken-lin

         

How do I split a file each time a regular expression occurs?

2  Asked on November 26, 2021 by edperez

 

Span /home on multiple partitions

1  Asked on November 23, 2021 by akshat-vats

     

Script to change current directory (cd, pwd)

11  Asked on November 23, 2021 by sony-santos

       

Root cannot change file permission or ownership

6  Asked on November 23, 2021

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir