PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

How do I decode g729

Open user3472g opened this issue 3 years ago • 1 comments

IMPORTANT: Be sure to replace all template sections {{ like this }} or your issue may be discarded.

Overview

I am attempting to write a simple g729 decoder using PyAV. However, the audio being outputted is of extremely poor audio quality and does not match that of CLI ffmpeg.

Expected behavior

Output an audible audio file from g729 input.

Actual behavior

audio being outputted is of extremely poor audio quality and does not match that of CLI ffmpeg. I am unable to attach a sample g729 file here to this ticket. The request here is to review the provided sample code for sensibleness.

Traceback:

No exceptions.

Investigation

Sample code:

    with open(path_to_g729_encoded_file, "rb") as f:  
      buf = f.read()  
      codec = av.CodecContext.create("g729", 'r')  
      codec.channels = 1  
      codec.bit_rate = 8000  
      codec.sample_rate = 8000  
      g729Packets = codec.parse(buf)  
      fout = open("audio.s16p", "wb")  
      for g729 in g729Packets: 
         for frame in codec.decode(g729):  
            for plane in frame.planes:  
              fout.write(bytes(plane))  
      fout.close()

Research

I have done the following:

user3472g avatar Jun 12 '22 16:06 user3472g

Your decoded frames probably have padding

jlaine avatar Jun 16 '22 15:06 jlaine

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 15 '22 03:10 github-actions[bot]