Skip to content

Commit 4724964

Browse files
committed
No more intermediate decompression and metaflac passes
flac supports reading in a FLAC file directly for source input, and writes out a new file with the desired compression file based on it. Use this to speed up operation and make it a little more reliable, copying all metadata and ancillary streams (such as artwork) without worry about leaving them out. Additionally, the `--verify` flag is now used too, giving extra assurance that the output FLAC file is correct. I have strong doubts this is actually necessary; I think decoding errors will be caught and should cover enough, but this has been requested twice now and the performance impact is offset by the overall improvement in this commit. Thanks @Entze and @wlhlm for the suggestions Closes: #5, #6
1 parent aead6a8 commit 4724964

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

reflac

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,18 @@ recompress()
6565
fi
6666

6767
if [ $NOACTION -eq 0 ]; then
68-
HAS_COVER_ART=1
69-
metaflac --no-utf8-convert \
70-
--export-tags-to="$TMPDIR/$(basename -s flac -- "$flac")tag" \
71-
-- "$flac"
72-
metaflac --export-picture-to="$TMPDIR/$(basename -s flac -- "$flac")img" \
73-
-- "$flac" > /dev/null 2>&1 || HAS_COVER_ART=0 #the error is handled later. do not exit the script
7468
if [ $VERBOSE -gt 1 ]; then
75-
flac --force-rf64-format --output-prefix="$TMPDIR/" -d -- "$flac"
76-
flac --delete-input-file -$FLAC_LEVEL -- \
77-
"$TMPDIR/$(basename -s flac -- "$flac")rf64"
69+
flac -$FLAC_LEVEL \
70+
--output-name="${TMPDIR}/$(basename -- "$flac")" \
71+
--verify -- \
72+
"$flac"
7873
else
79-
flac -s --force-rf64-format --output-prefix="$TMPDIR/" -d -- "$flac"
80-
flac -s --delete-input-file -$FLAC_LEVEL -- \
81-
"$TMPDIR/$(basename -s flac -- "$flac")rf64"
74+
flac --silent -$FLAC_LEVEL \
75+
--output-name="${TMPDIR}/$(basename -- "$flac")" \
76+
--verify -- \
77+
"$flac"
8278
fi
8379

84-
if [ $HAS_COVER_ART -eq 1 ]; then
85-
metaflac --no-utf8-convert $PRESERVE_MODTIME \
86-
--import-tags-from="$TMPDIR/$(basename -s flac -- "$flac")tag" \
87-
--import-picture-from="$TMPDIR/$(basename -s flac -- "$flac")img" \
88-
-- "$TMPDIR/$flac"
89-
else
90-
metaflac --no-utf8-convert $PRESERVE_MODTIME \
91-
--import-tags-from="$TMPDIR/$(basename -s flac -- "$flac")tag" \
92-
-- "$TMPDIR/$flac"
93-
fi
9480
mv -f -- "$TMPDIR/$flac" "$flac.new"
9581
if [ $SYNC -eq 1 ]; then
9682
sync "$flac.new"
@@ -99,8 +85,6 @@ recompress()
9985
else
10086
mv -f "$flac.new" "$flac"
10187
fi
102-
rm -f -- "$TMPDIR/$(basename -s flac -- "$flac")tag" \
103-
"$TMPDIR/$(basename -s flac -- "$flac")img"
10488
fi
10589
done
10690
}

0 commit comments

Comments
 (0)