首页 > 解决方案 > LIBAV MJPEG 编码和霍夫曼表

问题描述

我正在尝试使用 libav(ffmpeg) 使用 MJPEG 视频有效负载创建 RTP 流 示例代码非常简单,它适用于 MPEG1 我看到 MJPEG 中的编码有效,但是当我需要发送 mjpeg 帧时,RTP 发送者返回错误:

[rtp @ 000000878ca77aa0] RFC 2435 需要 jpeg 的标准 Huffman 表

我在 libav 标头中看到评论:

/**
     * some codecs need / can use extradata like Huffman tables.
     * MJPEG: Huffman tables
     * rv10: additional flags
     * MPEG-4: global headers (they can be in the bitstream or here)
     * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
     * than extradata_size to avoid problems if it is read with the bitstream reader.
     * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
     * - encoding: Set/allocated/freed by libavcodec.
     * - decoding: Set/allocated/freed by user.
     */
    uint8_t *extradata;
    int extradata_size;

但是如何更正填充霍夫曼表或初始化默认表。我必须为编码器设置标志吗?谢谢。

标签: c++cvideo-processingmjpeglibav

解决方案


您可以将 huffman 选项设置为 0,即:

ffmpeg -i /dev/video0 -input_format mjpeg -f v4l2 -pix_fmt yuvj420p -vcodec mjpeg -huffman 0 -f rtp "rtp://127.0.0.1:10000" -sdp_file sdp_file 

推荐阅读