相关文章推荐
眉毛粗的滑板  ·  图像处理 - 知乎·  1 年前    · 
耍酷的硬盘  ·  Quickstart: Create ...·  1 年前    · 
纯真的核桃  ·  sqlserver ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have pcap file that contains RTP data which in turn is audio for G.729 codec. Is there a way to decode this stream by pushing it into FFMPEG? This would probably mean I have to extract the RTP payload data from the PCAP file and then somehow pass it to FFMPEG.

Any guidelines and pointers are highly appreciated!

this doesn't require ffmpeg, but I assume you dont really care how the audio is extracted... check out How to Decode G729 on the wireshark wiki...

  • In Wireshark, use menu "Statistics -> RTP -> Show All Streams". Select the desired stream and press "Analyze".

  • In the next dialog screen, press "Save Payload...". Save options are Format = .raw and Channel = forward. Name file sample.raw.

  • Convert the .raw file to .pcm format using the Open G.729 decoder. Syntax: va_g729_decoder.exe sample.raw sample.pcm. Or for Linux: wine va_g729_decoder.exe sample.raw sample.pcm.

  • The .pcm file contains 16-bit linear PCM samples at 8000 Hz. Note that each sample is in Little-Endian format. To convert to .au format, all you need to do is prepend the 24 byte au header, and convert each PCM sample to network byte order (or Big-Endian). The following Perl Script will do the trick.

  • USAGE: perl pcm2au.pl inputFile outputFile

    $usage = "Usage: 'perl $0 <Source PCM File> <Destination AU File>' ";
    $srcFile = shift or die $usage;
    $dstFile = shift or die $usage;
    open(SRCFILE, "$srcFile") or die "Unable to open file: $!\n";
    binmode SRCFILE;
    open(DSTFILE, "> $dstFile") or die "Unable to open file: $!\n";
    binmode DSTFILE;
    ###################################
    # Write the AU header
    ###################################
    print DSTFILE  ".snd";
    $foo = pack("CCCC", 0,0,0,24);
    print DSTFILE  $foo;
    $foo = pack("CCCC", 0xff,0xff,0xff,0xff);
    print DSTFILE  $foo;
    $foo = pack("CCCC", 0,0,0,3);
    print DSTFILE  $foo;
    $foo = pack("CCCC", 0,0,0x1f,0x40);
    print DSTFILE  $foo;
    $foo = pack("CCCC", 0,0,0,1);
    print DSTFILE  $foo;
    #############################
    # swap the PCM samples
    #############################
    while (read(SRCFILE, $inWord, 2) == 2) {
        @bytes   = unpack('CC', $inWord);
        $outWord = pack('CC', $bytes[1], $bytes[0]);
        print DSTFILE  $outWord;
    close(DSTFILE);
    close(SRCFILE);
                    Well this gives me an idea on how to go forward. Probably requires me to do some extra coding to make it into a program. Thanks indeed.
    – user349026
                    Oct 12, 2011 at 9:11
    
  • extract the RTP/RTCP packets: with a tool like rtpbreak: http://dallachiesa.com/code/rtpbreak/
  • generate (with and editor) a sdp file to be passed at ffmpeg or mplayer or vlan
  • launch ffmpeg (or mplayer or vlan) with SDP file
  • stream RTP/RTCP packets at ffmpeg with rtpplay: http://www.cs.columbia.edu/irt/software/rtptools/
  • But if your goal is "only" the pcap-audio decoding (with RTP G729 codec) then you can use videosnaf or xplico

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.