1

我需要使用ogg123将输入 ogg 文件转换为 wav 的程序。我的 ogg 在 S3 上 - 所以我需要先下载它,然后再转码。但我认为使用进程替换对声音进行转码会更快——无需写入磁盘源 ogg 文件。

从 bash 我想这样做:

ogg123 -d wav <(./test.py) -f out.wav

在 Python 中,对于二进制输出,我尝试过:

os.write

sys.stdout.buffer.write

fp = os.fdopen(sys.stdout.fileno(), 'wb'); fp.write

例如:

#!/usr/bin/env python3

import os

import boto3

s3_client = boto3.client('s3')

os.write(1, 
    s3_client.get_object(
        Bucket='my-bucket-name',
        Key='file.ogg'
    )['Body'].read()
)

./test.py在所有情况下打印视觉上有效的数据。例如:

xxd <(./test.py) | head打印:

00000000: 4f67 6753 0002 0000 0000 0000 0000 0000  OggS............
00000010: 0000 0000 0000 5664 269e 011e 0176 6f72  ......Vd&....vor
00000020: 6269 7300 0000 0001 2256 0000 0000 0000  bis....."V......
00000030: 058a 0000 0000 0000 a901 4f67 6753 0000  ..........OggS..
00000040: 0000 0000 0000 0000 0000 0000 0100 0000  ................
00000050: 5096 ab47 0e16 ffff ffff ffff ffff ffff  P..G............
00000060: ffff c503 766f 7262 6973 0600 0000 6666  ....vorbis....ff
00000070: 6d70 6567 0000 0000 0105 766f 7262 6973  mpeg......vorbis
00000080: 2242 4356 0100 4000 0018 4210 2a05 ad63  "BCV..@...B.*..c
00000090: 8e3a c815 218c 19a2 a042 ca29 c71d 42d0  .:..!....B.)..B.

但是所有这些变体都会从 ogg123 生成相同的错误:

Error opening /dev/fd/63 using the oggvorbis module. The file may be corrupted.

我在本地尝试了相同的文件 - 文件是正确的:

$ ogg123 -d wav file.ogg -f out.wav

Audio Device:   WAV file output

Playing: file.ogg
Ogg Vorbis stream: 1 channel, 22050 Hz

Done.

你能推荐什么?

4

1 回答 1

0

感谢您的帮助,我发现我可以使用纯 ogg123 通过 S3 获取:

ogg123 -d wav https://s3.amazonaws.com/mybucket/file.ogg -f out.wav
于 2017-10-17T12:55:30.183 回答