Opened 9 years ago
Last modified 16 months ago
#4905 open defect
Splitting a flac file using -ss and -t creates chunks with wrong duration
Reported by: | cdrsgi | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avfilter |
Version: | git-master | Keywords: | flac |
Cc: | whatdoido | Blocked By: | |
Blocking: | Reproduced by developer: | yes | |
Analyzed by developer: | no |
Description
Summary of the bug:
When i try to split a large flac files with ffmpeg, created chunks still have the large file's duration and sample count.
How to reproduce:
ffmpeg -v 9 -loglevel 99 -ss 0 -y -i "D:\1.flac" -vn -c:a copy -t 77.222 "C:\1_1.flac" Exit code: 0 Console output: ffmpeg version N-75563-g235381e Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.9.3 (GCC) configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib libavutil 55. 2.100 / 55. 2.100 libavcodec 57. 3.100 / 57. 3.100 libavformat 57. 2.100 / 57. 2.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 8.100 / 6. 8.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.100 / 2. 0.100 libpostproc 54. 0.100 / 54. 0.100 Splitting the commandline. Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'. Reading option '-ss' ... matched as option 'ss' (set the start time offset) with argument '0'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-i' ... matched as input file with argument 'D:\Mp3\Pearl Jam\Pearl Jam\1991 - Ten\01 - Pearl Jam - Once.flac'. Reading option '-vn' ... matched as option 'vn' (disable video) with argument '1'. Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'copy'. Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '77.222'. Reading option 'C:\1_1.flac' ... matched as output file. Finished splitting the commandline. Parsing a group of options: global . Applying option v (set logging level) with argument 9. Applying option y (overwrite output files) with argument 1. Successfully parsed a group of options. Parsing a group of options: input file D:\Mp3\Pearl Jam\Pearl Jam\1991 - Ten\01 - Pearl Jam - Once.flac. Applying option ss (set the start time offset) with argument 0. Successfully parsed a group of options. Opening an input file: D:\Mp3\Pearl Jam\Pearl Jam\1991 - Ten\01 - Pearl Jam - Once.flac. Probing aac score:1 size:2048 Probing flac score:50 size:2048 [flac @ 00000000002e2f60] Format flac probed with size=2048 and score=50 [flac @ 00000000002e2f60] Before avformat_find_stream_info() pos: 1973 bytes read:32768 seeks:0 [flac @ 00000000002ecc00] sample/frame number mismatch in adjacent frames Last message repeated 14 times [flac @ 00000000002e2f60] All info found [flac @ 00000000002e2f60] 0: start_time: 0.000 duration: 10.216 [flac @ 00000000002e2f60] stream: start_time: 0.000 duration: 231.667 bitrate=919 kb/s [flac @ 00000000002e2f60] After avformat_find_stream_info() pos: 19381 bytes read:32768 seeks:0 frames:1 [flac @ 00000000002e2f60] read_seek: 0 0 [flac @ 00000000002e2f60] gen_seek: 0 0 [NULL @ 00000000002ecc00] sample/frame number mismatch in adjacent frames Last message repeated 14 times Input #0, flac, from 'D:\Mp3\Pearl Jam\Pearl Jam\1991 - Ten\01 - Pearl Jam - Once.flac': Metadata: ALBUM : Ten ALBUMARTISTSORT : Pearl Jam ARTIST : Pearl Jam ARTISTSORT : Pearl Jam CATALOGNUMBER : 88697398492 COMMENT : Track 1 DATE : 2009-03-23 disc : 1 GENRE : Grunge LABEL : Bertelsmann Music Group LANGUAGE : eng MEDIA : CD MUSICBRAINZ_ALBUMARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_ALBUMID: 06fc304e-d70a-4846-93e5-544d6aa618d6 MUSICBRAINZ_ARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_TRACKID: 94bed552-376f-492d-8e87-f470aa7fda0c MUSICIP_PUID : 15ee9b0f-beda-b60f-cb39-e59d719d9f67 ORIGINALDATE : 1991-08-27 RELEASECOUNTRY : GB RELEASESTATUS : official RELEASETYPE : album SCRIPT : Latn TITLE : Once track : 01 REPLAYGAIN_ALBUM_GAIN: -5.72 dB REPLAYGAIN_ALBUM_PEAK: 1.119748 REPLAYGAIN_TRACK_GAIN: -6.22 dB REPLAYGAIN_TRACK_PEAK: 0.950928 ENCODEDBY : Easy CD-DA Extractor (http://www.poikosoft.com) TOTALTRACKS : 11 TOTALDISCS : 2 album_artist : Pearl Jam Duration: 00:03:51.67, start: 0.000000, bitrate: 919 kb/s Stream #0:0, 1, 1/44100: Audio: flac, 44100 Hz, stereo, s16 Side data: replaygain: track gain - -6.220000, track peak - 0.000022, album gain - -5.720000, album peak - 0.000026, Successfully opened the file. Parsing a group of options: output file C:\1_1.flac. Applying option vn (disable video) with argument 1. Applying option c:a (codec name) with argument copy. Applying option t (record or transcode "duration" seconds of audio/video) with argument 77.222. Successfully parsed a group of options. Opening an output file: C:\1_1.flac. Successfully opened the file. Output #0, flac, to 'C:\1_1.flac': Metadata: ALBUM : Ten ALBUMARTISTSORT : Pearl Jam ARTIST : Pearl Jam ARTISTSORT : Pearl Jam CATALOGNUMBER : 88697398492 DESCRIPTION : Track 1 DATE : 2009-03-23 DISCNUMBER : 1 GENRE : Grunge LABEL : Bertelsmann Music Group LANGUAGE : eng MEDIA : CD MUSICBRAINZ_ALBUMARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_ALBUMID: 06fc304e-d70a-4846-93e5-544d6aa618d6 MUSICBRAINZ_ARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_TRACKID: 94bed552-376f-492d-8e87-f470aa7fda0c MUSICIP_PUID : 15ee9b0f-beda-b60f-cb39-e59d719d9f67 ORIGINALDATE : 1991-08-27 RELEASECOUNTRY : GB RELEASESTATUS : official RELEASETYPE : album SCRIPT : Latn TITLE : Once TRACKNUMBER : 01 REPLAYGAIN_ALBUM_GAIN: -5.72 dB REPLAYGAIN_ALBUM_PEAK: 1.119748 REPLAYGAIN_TRACK_GAIN: -6.22 dB REPLAYGAIN_TRACK_PEAK: 0.950928 ENCODEDBY : Easy CD-DA Extractor (http://www.poikosoft.com) TOTALTRACKS : 11 TOTALDISCS : 2 ALBUMARTIST : Pearl Jam encoder : Lavf57.2.100 Stream #0:0, 0, 1/44100: Audio: flac, 44100 Hz, stereo (16 bit) Side data: replaygain: track gain - -6.220000, track peak - 0.000022, album gain - -5.720000, album peak - 0.000026, Stream mapping: Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help [NULL @ 00000000002ecc00] sample/frame number mismatch in adjacent frames Last message repeated 1678 times No more output streams to write to, finishing. size= 7284kB time=00:01:17.18 bitrate= 773.1kbits/s video:0kB audio:7275kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.123952% Input file #0 (D:\Mp3\Pearl Jam\Pearl Jam\1991 - Ten\01 - Pearl Jam - Once.flac): Input stream #0:0 (audio): 833 packets read (7461572 bytes); Total: 833 packets (7461572 bytes) demuxed Output file #0 (C:\1_1.flac): Output stream #0:0 (audio): 832 packets muxed (7449633 bytes); Total: 832 packets (7449633 bytes) muxed 0 frames successfully decoded, 0 decoding errors [AVIOContext @ 00000000002f5860] Statistics: 2 seeks, 834 writeouts [AVIOContext @ 00000000002ec740] Statistics: 7569408 bytes read, 0 seeks
Change History (7)
comment:1 by , 9 years ago
Keywords: | split removed |
---|---|
Priority: | important → normal |
Version: | unspecified → git-master |
comment:2 by , 9 years ago
ffmpeg.exe -i 1_1.flac -f null -
ffmpeg version N-75563-g235381e Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.9.3 (GCC) configuration: --disable-static --enable-shared --enable-gpl --enable-version --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --en ble-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray -- nable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --en ble-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-li vo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-l bwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs -- nable-libxvid --enable-lzma --enable-decklink --enable-zlib libavutil 55. 2.100 / 55. 2.100 libavcodec 57. 3.100 / 57. 3.100 libavformat 57. 2.100 / 57. 2.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 8.100 / 6. 8.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.100 / 2. 0.100 libpostproc 54. 0.100 / 54. 0.100 Input #0, flac, from '1_1.flac': Metadata: ALBUM : Ten ALBUMARTISTSORT : Pearl Jam ARTIST : Pearl Jam ARTISTSORT : Pearl Jam CATALOGNUMBER : 88697398492 comment : Track 1 DATE : 2009-03-23 disc : 1 GENRE : Grunge LABEL : Bertelsmann Music Group LANGUAGE : eng MEDIA : CD MUSICBRAINZ_ALBUMARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_ALBUMID: 06fc304e-d70a-4846-93e5-544d6aa618d6 MUSICBRAINZ_ARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_TRACKID: 94bed552-376f-492d-8e87-f470aa7fda0c MUSICIP_PUID : 15ee9b0f-beda-b60f-cb39-e59d719d9f67 ORIGINALDATE : 1991-08-27 RELEASECOUNTRY : GB RELEASESTATUS : official RELEASETYPE : album SCRIPT : Latn TITLE : Once track : 01 REPLAYGAIN_ALBUM_GAIN: -5.72 dB REPLAYGAIN_ALBUM_PEAK: 1.119748 REPLAYGAIN_TRACK_GAIN: -6.22 dB REPLAYGAIN_TRACK_PEAK: 0.950928 ENCODEDBY : Easy CD-DA Extractor (http://www.poikosoft.com) TOTALTRACKS : 11 TOTALDISCS : 2 album_artist : Pearl Jam ENCODER : Lavf57.2.100 Duration: 00:03:51.67, start: 0.000000, bitrate: 257 kb/s Stream #0:0: Audio: flac, 44100 Hz, stereo, s16 Side data: replaygain: track gain - -6.220000, track peak - 0.000022, album gain - - .720000, album peak - 0.000026, Output #0, null, to 'pipe:': Metadata: ALBUM : Ten ALBUMARTISTSORT : Pearl Jam ARTIST : Pearl Jam ARTISTSORT : Pearl Jam CATALOGNUMBER : 88697398492 comment : Track 1 DATE : 2009-03-23 disc : 1 GENRE : Grunge LABEL : Bertelsmann Music Group LANGUAGE : eng MEDIA : CD MUSICBRAINZ_ALBUMARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_ALBUMID: 06fc304e-d70a-4846-93e5-544d6aa618d6 MUSICBRAINZ_ARTISTID: 83b9cbe7-9857-49e2-ab8e-b57b01038103 MUSICBRAINZ_TRACKID: 94bed552-376f-492d-8e87-f470aa7fda0c MUSICIP_PUID : 15ee9b0f-beda-b60f-cb39-e59d719d9f67 ORIGINALDATE : 1991-08-27 RELEASECOUNTRY : GB RELEASESTATUS : official RELEASETYPE : album SCRIPT : Latn TITLE : Once track : 01 REPLAYGAIN_ALBUM_GAIN: -5.72 dB REPLAYGAIN_ALBUM_PEAK: 1.119748 REPLAYGAIN_TRACK_GAIN: -6.22 dB REPLAYGAIN_TRACK_PEAK: 0.950928 ENCODEDBY : Easy CD-DA Extractor (http://www.poikosoft.com) TOTALTRACKS : 11 TOTALDISCS : 2 album_artist : Pearl Jam encoder : Lavf57.2.100 Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s Metadata: encoder : Lavc57.3.100 pcm_s16le Stream mapping: Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native)) Press [q] to stop, [?] for help size=N/A time=00:01:17.27 bitrate=N/A video:0kB audio:13312kB subtitle:0kB other streams:0kB global headers:0kB muxin overhead: unknown
comment:3 by , 9 years ago
Reproduced by developer: | set |
---|---|
Status: | new → open |
Reproducible with ffmpeg -i fate-suite/filter/seq-3341-7_seq-3342-5-24bit.flac -t 1 -acodec copy out.flac
comment:5 by , 20 months ago
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"
`
comment:6 by , 16 months ago
Similar to OP, taking an input flac file -> segment filter w/reset_timestamps -> flac
, I have these findings.
Using head, I have observed that when an flac output is generated via the segment filter, the flacenc.c
ONLY receives the streaminfo
data for the FINAL segment output (the 3rd in my case) and thus the trailer update is never performed all other segment outputs (file 1 and 2 in this case).
Indeed avformat_open_input
on the non final segment flacs the AVFormatContext.duration
is an invalid value (-9223372036854775808) and the final segment having the same reported duration as the original input file.
An initial look at libavformat/segment.c
its not apparent where this bug would exist (if indeed its here) - seg_write_packet
does some determination of whether to create AV_PKT_DATA_NEW_EXTRADATA
but this is never called for any of the segments so it may suggest additional handling in segment_end
but I'd need some guidance on additional work here.
comment:7 by , 16 months ago
Cc: | added |
---|---|
Component: | undetermined → avfilter |
Please provide console output for
ffmpeg -i 1_1.flac -f null -