[FFmpeg-trac] #4905(undetermined:open): Splitting a flac file using -ss and -t creates chunks with wrong duration
FFmpeg
trac at avcodec.org
Mon Mar 20 07:48:42 EET 2023
#4905: Splitting a flac file using -ss and -t creates chunks with wrong duration
-------------------------------------+-------------------------------------
Reporter: cdrsgi | Owner: (none)
Type: defect | Status: open
Priority: normal | Component:
| undetermined
Version: git-master | Resolution:
Keywords: flac | Blocked By:
Blocking: | Reproduced by developer: 1
Analyzed by developer: 0 |
-------------------------------------+-------------------------------------
Comment (by martin):
I am facing this same issue:
Input flac File: https://file.io/D1EXEgJ0OtgM
I have a shell script `split_by_silence.sh` which takes an input audio
file, detects split points where silence (or very low volume audio)
occurs, and then splits the audio file **using ffmpeg** into the
individual split point segments.
So if 10 split points = 11 audio files exported.
When I run it on an mp3, it produces 11 files (as expected with my input
file) and each file has correct length metadata.
**But when ffmpeg splits a flac file, the metadata output for 'length' is
broken**
I've tried following the closest question, marked as a duplicate, here:
https://stackoverflow.com/questions/66732630/cutting-flac-using-ffmpeg-
does-not-change-timestamps-accordingly
By adding a step to re-encode my flac file in ffmpeg:
`ffmpeg -i full.flac -ss 0 -t 2241 fixed.flac`
Which I'm not sure if is working, but outputs a fixed.flac file. Which
when I run with my split command:
`ffmpeg -i "inputFile.flac" -c copy -map 0 -f segment -segment_times
"22,441,5567,1122,etc..." "%d_output.flac"
`
The output files still have broken flac 'length' metadata, like you can
see in my image, even though when opened in audacity, the file does have a
real length. ffmpeg just encoded the wrong value?
[![enter image description here][1]][1]
This is my current ffmpeg version:
```
$ ffmpeg
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg
developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
```
And here is my .sh file I run with
`$ ./split_by_silence.sh`
```
# -----------------------
# SPLIT BY SILENCE
# Requirements:
# ffmpeg
# $ apt-get install bc
# How To Run:
# $ ./split_by_silence.sh "full_lowq.flac" %03d_output.flac
# output title format
OUTPUTTITLE="%d_output.flac"
# input audio filepath
IN="/mnt/c/Users/marti/Documents/projects/split_by_silence2/full.flac"
# output audio filepath
OUTPUTFILEPATH="/mnt/c/Users/marti/Documents/projects/split_by_silence2"
# ffmpeg option: split input audio based on this silencedetect value
SD_PARAMS="-11dB"
MIN_FRAGMENT_DURATION=120 # split option: minimum fragment duration
export MIN_FRAGMENT_DURATION
# -----------------------
# step: ffmpeg
# goal: get comma separated list of split points (use ffmpeg to determine
points where audio is at SD_PARAMS [-18db] )
echo "_______________________"
echo "Determining split points..."
SPLITS=$(
ffmpeg -v warning -i "$IN" -af
silencedetect="$SD_PARAMS",ametadata=mode=print:file=-:key=lavfi.silence_start
-vn -sn -f s16le -y /dev/null \
| grep lavfi.silence_start= \
| cut -f 2-2 -d= \
| perl -ne '
our $prev;
INIT { $prev = 0.0; }
chomp;
if (($_ - $prev) >= $ENV{MIN_FRAGMENT_DURATION}) {
print "$_,";
$prev = $_;
}
' \
| sed 's!,$!!'
)
echo "split points list= $SPLITS"
# add '5.5' to each split\
IFS=',' read -ra SPLITS_ARRAY <<< "$SPLITS"
for i in "${!SPLITS_ARRAY[@]}"; do
SPLITS_ARRAY[i]=$(echo "${SPLITS_ARRAY[i]}+5.5" | bc)
done
SPLITS=$(IFS=','; echo "${SPLITS_ARRAY[*]}")
echo "SPLITS=$SPLITS"
# using the split points list, calculate how many output audio files will
be created
num=0
res="${SPLITS//[^,]}"
CHARCOUNT="${#res}"
num=$((CHARCOUNT + 2))
echo "_______________________"
echo "Exporting $num tracks with ffmpeg"
ffmpeg -i "$IN" -c copy -map 0 -f segment -segment_times "$SPLITS"
"$OUTPUTFILEPATH/$OUTPUTTITLE"
echo "Done."
echo "------------------------------------------------"
echo "$num TRACKS EXPORTED"
```
--
Ticket URL: <https://trac.ffmpeg.org/ticket/4905#comment:5>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list