Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Usage: Paste code into a .sh file, or simply substitute the input and output file names into $1 and $2 if you prefer to
- # run it directly.
- # The scripts require FFmpeg and Python 3 to be installed. The preview script requires FFplay as well (comes with FFmpeg)
- #--------------------------------------#
- # To convert into 1-bit MSB-first PCM:
- #!/bin/sh
- ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf "import sys\nfrom struct import pack\nbuffer = sys.stdin.buffer.read(8)\nwhile len(buffer) == 8:\n packed = 0\n for b in buffer:\n packed = (packed << 1) | ((b - 3) >> 7)\n sys.stdout.buffer.write(pack('B', packed))\n buffer = sys.stdin.buffer.read(8)")" > $2
- #--------------------------------------#
- # To convert into 1-bit LSB-first PCM:
- #!/bin/sh
- ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf "import sys\nfrom struct import pack\nbuffer = sys.stdin.buffer.read(8)\nwhile len(buffer) == 8:\n packed = 0\n for b in buffer:\n packed = (packed >> 1) | ((b - 3) & 128)\n sys.stdout.buffer.write(pack('B', packed))\n buffer = sys.stdin.buffer.read(8)")" > $2
- #--------------------------------------#
- # If you want to preview the audio:
- #!/bin/sh
- ffmpeg -i $1 -af highpass=80 -ar 24000 -ac 1 -f u8 - | python3 -c "$(printf 'import sys\nsys.stdout.buffer.write(bytes(map(lambda x: ((x - 3) & 128) >> 2, sys.stdin.buffer.read())))')" | ffplay -f u8 -ac 1 -ar 24000 -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement