[FFmpeg-devel] [WIP] libcodec2 wrapper + de/muxer in FFmpeg

Tomas Härdin tjoppen at acc.umu.se
Thu Aug 3 01:40:04 EEST 2017


Hi

Posting this to both [ffmpeg-devel] and [Freetel-codec2] in hopes of
maximum feedback.

I've been spending the last few days getting codec2 (http://freedv.org/
) hooked up in libavcodec, and a set of muxers and demuxers for both
raw codec2 streams and the recently created .c2 format. codec2 is very
low bitrate (3200 bit/s down to 700 bit/s) speech codec developed for
digital voice in amateur radio, but is now finding use in other
applications where compressing large amounts of human speech is useful
(audiobooks or podcasts for example)

Sample: http://www.nivex.net/images/tmp/report2074.c2

With both the raw demuxer and the encoder you need to specify the
desired mode, like this:

  # Transcode .wav to .c2
  ffmpeg -i foo.wav -mode 700C out.c2

  # Transcode raw codec2 stream to .wav
  ffmpeg -mode 700C -i bar.raw out.wav

Decoding a .c2 file is straightforward however, thanks to the header:

  ffmpeg -i report2074.c2 out.wav

There's one issue currently which I suspect is due to timestamping,
where the demuxer seems to lose track of the block_align grid:

  $ ./ffmpeg -i report2074.c2 /tmp/out.wav
  ...
  Output #0, wav, to '/tmp/out.wav':
    Metadata:
      ISFT            : Lavf57.77.100
      Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz,
mono, s16, 128 kb/s
      Metadata:
        encoder         : Lavc57.103.100 pcm_s16le
  [libcodec2 @ 0x561d7bc4d1e0] Multiple frames in a packet
  [libcodec2 @ 0x561d7bc4d1e0] get_buffer() failed
  Error while decoding stream #0:0: Invalid argument
  [libcodec2 @ 0x561d7bc4d1e0] get_buffer() failed
  Error while decoding stream #0:0: Invalid argument
  [libcodec2 @ 0x7f59c0015840] Multiple frames in a packet.
  [libcodec2 @ 0x7f59c0015840] get_buffer() failed

I plan on looking into this once I've had some sleep.

Some remarks:

* I had to make the ffmpeg CLI not complain about the 700 modes, since
it thinks encoding at below 1 kbps is a user error

* I have duplicated some minor functions in libcodec2 in
libavcodec/codec2utils.*. This avoid having to link libcodec2 just for
remuxing, and in case someone writes a native decoder for libavcodec

* Not sure if codec2utils should go in libavutil, libavcodec felt good
enough

* The demuxer tries to read up to 0.1 seconds worth of frames to speed
things up a little without making seeking too broken. 3 frames = 12
bytes for the 700 bit/s modes, which decode to 960 samples

* The decoder is able to deal with multiple frames at a time, the
encoder does not need to

* The .c2 format is still fairly experimental, but the version bytes
should be enough to deal with any potential future variants 

Feel free to bikeshed around whether extradata should be the entire .c2
header or just the mode byte. It really only matters if we go with RIFF
or ISOM mappings (.wav .avi .mov and friends), which I decided to leave
out for now.

/Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-codec2-muxers-demuxers-and-en-decoder-via-libcod.patch
Type: text/x-patch
Size: 34216 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170803/18a2a535/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170803/18a2a535/attachment.sig>


More information about the ffmpeg-devel mailing list