2017-10-17 108 views
1

我需要使用名为ogg123的程序来将输入的ogg文件转换为wav。我的ogg在S3上 - 所以我需要先下载它,然后转码。但我认为这将更快地转码声音 - 无需写入磁盘源文件ogg - 使用进程替代Python:如何将二进制数据写入标准输出以便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 "[email protected]*..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. 

您能推荐什么结束?

+1

你肯定'ogg123'可以从流中读取(即,非可查找输入源) ? – larsks

+0

我不确定... –

+0

你可以尝试[SoX](http://sox.sourceforge.net/)来查看它是否是ogg123中的问题。此外,'diff --binary <(./ test.py)file.ogg'来检查比特匹配。 – cxw

回答

0

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

ogg123 -d wav https://s3.amazonaws.com/mybucket/file.ogg -f out.wav 
相关问题