Klemper Posted December 13 Posted December 13 Basically, what is in the title. A simple tool to merge files. Thanks very much. Free or paid, doesn't matter. Regards.
D.Draker Posted December 14 Posted December 14 Tough question. To spare you some time, I just tried the glorified, over-popularised Audacity 3.0.5 64bit, and it does re-encode, so not suitable at all. On a side note, I never found over-popularised software to be attractive,
D.Draker Posted December 14 Posted December 14 There's also the over-popularised *free* FFMPEG, but the quality of the output file sucks, even though it doesn't *theoretically* re-encode. Also, it broke all the timings! Here's the CMD string. ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.flac
D.Draker Posted December 14 Posted December 14 From their official site: https://trac.ffmpeg.org/wiki/Concatenate Instructions Create a file mylist.txt with all the files you want to have concatenated in the following form (lines starting with a # are ignored): # this is a comment file '/path/to/file1.wav' file '/path/to/file2.wav' file '/path/to/file3.wav' Note that these can be either relative or absolute paths. Then you can stream copy or re-encode your files: ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav The -safe 0 above is not required if the paths are relative. Automatically generating the input file It is possible to generate this list file with a bash for loop, or using printf. Either of the following would generate a list file containing every *.wav in the working directory: # with a bash for loop for f in *.wav; do echo "file '$f'" >> mylist.txt; done # or with printf printf "file '%s'\n" *.wav > mylist.txt On Windows Command-line: (for %i in (*.wav) do @echo file '%i') > mylist.txt Or for Windows Powershell: foreach ($i in Get-ChildItem .\*.wav) {"file '$i'" | Out-File mylist.txt -Encoding utf8 -Append} Or for Windows bat-file: (for %%i in (*.wav) do @echo file '%%i') > mylist.txt If your shell supports process substitution (like Bash and Zsh), you can avoid explicitly creating a list file and do the whole thing in a single line. This would be impossible with the concat protocol (see below). Make sure to generate absolute paths here, since ffmpeg will resolve paths relative to the list file your shell may create in a directory such as "/proc/self/fd/". Further, this process will fail if file names contain a single quote (e.g. 's) and an actual file must be generated. (From docs: https://ffmpeg.org/ffmpeg-formats.html#concat-1 3.5.1 Syntax: special characters and spaces must be escaped with backslash or single quotes) From docs: https://ffmpeg.org/ffmpeg-formats.html#concat-1 3.5.1 Syntax The script is a text file in extended-ASCII, with one directive per line. Empty lines, leading spaces and lines starting with ’#’ are ignored. The following directive is recognized: file path Path to a file to read; special characters and spaces must be escaped with backslash or single quotes. All subsequent file-related directives apply to that file. ffmpeg -f concat -safe 0 -i <(for f in ./*.wav; do echo "file '$PWD/$f'"; done) -c copy output.wav ffmpeg -f concat -safe 0 -i <(printf "file '$PWD/%s'\n" ./*.wav) -c copy output.wav ffmpeg -f concat -safe 0 -i <(find . -name '*.wav' -printf "file '$PWD/%p'\n") -c copy output.wav You can also loop a video. This example will loop input.mkv 10 times: for i in {1..10}; do printf "file '%s'\n" input.mkv >> mylist.txt; done ffmpeg -f concat -i mylist.txt -c copy output.mkv Changing playlist files on the fly The concat demuxer opens the referenced files only when they are needed. This allows us to swap the referenced files atomically behind the demuxers back to be able to use the concat demuxer as a changeable live source. Check out the following example file list.txt: ffconcat version 1.0 file dummy.mxf file dummy.mxf dummy.mxf is referenced twice to make sure the concat demuxer reopens the file when it reaches it. Combine this with infinite looping and you are done: ffmpeg -re -stream_loop -1 -f concat -i list.txt -flush_packets 0 -f mpegts udp://127.0.0.1:5000?pkt_size=1316 Now you can change the looping clip by a simple move command: mv next_clip.mxf dummy.mxf Automatically appending to the list file Concatenation does not work if the next clip for does not exist at the moment, because decoding won't start until the whole list is read. However, it is possible to refer to another list at the end of the current list. The following script provides an example for this mechanism: #!/bin/bash fn_concat_init() { echo "fn_concat_init" concat_pls=`mktemp -u -p . concat.XXXXXXXXXX.txt` concat_pls="${concat_pls#./}" echo "concat_pls=${concat_pls:?}" mkfifo "${concat_pls:?}" echo } fn_concat_feed() { echo "fn_concat_feed ${1:?}" { >&2 echo "removing ${concat_pls:?}" rm "${concat_pls:?}" concat_pls= >&2 fn_concat_init echo 'ffconcat version 1.0' echo "file '${1:?}'" echo "file '${concat_pls:?}'" } >"${concat_pls:?}" echo } fn_concat_end() { echo "fn_concat_end" { >&2 echo "removing ${concat_pls:?}" rm "${concat_pls:?}" # not writing header. } >"${concat_pls:?}" echo } fn_concat_init echo "launching ffmpeg ... all.mkv" timeout 60s ffmpeg -y -re -loglevel warning -i "${concat_pls:?}" -pix_fmt yuv422p all.mkv & ffplaypid=$! echo "generating some test data..." i=0; for c in red yellow green blue; do ffmpeg -loglevel warning -y -f lavfi -i testsrc=s=720x576:r=12:d=4 -pix_fmt yuv422p -vf "drawbox=w=50:h=w:t=w:c=${c:?}" test$i.mkv fn_concat_feed test$i.mkv ((i++)); echo done echo "done" fn_concat_end wait "${ffplaypid:?}" echo "done encoding all.mkv" Note that recursively referencing playlist files will cause ffmpeg to eventually run out of file descriptors (or other resources) because ffmpeg only closes the playlist file when the playlist has finished, but in the example above because of the recursive chaining none of the playlist files actually end. Concat protocol While the demuxer works at the stream level, the concat protocol works at the file level. Certain files (MPEG-2 transport streams, possibly others) can be concatenated. This is analogous to using cat on UNIX-like systems or copy on Windows. Instructions The following command concatenates three MPEG-2 TS files and concatenates them without re-encoding: ffmpeg -i "concat:input1.ts|input2.ts|input3.ts" -c copy output.ts Using intermediate files If you have MP4 files, these could be losslessly concatenated by first transcoding them to MPEG-2 transport streams. With H.264 video and AAC audio, the following can be used: ffmpeg -i input1.mp4 -c copy intermediate1.ts ffmpeg -i input2.mp4 -c copy intermediate2.ts ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy output.mp4 Using named pipes to avoid intermediate files If you're using a system that supports named pipes, you can use those to avoid creating intermediate files. This sends stderr (to which ffmpeg sends all the written data) to /dev/null, to avoid cluttering up the command-line: mkfifo temp1 temp2 ffmpeg -y -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1 2> /dev/null & \ ffmpeg -y -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2 2> /dev/null & \ ffmpeg -f mpegts -i "concat:temp1|temp2" -c copy -bsf:a aac_adtstoasc output.mp4 The additional -y switch is needed to force ffmpeg to write to existing files temp1 and temp2, which are the named pipes. Without the switch, the first two ffmpeg programs running in the background will not produce any output because they wait for interactive yes/no answers to the questions whether to overwrite existing files. All MPEG codecs (MPEG-4 Part 10 / AVC, MPEG-4 Part 2, MPEG-2 Video, MPEG-1 Audio Layer II, MPEG-2 Audio Layer III (MP3), MPEG-4 Part III (AAC)) are supported in the MPEG-TS container format, although the commands above would require some alteration (e.g., the -bsf bitstream filters will have to be changed). Concatenation of files with different codecs In many cases, input files will have different codecs or different codec properties, which makes it impossible to use any of the above methods. Concat filter See the concat filter documentation for more info. The filter works on segments of synchronized video and audio streams. All segments must have the same number of streams of each type, and that will also be the number of streams at output. Note: Filters are incompatible with stream copying; you can't use -c copy with this method. Since you have to re-encode the video and audio stream(s), and since re-encoding may introduce compression artifacts, make sure to add proper target bitrate or quality settings. See the encoding guides for more info. tags concat For the concat filter to work, the inputs have to be of the same frame dimensions (e.g., 1920⨉1080 pixels) and should have the same framerate. Therefore, you may at least have to add a scale or scale2ref filter before concatenating videos. A handful of other attributes have to match as well, like the stream aspect ratio. Refer to the documentation of the filter for more info. Instructions Let's say we have three files that we want to concatenate – each of them with one video and audio stream. The concat filter command would look like this: ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \ -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \ -map "[outv]" -map "[outa]" output.mkv Now, let's dissect that command. We first specify all the input files, then instantiate a -filter_complex filtergraph – this is needed instead of -filter:v because it has multiple inputs and outputs. The following line: [0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0] tells ffmpeg which streams to take from the input files and send as input to the concat filter. In this case, video stream 0 [0:v:0] and audio stream 0 [0:a:0] from input 0 (input1.mp4 in this example), and video stream 0 [1:v:0] and audio stream 0 [1:v:0] from input 1 (input2.webm), etc. concat=n=3:v=1:a=1[outv][outa]' This is the concat filter itself. n=3 is telling the filter that there are three input segments; v=1 is telling it that there will be one video stream per segment; a=1 is telling it that there will be one audio stream per segment. The filter then concatenates these segments and produces two output streams. [outv] and [outa] are names for these output streams. Note that the quotes around the filter section are required. The following image shows the stream mapping to and from the filter in the above example: You can then either re-use these streams in other filters, or map them to the output file: -map "[outv]" -map "[outa]" output.mkv This tells ffmpeg to use the results of the concat filter rather than the streams directly from the input files. Using an external script There is a Bash script called mmcat which was useful for older versions of ffmpeg that did not include the concat filter.
D.Draker Posted December 14 Posted December 14 Anyways, I didn't like the output quality, it sounded "metallic", and I have a very good Hi-End audio devices. Whatever you try, keep the originals! Good luck in your searches! Probably @NotHereToPlayGames also joins the discussion since I read he's a huge music fan. 1
j7n Posted December 14 Posted December 14 There is not much reason not to re-encode a FLAC. One of the main benefits from lossless is to give you freedom to edit. Just use any visual editor you are comfortable with, or use Foobar2000 to produce a single file output. If you have an old PC, there is a CUDA (FLACCL) encoder for 16-bit that is very fast. MkvToolNix throws a big warnings on appending multiple files that are in the same format. You can then extract it, but it is a hassle. Some strict or simple players might not like the transition point or not play it gapless. With lossy formats you would avoid transcoding to maintain the quality, and editing this way was very limited. This is not needed with lossless.
Klemper Posted December 14 Author Posted December 14 16 hours ago, D.Draker said: There's also the over-popularised *free* FFMPEG, but the quality of the output file sucks, even though it doesn't *theoretically* re-encode. Also, it broke all the timings! Here's the CMD string. ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.flac Thanks, will try,
Klemper Posted December 14 Author Posted December 14 12 hours ago, j7n said: There is not much reason not to re-encode a FLAC. One of the main benefits from lossless is to give you freedom to edit. Just use any visual editor you are comfortable with, or use Foobar2000 to produce a single file output. If you have an old PC, there is a CUDA (FLACCL) encoder for 16-bit that is very fast. MkvToolNix throws a big warnings on appending multiple files that are in the same format. You can then extract it, but it is a hassle. Some strict or simple players might not like the transition point or not play it gapless. With lossy formats you would avoid transcoding to maintain the quality, and editing this way was very limited. This is not needed with lossless. Respectfully, I'm looking only for merging WITHOUT re-encoding, FLAC is not lossless, it's only what they declare. WAV is lossless. Compare their size,
TSNH Posted December 14 Posted December 14 1 hour ago, Klemper said: FLAC is not lossless, it's only what they declare. Where did you find this info? Compressing audio in a lossless way should be theoretically possible and that's exactly what FLAC is supposed to accomplish. It would have no reason to exist otherwise. 1
j7n Posted December 14 Posted December 14 A lossless format can be opened and saved any number of times without degradation. The file is smaller because of compression, which exploits similarities between successive samples to extract a trend in them. The remaining error can then be saved with fewer bits. A lossy codec differs here that it would only use X number of bits and no more, while a lossless codec will use as many as needed. Note that some editors will apply dithering when saving an open file, including wav files. This is under assumption that that you actually made some edits. Some other software might reduce the bit depth. This is why you need to be familiar with the chosen software and its advanced options. Appending is complicated by the fact that the last block is shorter. In the simplest FLAC stream all blocks are the same length. This is why the splice might not be seamless. Medieval Cue Splitter attempted this and has polluted the internet with albums that are not gapless. For appending I would use Foobar2000 converter, selecting in the advanced options, bit depth: auto (default) and destination: Merge all tracks into one output file. 1
D.Draker Posted December 14 Posted December 14 11 hours ago, j7n said: There is not much reason not to re-encode a FLAC. One of the main benefits from lossless is to give you freedom to edit. I have a severely damaged right ear, left isn't much better either! I served in the artillery, and even I hear the difference between FLAC and WAV, all in favour of WAV!
D.Draker Posted December 14 Posted December 14 11 hours ago, j7n said: A lossless format can be opened and saved any number of times without degradation. I also here the quality loss when converting FLAC to FLAC with either Audacity or FFMPEG. You want to say you don't? What are your hardware specs?
D.Draker Posted December 14 Posted December 14 13 hours ago, Klemper said: FLAC is not lossless, it's only what they declare. WAV is lossless. Compare their size, Well, I don't know much about FLAC, I store my own Vinyl Rips only in wav. FLAC sounds more "flat", lacks depth. I own many vinyls. 1
j7n Posted December 15 Posted December 15 You can use the bit-compare tool in Foobar to check if the files are identical and the magnitude of the difference. I don't trust ffmpeg. It attempts to do so many things and not any of them really well. It also goes through rapid updating and growth in size. One version might work right and another might not. If you feed it 24 bits make sure you get that out. FFMPEG compressor is really special because it can compress samples with high redundancy like classical music or dull drone to levels similar to TAK, so it has a reason for existing.
Klemper Posted December 15 Author Posted December 15 On 12/14/2024 at 10:59 PM, TSNH said: Compressing audio in a lossless way should be theoretically possible and that's exactly what FLAC is supposed to accomplish. It would have no reason to exist otherwise. Then why FLAC is about 25 percent smaller than WAV? And MP3 is even smaller?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now