x264编码后的文件保存

方法1:

在x264示例中的保存方法:

        i_frame_size = x264_encoder_encode( h, &nal, &i_nal, &pic, &pic_out );


        if( i_frame_size < 0 )
            goto fail;

        else if( i_frame_size )

        {
            if( !fwrite( nal->p_payload, i_frame_size, 1, stdout ) )
                goto fail;
        }


也就是说:i_frame_size :表示编码后的数据大小;

                   nal->p_payload:表示数据内容;


方法2:

x264_encoder_encode的函数注释:

/* x264_encoder_encode:
 *      encode one picture.
 *      *pi_nal is the number of NAL units outputtedin pp_nal.
 *      returns negative on error, zero if no NAL units returned.
 *      the payloads of all output NALs are guaranteed to be sequential in memory. */


int     x264_encoder_encode( x264_t *, x264_nal_t **pp_nal, int *pi_nal, x264_picture_t *pic_in, x264_picture_t *pic_out );

上面注释中有两句话比较重要:

1:

 *pi_nal is the number of NAL units outputted in pp_nal. :

表示 *pi_nal 是int类型,记录了当前编码后NAL数目;编码后的NAL保存在pp_nal中;

pp_nal 的类型是x264_nal_t **pp_nal,表示是指向指针的指针,也就是pp_nal是指向x264_nal_t链表的指针,每一个*pp_nal中保存一个NAL(也就是一个x264_nal_t 结构体);


2:the payloads of all output NALs are guaranteed to be sequential in memory;

这句话表示,NAL在内存是连续的,所以“方法1”是可行的;



方法2,是根据第一句话编写的:

        i_frame_size = x264_encoder_encode( h, &nal, &i_nal, &pic, &pic_out );


        if( i_frame_size < 0 )
            goto fail;

        else if( i_frame_size )

        {

               static FILE * f = fopen("encode_yuan_nal.h264","w+b"); 

for ( int i = 0; i < i_nal; i++ )
{
fwrite((nal + i)->p_payload, 1, (nal + i)->i_payload, f); 
}

        }


或者,可以简答的将 x264_nal_t **pp_nal 看做: x264_nal_t  *  pp_nal [ i_nal  ] ;


所以,这里,方法1 和 方法2 的结果是一样的,但是方法2的好处是在网络处理的时候,非常方便;

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chinabinlang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值