Skip to content
The Chat Archive
o1-preview-2024-09-12· OpenAI WildChat-4.8M (AI2)

I found this script online. It's from four years ago and uses FFmpeg 4.3.1. I'm using…

  1. 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.mkv" −map0:a:m:language:eng?−afaresample=resampler=soxr,asetrate=46033.92−ar48000−samplefmts16−mapchapters−1−mapmetadata−1"1.mkv" \ -map 0:a:m:language:eng? -af aresample=resampler=soxr,asetrate=46033.92 -ar 48000 -sample_fmt s16 -map_chapters -1 -map_metadata -1 "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.dan.flac" −map0:a:m:language:fin?−afaresample=resampler=soxr,asetrate=46033.92−ar48000−samplefmts16−mapchapters−1−mapmetadata−1"1.dan.flac" \ -map 0:a:m:language:fin? -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.nor.flac" −map0:a:m:language:swe?−afaresample=resampler=soxr,asetrate=46033.92−ar48000−samplefmts16−mapchapters−1−mapmetadata−1"1.nor.flac" \ -map 0:a:m:language:swe? -af aresample=resampler=soxr,asetrate=46033.92 -ar 48000 -sample_fmt s16 -map_chapters -1 -map_metadata -1 "1.swe.flac"

    mkvmerge -o "1.resampled.mkv"−−no−chapters−−no−audio−−default−duration0:23976/1000fps"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:FLACDanish"−−language0:dan"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:FLACNorwegian"−−language0:nor"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"

  2. 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:

    1. Order of Audio Filters: The script applies the audio filters in the order aresample followed by asetrate. 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 using asetrate and then resample it back to the original sample rate using aresample. Therefore, you should reverse the order of the filters in your script.

    2. Filter Syntax Updates: In newer versions of FFmpeg, it's recommended to specify the target sample rate directly within the aresample filter rather than using the -ar option separately. Also, enclosing the filter chain in quotes ensures that the entire chain is interpreted correctly.

    3. Fractional Sample Rates: Using a fractional sample rate like 46033.92 is acceptable, but make sure that your FFmpeg build supports this precision. Some builds might round the value, which could affect the output.

    4. Verification of Options: Ensure that all the options like -map, -map_chapters -1, and -map_metadata -1 are 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 specifying 48000 directly in aresample, we ensure the resampling happens correctly, and we eliminate the need for the separate -ar 48000 option.

    • 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.