I found this script online. It's from four years ago and uses FFmpeg 4.3.1. I'm using…
- User
I found this script online. It's from four years ago and uses FFmpeg 4.3.1. I'm using FFmpeg 7.0.2. Will this script run correctly on the newest version of FFmpeg or do I need to update some of it?
ffmpeg -hide_banner -y -i "1.eng.flac"
-map 0:a:m:language:dan? -af aresample=resampler=soxr,asetrate=46033.92 -ar 48000 -sample_fmt s16 -map_chapters -1 -map_metadata -1 "1.fin.flac"
-map 0:a:m:language:nor? -af aresample=resampler=soxr,asetrate=46033.92 -ar 48000 -sample_fmt s16 -map_chapters -1 -map_metadata -1 "1.swe.flac"mkvmerge -o "1.mkv"
--track-name "0:FLAC English" --language 0:eng "1.dan.flac"
--track-name "0:FLAC Finnish" --language 0:fin "1.nor.flac"
--track-name "0:FLAC Swedish" --language 0:swe "$1.swe.flac" - Assistant
It appears that the script you found uses FFmpeg options and filters that are still available in FFmpeg 7.0.2. However, there are a few important considerations and potential updates to ensure the script runs correctly with the newer version:
-
Order of Audio Filters: The script applies the audio filters in the order
aresamplefollowed byasetrate. This order may not achieve the desired effect. Typically, when changing the playback speed or duration of audio without altering the pitch, you should first adjust the sample rate usingasetrateand then resample it back to the original sample rate usingaresample. Therefore, you should reverse the order of the filters in your script. -
Filter Syntax Updates: In newer versions of FFmpeg, it's recommended to specify the target sample rate directly within the
aresamplefilter rather than using the-aroption separately. Also, enclosing the filter chain in quotes ensures that the entire chain is interpreted correctly. -
Fractional Sample Rates: Using a fractional sample rate like
46033.92is acceptable, but make sure that your FFmpeg build supports this precision. Some builds might round the value, which could affect the output. -
Verification of Options: Ensure that all the options like
-map,-map_chapters -1, and-map_metadata -1are still valid in FFmpeg 7.0.2. These options have not changed significantly in recent versions, so they should work as expected.
Updated Script:
Here's the updated script with the filters in the correct order and syntax adjustments:
ffmpeg -hide_banner -y -i "$1.mkv" \ -map 0:a:m:language:eng? -af "asetrate=46033.92, aresample=48000:resampler=soxr" -sample_fmt s16 -map_chapters -1 -map_metadata -1 "$1.eng.flac" \ -map 0:a:m:language:dan? -af "asetrate=46033.92, aresample=48000:resampler=soxr" -sample_fmt s16 -map_chapters -1 -map_metadata -1 "$1.dan.flac" \ -map 0:a:m:language:fin? -af "asetrate=46033.92, aresample=48000:resampler=soxr" -sample_fmt s16 -map_chapters -1 -map_metadata -1 "$1.fin.flac" \ -map 0:a:m:language:nor? -af "asetrate=46033.92, aresample=48000:resampler=soxr" -sample_fmt s16 -map_chapters -1 -map_metadata -1 "$1.nor.flac" \ -map 0:a:m:language:swe? -af "asetrate=46033.92, aresample=48000:resampler=soxr" -sample_fmt s16 -map_chapters -1 -map_metadata -1 "$1.swe.flac" mkvmerge -o "$1.resampled.mkv" --no-chapters --no-audio --default-duration 0:23976/1000fps "$1.mkv" \ --track-name "0:FLAC English" --language 0:eng "$1.eng.flac" \ --track-name "0:FLAC Danish" --language 0:dan "$1.dan.flac" \ --track-name "0:FLAC Finnish" --language 0:fin "$1.fin.flac" \ --track-name "0:FLAC Norwegian" --language 0:nor "$1.nor.flac" \ --track-name "0:FLAC Swedish" --language 0:swe "$1.swe.flac"Explanation of Updates:
-
Filter Chain Order: The filters are now in the order
"asetrate=46033.92, aresample=48000:resampler=soxr". This means:asetrate=46033.92: Adjusts the sample rate to 46033.92 Hz without altering the data, effectively changing the playback speed.aresample=48000:resampler=soxr: Resamples the audio back to 48000 Hz using the SoX Resampler library, which provides high-quality resampling.
-
Inclusion of Sample Rate in
aresample: By specifying48000directly inaresample, we ensure the resampling happens correctly, and we eliminate the need for the separate-ar 48000option. -
Quoting the Filter Chain: Enclosing the filter chain in quotes prevents shell interpretation issues and ensures FFmpeg parses the entire string as a single filter chain.
Recommendation:
Before running the script on important files, test it on a small sample to ensure it behaves as expected. Pay attention to the audio quality and synchronization after processing. If you encounter any issues, refer to the FFmpeg documentation for version 7.0.2 to check for any additional changes or deprecations that might affect your specific use case.
-