rusty_vorbis, libvorbis का Pure Rust विकल्प है
libvorbis और libogg के glue की जगह rusty_vorbis लाएँ: परिचित -q scale पर encoder, FFmpeg 8.1 से मेल खाता packet decoder, और build में कहीं भी C नहीं।

क्या rusty_vorbis encoding और decoding दोनों के लिए libvorbis की जगह ले सकता है?
हाँ। rusty_vorbis में Vorbis -q quality scale से चलने वाला VorbisEncoder और packet-level Decoder है जो FFmpeg 8.1 से 3e-8 के भीतर मेल खाता है। इसकी zero dependencies हैं और इसमें C नहीं है। Ogg container layer आप ही देते हैं, जैसे libogg के साथ देते थे।
Ship it
1.5–1.6× Faster Than SymphoniaThe decoder is 1.5–1.6× faster than symphonia 0.5.5 and 2.5–3.1× faster than lewton 0.10.2, and it matches FFmpeg.
rusty_vorbis एक Ogg Vorbis encoder और decoder है जो Rust में zero dependencies के साथ लिखा गया है और remade_ffmpeg_rs monorepo में शिप होता है। अगर आपका product podcasts, game assets या voice notes encode करने के लिए libvorbis लिंक करता है, और उन्हें चलाने के लिए lewton या symphonia लिंक करता है, तो यह crate एक ही API में दोनों दिशाएँ कवर करता है। यह पेज migration guide है: कौन-सी libvorbis calls किन rusty_vorbis calls से मैप होती हैं, आपकी pipeline में क्या बदलता है, और switch करने से पहले कौन-से gaps जानने चाहिए।
decoder की timing table और release history के लिए rusty_vorbis 0.1.2 पढ़ें। इसे लपेटने वाले engine के लिए remade_ffmpeg_rs फ़ील्ड नोट और repo landing देखें।
आप किसकी जगह ले रहे हैं
libvorbis और उसके साथी
libvorbis Xiph.Org reference codec है, C में लिखा गया। एक सामान्य encoder integration vorbis_info_init, vorbis_encode_init_vbr, vorbis_analysis_headerout कॉल करता है, फिर vorbis_analysis_buffer, vorbis_analysis_wrote, vorbis_analysis_blockout और vorbis_bitrate_flushpacket पर loop करता है, और libogg packets को pages में लपेटता है। Decoding में vorbis_synthesis_headerin तीन बार, फिर vorbis_synthesis, vorbis_synthesis_blockin और vorbis_synthesis_pcmout से गुज़रते हैं। यानी हर target के लिए दो native libraries build करनी पड़ती हैं, और boards तथा wasm builds पर C toolchain भी, जो उसे host नहीं करना चाहते।
जहाँ C code ने नुकसान किया है
Vorbis files उपयोगकर्ताओं से, mods से और scraped archives से आती हैं, इसलिए decoder untrusted input के लिए parser है। CVE-2018-5146 Vorbis audio data process करते समय out-of-bounds memory write था, जो Pwn2Own के ज़रिए report हुआ और Firefox 59.0.1, Firefox ESR 52.7.2 और Thunderbird 52.7 में fix हुआ। उसी C code के ऊपर Rust binding उसी तरह के bug को बिना बदलाव विरासत में लेती है। Codec को बदलना ही इसे path से हटाने का एकमात्र तरीका है।
rusty_vorbis इसके बदले क्या देता है
README इसे लेखकों की जानकारी के अनुसार पहला permissively licensed Vorbis encoder बताता है जो pure Rust में लिखा गया है: बाकी हर Rust encoder libvorbis को bind करता है। Encoder forward MDCT, असली psychoacoustic model से Bark-scale masking-threshold floor, point stereo के साथ channel coupling, और rate-distortion residue VQ चलाता है, फिर libvorbis-compatible setup header लिखता है। इसका output ffmpeg और lewton में decode होता है। Decoder पूरा Vorbis I कवर करता है: floor 0 और 1, residue 0, 1 और 2, VQ lookup types 1 और 2, submaps, block switching और 255 channels तक। Vorbis खुद patent-free और royalty-free है, और crate Apache-2.0 है।
libvorbis से rusty_vorbis पर switch करना
Step 1: encoder loop बदलें
VorbisEncoderConfig से एक VorbisEncoder बनाएँ। quality field 0..1 value लेता है; quality01_from_vorbis_q(4.0) परिचित -q scale से convert करता है, जो -1 से 10 तक चलता है, इसलिए oggenc या vorbis_encode_init_vbr के लिए tune किए presets वैसे ही काम करते हैं। push_pcm_f32 से interleaved samples दें (या 16-bit input के लिए push_pcm_s16), channel count और sample rate पास करते हुए। Input खत्म होने पर finish() कॉल करें; बाकी blocks फिर cores पर parallel encode होते हैं।
next_packet() से packets निकालें। Drain protocol FFmpeg का पालन करता है: Error::Again का मतलब है और input दें, Error::Eof का मतलब flushed stream खाली है। पहले तीन packets identification, comment और setup headers हैं, जो vorbis_analysis_headerout की जगह लेते हैं। उसके बाद सब granule positions वाले audio हैं, जो उसी क्रम में आपके Ogg muxer के लिए तैयार हैं।
Step 2: decoder बदलें
तीन header packets से decode::Decoder::new(ident, comment, setup) बनाएँ। max_frames_per_packet() * channels() floats का एक buffer allocate करें, फिर हर audio packet पर decode_interleaved(packet, &mut buf) कॉल करें। यह frame count लौटाता है और प्रति packet allocate नहीं करता। decode और channel के ज़रिए planar path भी उपलब्ध है।
दो behaviours libvorbis की आदतों के बजाय lewton और FFmpeg से मेल खाते हैं। पहला audio packet शून्य frames देता है। जब आप tail को final granule तक trim करते हैं, packet_blocksize से गिनें, क्योंकि long block के बाद short block आने पर यह अपनी tail एक packet पहले लौटा देता है।
Step 3: channel order ठीक करें और अपने corpus पर test करें
Output Vorbis order में आता है, इसलिए 5.1 FL C FR RL RR LFE है। अगर आपका mixer WAV या FFmpeg order चाहता है, तो adapter में क्रम बदलें। remade_ffmpeg_rs adapter पहले से rusty_vorbis के ज़रिए decode करता है और end trim लागू करके FFmpeg channel order में float देता है, इसलिए engine से route करने पर वह step बच जाता है।
Ship करने से पहले अपनी library के एक slice को दोनों stacks से decode करें और floats का diff लें। Crate का अपना gate q0 से q10 तक, एक से आठ channels और 8 से 96 kHz तक की libvorbis streams पर FFmpeg 8.1 से तुलना करता है, और identical frame counts तथा अधिकतम 3e-8 अंतर की मांग करता है।
आपको क्या मिलता है, और क्या आपकी सूची में रहता है
उद्धृत करने योग्य मापी गई संख्याएँ
60-second files पर, एक pinned core पर, decoder symphonia 0.5.5 से 1.52x से 1.63x तेज़ और lewton 0.10.2 से 2.48x से 3.11x तेज़ चलता है, हर round में paired wins के साथ। Encoder single thread पर libvorbis से लगभग 1.4x धीमा है। लगभग 5.3x wall-clock बढ़त सिर्फ 24-core machine पर frame-parallel encoding के साथ दिखती है, क्योंकि libvorbis एक core पर एक stream संभालता है। Speed के लिए इस्तेमाल की गई residue-class shortlist को PEAQ से जाँचा गया और उसने ODG को 0.03 या उससे कम बदला।
मुफ्त में मिलने वाली मज़बूती
खराब packets Err लौटाते हैं और decoder state को छूते नहीं। Codebook, VQ और Huffman table allocations capped हैं, इसलिए crafted setup header unbounded memory नहीं माँग सकता। 300 generated setups पर lewton के साथ decoder build करने से lewton के तीन defects भी सामने आए, जिनमें block sizes 64 और 128 पर गलत fast IMDCT शामिल है; rusty_vorbis हर मामले में spec का पालन करता है।
libogg हटाने से पहले gaps
- यह crate packet level है। यह Ogg pages नहीं पढ़ता या लिखता, इसलिए container layer रखें या engine इस्तेमाल करें।
- Single-threaded encoding libvorbis से धीमी है। एक साथ कई short clips encode करने वाले server को कोई बढ़त न मिले।
- Long ArtCraft editor export decode note में अभी भी open measurement है, इसलिए यह दावा न करें कि apps switch हो चुके हैं।
आस-पास के audio काम के लिए rusty_flac, rusty_opus और Media बैंड देखें। Toolkit view FFmpeg विकल्प पेज है। Release 0.1.2 rusty_vorbis-v0.1.2 के रूप में tagged है, और जो network इन crates को आपके अपने devices पर रखता है वह mata.network है।
FAQ
rusty_vorbis कहाँ मिलता है?
remade_ffmpeg_rs monorepo में crates/rusty_vorbis पर, Apache-2.0 के अंतर्गत। 0.1.2 पहला release है जिसमें decoder है; 0.1.1 सिर्फ encode करता था।
क्या rusty_vorbis Ogg files सीधे पढ़ता या लिखता है?
नहीं। यह Vorbis packets पर काम करता है। encoder तीन header packets और फिर granule positions वाले audio packets निकालता है, और decoder तीन headers plus audio packets को stream order में लेता है। इसके चारों ओर एक Ogg muxer या demuxer रहता है।
क्या encoder libvorbis से तेज़ है?
एक thread पर यह libvorbis से लगभग 1.4x पीछे है। लगभग 5.3x wall-clock बढ़त 24-core machine पर frame-parallel encoding से मिलती है, क्योंकि libvorbis एक core पर एक stream encode करता है। दोनों संख्याएँ साथ में उद्धृत करें।
मेरे 5.1 channels गलत क्रम में क्यों आते हैं?
decoder Vorbis channel order देता है, इसलिए 5.1 FL C FR RL RR LFE के रूप में आता है। WAV और FFmpeg अलग क्रम चाहते हैं। अपने adapter में क्रम बदलें; remade_ffmpeg_rs adapter पहले ही ऐसा करता है।
जब कोई Vorbis file hostile हो तो क्या होता है?
खराब packets error लौटाते हैं और decoder state जैसा था वैसा ही छोड़ देते हैं। Codebook, VQ और Huffman table allocations पर cap है, इसलिए crafted setup header unbounded memory नहीं माँग सकता। decoder को debug profile में fuzz किया जाता है।