当前位置: 首页 > news >正文

工业网站开发商厦门免费推广平台

工业网站开发商,厦门免费推广平台,如何建一个微信公众号,企业网站怎样做seo优化 应该如何做1、查找所需的编码器–avcodec_find_encoder或avcodec_find_encoder_by_name 音频编码和视频编码流程基本相同#xff0c;使用音频编码器则可以编码音频数据#xff0c;使用视频编码器则可以编码视频数据。 /* 指定的编码器 ID 查找对应的编码器。可以通过这个函数来获取特…1、查找所需的编码器–avcodec_find_encoder或avcodec_find_encoder_by_name 音频编码和视频编码流程基本相同使用音频编码器则可以编码音频数据使用视频编码器则可以编码视频数据。 /* 指定的编码器 ID 查找对应的编码器。可以通过这个函数来获取特定编码器的 AVCodec 结构体从而进行后续的编码操作。* id表示要查找的编码器的 AVCodecID 枚举类型标识符。*/ AVCodec *avcodec_find_encoder(enum AVCodecID id);/* 根据指定的编码器名称查找对应的编码器。*/ AVCodec *avcodec_find_encoder_by_name(const char *name);2、获取编码上下文信息存储结构–avcodec_alloc_context3 /* 该函数将返回一个指向 AVCodecContext 结构体的指针该结构体已经被适当地分配和初始化可以在接下来的编解码操作中使用。* codec指向要分配上下文的 AVCodec 结构体的指针。*/ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);3、设置编码上下文信息 4、将编码器上下文和编码器进行关联—avcodec_open2 /* 该函数会尝试打开指定的编解码器并将其状态保存在 AVCodecContext 结构体中以便后续进行编解码操作。如果打开成功函数将返回0如果发生错误将返回一个负值表示错误代码。 * avctx指向要打开的 AVCodecContext 结构体的指针。 * codec指向要使用的 AVCodec 结构体的指针。 * options一个指向 AVDictionary 指针的指针用于传递额外的选项参数给编解码器。 */ int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);5、分配存储压缩编码数据的帧结构–av_packet_alloc /*分配一个新的 AVPacket 结构体并对其进行初始化。AVPacket 结构体用于存储压缩编码后的音视频数据包可以在音视频编解码过程中用来传递数据。*/ AVPacket *av_packet_alloc(void);6、分配存储音视频帧元数据结构–av_frame_alloc /* 分配一个新的 AVFrame 结构体并对其进行初始化。AVFrame 结构体用于存储音视频帧的数据包括像素数据、采样数据以及相关的元信息。 */ AVFrame *av_frame_alloc(void);7、将数据填充的AVFrame 结构中—av_samples_fill_arrays /* 将已分配的内存填充为包含音频样本数据的数组。这个函数通常用于为音频数据提供一个包含样本数据的数组以便后续进行音频编解码或处理操作。* audio_data指向一个指针数组的指针用于存储填充后的音频数据。* linesize一个整型数组用于存储每个音频通道的行大小字节数如果不需要可以传入 NULL。* buf指向包含音频数据的缓冲区。* nb_channels音频通道数。* nb_samples每个通道中的样本数。* sample_fmt音频采样格式枚举类型 AVSampleFormat。* align对齐值通常设为0。*/int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,const uint8_t *buf, int nb_channels, int nb_samples,enum AVSampleFormat sample_fmt, int align);8、将音频或视频源数据发送到编解码中处理–avcodec_send_frame /* 该函数将会把待编解码的帧送入编解码器进行处理。如果发送成功函数将返回0如果发生错误将返回一个负值表示错误代码。* avctx指向已经打开的 AVCodecContext 结构体的指针表示要使用的编解码器上下文。* frame指向 AVFrame 结构体的指针表示待编解码的音视频帧数据。*/ int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);9、接收编码后的数据包–avcodec_receive_packet /* 该函数将从编解码器中接收解码后的数据包并将其存储在提供的 AVPacket 结构体中。如果成功接收到数据包则函数返回0如果没有可用数据包或者出现错误则返回负值表示错误代码。* avctx指向已经打开的 AVCodecContext 结构体的指针表示要使用的编解码器上下文。* avpkt指向 AVPacket 结构体的指针用于接收解码后的数据包。*/ int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);10、将编码后的音频、视频数据包按照一定的格式存储到文件中 例如AAC文件则先写好其adts头部数据再存储音频数据帧。 11、音频代码 /** * projectName 08-01-encode_audio * brief 音频编码 * 从本地读取PCM数据进行AAC编码 * 1. 输入PCM格式问题通过AVCodec的sample_fmts参数获取具体的格式支持 * 1默认的aac编码器输入的PCM格式为:AV_SAMPLE_FMT_FLTP * 2libfdk_aac编码器输入的PCM格式为AV_SAMPLE_FMT_S16. * 2. 支持的采样率通过AVCodec的supported_samplerates可以获取 * author Liao Qingfu * date 2020-04-15 */#include stdint.h #include stdio.h #include stdlib.h#include libavcodec/avcodec.h#include libavutil/channel_layout.h #include libavutil/common.h #include libavutil/frame.h #include libavutil/samplefmt.h #include libavutil/opt.h/* 检测该编码器是否支持该采样格式 */ static int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt) {const enum AVSampleFormat *p codec-sample_fmts;while (*p ! AV_SAMPLE_FMT_NONE) { // 通过AV_SAMPLE_FMT_NONE作为结束符if (*p sample_fmt)return 1;p;}return 0; }/* 检测该编码器是否支持该采样率 */ static int check_sample_rate(const AVCodec *codec, const int sample_rate) {const int *p codec-supported_samplerates;while (*p ! 0) {// 0作为退出条件比如libfdk-aacenc.c的aac_sample_ratesprintf(%s support %dhz\n, codec-name, *p);if (*p sample_rate)return 1;p;}return 0; }/* 检测该编码器是否支持该采样率, 该函数只是作参考 */ static int check_channel_layout(const AVCodec *codec, const uint64_t channel_layout) {// 不是每个codec都给出支持的channel_layoutconst uint64_t *p codec-channel_layouts;if(!p) {printf(the codec %s no set channel_layouts\n, codec-name);return 1;}while (*p ! 0) { // 0作为退出条件比如libfdk-aacenc.c的aac_channel_layoutprintf(%s support channel_layout %d\n, codec-name, *p);if (*p channel_layout)return 1;p;}return 0; }static void get_adts_header(AVCodecContext *ctx, uint8_t *adts_header, int aac_length) {uint8_t freq_idx 0; //0: 96000 Hz 3: 48000 Hz 4: 44100 Hzswitch (ctx-sample_rate) {case 96000: freq_idx 0; break;case 88200: freq_idx 1; break;case 64000: freq_idx 2; break;case 48000: freq_idx 3; break;case 44100: freq_idx 4; break;case 32000: freq_idx 5; break;case 24000: freq_idx 6; break;case 22050: freq_idx 7; break;case 16000: freq_idx 8; break;case 12000: freq_idx 9; break;case 11025: freq_idx 10; break;case 8000: freq_idx 11; break;case 7350: freq_idx 12; break;default: freq_idx 4; break;}uint8_t chanCfg ctx-channels;uint32_t frame_length aac_length 7;adts_header[0] 0xFF;adts_header[1] 0xF1;adts_header[2] ((ctx-profile) 6) (freq_idx 2) (chanCfg 2);adts_header[3] (((chanCfg 3) 6) (frame_length 11));adts_header[4] ((frame_length 0x7FF) 3);adts_header[5] (((frame_length 7) 5) 0x1F);adts_header[6] 0xFC; } /* * */ static int encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output) {int ret;/* send the frame for encoding */ret avcodec_send_frame(ctx, frame);if (ret 0) {fprintf(stderr, Error sending the frame to the encoder\n);return -1;}/* read all the available output packets (in general there may be any number of them */// 编码和解码都是一样的都是send 1次然后receive多次, 直到AVERROR(EAGAIN)或者AVERROR_EOFwhile (ret 0) {ret avcodec_receive_packet(ctx, pkt);if (ret AVERROR(EAGAIN) || ret AVERROR_EOF) {return 0;} else if (ret 0) {fprintf(stderr, Error encoding audio frame\n);return -1;}uint8_t aac_header[7];get_adts_header(ctx, aac_header, pkt-size);size_t len 0;len fwrite(aac_header, 1, 7, output);if(len ! 7) {fprintf(stderr, fwrite aac_header failed\n);return -1;}len fwrite(pkt-data, 1, pkt-size, output);if(len ! pkt-size) {fprintf(stderr, fwrite aac data failed\n);return -1;}/* 是否需要释放数据? avcodec_receive_packet第一个调用的就是 av_packet_unref* 所以我们不用手动去释放这里有个问题不能将pkt直接插入到队列因为编码器会释放数据* 可以新分配一个pkt, 然后使用av_packet_move_ref转移pkt对应的buffer*/// av_packet_unref(pkt);}return -1; }/** 这里只支持2通道的转换 */ void f32le_convert_to_fltp(float *f32le, float *fltp, int nb_samples) {float *fltp_l fltp; // 左通道float *fltp_r fltp nb_samples; // 右通道for(int i 0; i nb_samples; i) {fltp_l[i] f32le[i*2]; // 0 1 - 2 3fltp_r[i] f32le[i*21]; // 可以尝试注释左声道或者右声道听听声音} } /** 提取测试文件* 1s16格式ffmpeg -i buweishui.aac -ar 48000 -ac 2 -f s16le 48000_2_s16le.pcm* 2flt格式ffmpeg -i buweishui.aac -ar 48000 -ac 2 -f f32le 48000_2_f32le.pcm* ffmpeg只能提取packed格式的PCM数据在编码时候如果输入要为fltp则需要进行转换* 测试范例:* 148000_2_s16le.pcm libfdk_aac.aac libfdk_aac // 如果编译的时候没有支持fdk aac则提示找不到编码器* 248000_2_f32le.pcm aac.aac aac // 我们这里只测试aac编码器不测试fdkaac */ int main(int argc, char **argv) {char *in_pcm_file NULL;char *out_aac_file NULL;FILE *infile NULL;FILE *outfile NULL;const AVCodec *codec NULL;AVCodecContext *codec_ctx NULL;AVFrame *frame NULL;AVPacket *pkt NULL;int ret 0;int force_codec 0; // 强制使用指定的编码char *codec_name NULL;if (argc 3) {fprintf(stderr, Usage: %s input_file out_file [codec_name], argc:%d\n,argv[0], argc);return 0;}in_pcm_file argv[1]; // 输入PCM文件out_aac_file argv[2]; // 输出的AAC文件enum AVCodecID codec_id AV_CODEC_ID_AAC;if(4 argc) {if(strcmp(argv[3], libfdk_aac) 0) {force_codec 1; // 强制使用 libfdk_aaccodec_name libfdk_aac;} else if(strcmp(argv[3], aac) 0) {force_codec 1;codec_name aac;}}if(force_codec)printf(force codec name: %s\n, codec_name);elseprintf(default codec name: %s\n, aac);if(force_codec 0) { // 没有强制设置编码器codec avcodec_find_encoder(codec_id); // 按ID查找则缺省的aac encode为aacenc.c} else {// 按名字查找指定的encode,对应AVCodec的name字段codec avcodec_find_encoder_by_name(codec_name);}if (!codec) {fprintf(stderr, Codec not found\n);exit(1);}codec_ctx avcodec_alloc_context3(codec);if (!codec_ctx) {fprintf(stderr, Could not allocate audio codec context\n);exit(1);}codec_ctx-codec_id codec_id;codec_ctx-codec_type AVMEDIA_TYPE_AUDIO;codec_ctx-bit_rate 128*1024;codec_ctx-channel_layout AV_CH_LAYOUT_STEREO;codec_ctx-sample_rate 48000; //48000;codec_ctx-channels av_get_channel_layout_nb_channels(codec_ctx-channel_layout);codec_ctx-profile FF_PROFILE_AAC_LOW; //if(strcmp(codec-name, aac) 0) {codec_ctx-sample_fmt AV_SAMPLE_FMT_FLTP;} else if(strcmp(codec-name, libfdk_aac) 0) {codec_ctx-sample_fmt AV_SAMPLE_FMT_S16;} else {codec_ctx-sample_fmt AV_SAMPLE_FMT_FLTP;}/* 检测支持采样格式支持情况 */if (!check_sample_fmt(codec, codec_ctx-sample_fmt)) {fprintf(stderr, Encoder does not support sample format %s,av_get_sample_fmt_name(codec_ctx-sample_fmt));exit(1);}if (!check_sample_rate(codec, codec_ctx-sample_rate)) {fprintf(stderr, Encoder does not support sample rate %d, codec_ctx-sample_rate);exit(1);}if (!check_channel_layout(codec, codec_ctx-channel_layout)) {fprintf(stderr, Encoder does not support channel layout %lu, codec_ctx-channel_layout);exit(1);}printf(\n\nAudio encode config\n);printf(bit_rate:%ldkbps\n, codec_ctx-bit_rate/1024);printf(sample_rate:%d\n, codec_ctx-sample_rate);printf(sample_fmt:%s\n, av_get_sample_fmt_name(codec_ctx-sample_fmt));printf(channels:%d\n, codec_ctx-channels);// frame_size是在avcodec_open2后进行关联printf(1 frame_size:%d\n, codec_ctx-frame_size);/* 将编码器上下文和编码器进行关联 */if (avcodec_open2(codec_ctx, codec, NULL) 0) {fprintf(stderr, Could not open codec\n);exit(1);}printf(2 frame_size:%d\n\n, codec_ctx-frame_size); // 决定每次到底送多少个采样点// 打开输入和输出文件infile fopen(in_pcm_file, rb);if (!infile) {fprintf(stderr, Could not open %s\n, in_pcm_file);exit(1);}outfile fopen(out_aac_file, wb);if (!outfile) {fprintf(stderr, Could not open %s\n, out_aac_file);exit(1);}/* packet for holding encoded output */pkt av_packet_alloc();if (!pkt){fprintf(stderr, could not allocate the packet\n);exit(1);}/* frame containing input raw audio */frame av_frame_alloc();if (!frame){fprintf(stderr, Could not allocate audio frame\n);exit(1);}/* 每次送多少数据给编码器由* (1)frame_size(每帧单个通道的采样点数);* (2)sample_fmt(采样点格式);* (3)channel_layout(通道布局情况);* 3要素决定*/frame-nb_samples codec_ctx-frame_size;frame-format codec_ctx-sample_fmt;frame-channel_layout codec_ctx-channel_layout;frame-channels av_get_channel_layout_nb_channels(frame-channel_layout);printf(frame nb_samples:%d\n, frame-nb_samples);printf(frame sample_fmt:%d\n, frame-format);printf(frame channel_layout:%lu\n\n, frame-channel_layout);/* 为frame分配buffer */ret av_frame_get_buffer(frame, 0);if (ret 0){fprintf(stderr, Could not allocate audio data buffers\n);exit(1);}// 计算出每一帧的数据 单个采样点的字节 * 通道数目 * 每帧采样点数量int frame_bytes av_get_bytes_per_sample(frame-format) \* frame-channels \* frame-nb_samples;printf(frame_bytes %d\n, frame_bytes);uint8_t *pcm_buf (uint8_t *)malloc(frame_bytes);if(!pcm_buf) {printf(pcm_buf malloc failed\n);return 1;}uint8_t *pcm_temp_buf (uint8_t *)malloc(frame_bytes);if(!pcm_temp_buf) {printf(pcm_temp_buf malloc failed\n);return 1;}int64_t pts 0;printf(start enode\n);for (;;) {memset(pcm_buf, 0, frame_bytes);size_t read_bytes fread(pcm_buf, 1, frame_bytes, infile);if(read_bytes 0) {printf(read file finish\n);break; // fseek(infile,0,SEEK_SET); // fflush(outfile); // continue;}/* 确保该frame可写, 如果编码器内部保持了内存参考计数则需要重新拷贝一个备份目的是新写入的数据和编码器保存的数据不能产生冲突*/ret av_frame_make_writable(frame);if(ret ! 0)printf(av_frame_make_writable failed, ret %d\n, ret);if(AV_SAMPLE_FMT_S16 frame-format) {// 将读取到的PCM数据填充到frame去但要注意格式的匹配, 是planar还是packed都要区分清楚ret av_samples_fill_arrays(frame-data, frame-linesize,pcm_buf, frame-channels,frame-nb_samples, frame-format, 0);} else {// 将读取到的PCM数据填充到frame去但要注意格式的匹配, 是planar还是packed都要区分清楚// 将本地的f32le packed模式的数据转为float palanarmemset(pcm_temp_buf, 0, frame_bytes);f32le_convert_to_fltp((float *)pcm_buf, (float *)pcm_temp_buf, frame-nb_samples);ret av_samples_fill_arrays(frame-data, frame-linesize,pcm_temp_buf, frame-channels,frame-nb_samples, frame-format, 0);}// 设置ptspts frame-nb_samples;frame-pts pts; // 使用采样率作为pts的单位具体换算成秒 pts*1/采样率ret encode(codec_ctx, frame, pkt, outfile);if(ret 0) {printf(encode failed\n);break;}}/* 冲刷编码器 */encode(codec_ctx, NULL, pkt, outfile);// 关闭文件fclose(infile);fclose(outfile);// 释放内存if(pcm_buf) {free(pcm_buf);}if (pcm_temp_buf) {free(pcm_temp_buf);}av_frame_free(frame);av_packet_free(pkt);avcodec_free_context(codec_ctx);printf(main finish, please enter Enter and exit\n);getchar();return 0; }12、视频编码代码 /** * projectName 08-02-encode_video * brief 视频编码从本地读取YUV数据进行H264编码 * author Liao Qingfu * date 2020-04-16 */ #include stdio.h #include stdlib.h #include string.h#include libavcodec/avcodec.h #include libavutil/time.h #include libavutil/opt.h #include libavutil/imgutils.hint64_t get_time() {return av_gettime_relative() / 1000; // 换算成毫秒 } static int encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,FILE *outfile) {int ret;/* send the frame to the encoder */if (frame)printf(Send frame %lld\n, frame-pts);/* 通过查阅代码使用x264进行编码时具体缓存帧是在x264源码进行* 不会增加avframe对应buffer的reference*/ret avcodec_send_frame(enc_ctx, frame);if (ret 0){fprintf(stderr, Error sending a frame for encoding\n);return -1;}while (ret 0){ret avcodec_receive_packet(enc_ctx, pkt);if (ret AVERROR(EAGAIN) || ret AVERROR_EOF) {return 0;} else if (ret 0) {fprintf(stderr, Error encoding audio frame\n);return -1;}if(pkt-flags AV_PKT_FLAG_KEY)printf(Write packet flags:%d pts:%lld dts:%lld (size:%5d)\n,pkt-flags, pkt-pts, pkt-dts, pkt-size);if(!pkt-flags)printf(Write packet flags:%d pts:%lld dts:%lld (size:%5d)\n,pkt-flags, pkt-pts, pkt-dts, pkt-size);fwrite(pkt-data, 1, pkt-size, outfile);}return 0; } /*** brief 提取测试文件ffmpeg -i test_1280x720.flv -t 5 -r 25 -pix_fmt yuv420p yuv420p_1280x720.yuv* 参数输入: yuv420p_1280x720.yuv yuv420p_1280x720.h264 libx264* param argc* param argv* return*/ int main(int argc, char **argv) {char *in_yuv_file NULL;char *out_h264_file NULL;FILE *infile NULL;FILE *outfile NULL;const char *codec_name NULL;const AVCodec *codec NULL;AVCodecContext *codec_ctx NULL;AVFrame *frame NULL;AVPacket *pkt NULL;int ret 0;if (argc 4) {fprintf(stderr, Usage: %s input_file out_file codec_name , argc:%d\n,argv[0], argc);return 0;}in_yuv_file argv[1]; // 输入YUV文件out_h264_file argv[2];codec_name argv[3];/* 查找指定的编码器 */codec avcodec_find_encoder_by_name(codec_name);if (!codec) {fprintf(stderr, Codec %s not found\n, codec_name);exit(1);}codec_ctx avcodec_alloc_context3(codec);if (!codec_ctx) {fprintf(stderr, Could not allocate video codec context\n);exit(1);}/* 设置分辨率*/codec_ctx-width 1280;codec_ctx-height 720;/* 设置time base */codec_ctx-time_base (AVRational)({1,25});codec_ctx-framerate (AVRational)({25, 1});/* 设置I帧间隔* 如果frame-pict_type设置为AV_PICTURE_TYPE_I, 则忽略gop_size的设置一直当做I帧进行编码*/codec_ctx-gop_size 25; // I帧间隔codec_ctx-max_b_frames 2; // 如果不想包含B帧则设置为0codec_ctx-pix_fmt AV_PIX_FMT_YUV420P;//if (codec-id AV_CODEC_ID_H264) {// 相关的参数可以参考libx264.c的 AVOption options// ultrafast all encode time:2270ms// medium all encode time:5815ms// veryslow all encode time:19836msret av_opt_set(codec_ctx-priv_data, preset, medium, 0);if(ret ! 0) {printf(av_opt_set preset failed\n);}ret av_opt_set(codec_ctx-priv_data, profile, main, 0); // 默认是highif(ret ! 0) {printf(av_opt_set profile failed\n);}ret av_opt_set(codec_ctx-priv_data, tune,zerolatency,0); // 直播是才使用该设置 // ret av_opt_set(codec_ctx-priv_data, tune,film,0); // 画质filmif(ret ! 0) {printf(av_opt_set tune failed\n);}}/** 设置编码器参数*//* 设置bitrate */codec_ctx-bit_rate 3000000; // codec_ctx-rc_max_rate 3000000; // codec_ctx-rc_min_rate 3000000; // codec_ctx-rc_buffer_size 2000000; // codec_ctx-thread_count 4; // 开了多线程后也会导致帧输出延迟, 需要缓存thread_count帧后再编程。 // codec_ctx-thread_type FF_THREAD_FRAME; // 并 设置为FF_THREAD_FRAME/* 对于H264 AV_CODEC_FLAG_GLOBAL_HEADER 设置则只包含I帧此时sps pps需要从codec_ctx-extradata读取* 不设置则每个I帧都带 sps pps sei*/ // codec_ctx-flags | AV_CODEC_FLAG_GLOBAL_HEADER; // 存本地文件时不要去设置/* 将codec_ctx和codec进行绑定 */ret avcodec_open2(codec_ctx, codec, NULL);if (ret 0) {fprintf(stderr, Could not open codec: %s\n, av_err2str(ret));exit(1);}printf(thread_count: %d, thread_type:%d\n, codec_ctx-thread_count, codec_ctx-thread_type);// 打开输入和输出文件infile fopen(in_yuv_file, rb);if (!infile) {fprintf(stderr, Could not open %s\n, in_yuv_file);exit(1);}outfile fopen(out_h264_file, wb);if (!outfile) {fprintf(stderr, Could not open %s\n, out_h264_file);exit(1);}// 分配pkt和framepkt av_packet_alloc();if (!pkt) {fprintf(stderr, Could not allocate video frame\n);exit(1);}frame av_frame_alloc();if (!frame) {fprintf(stderr, Could not allocate video frame\n);exit(1);}// 为frame分配bufferframe-format codec_ctx-pix_fmt;frame-width codec_ctx-width;frame-height codec_ctx-height;ret av_frame_get_buffer(frame, 0);if (ret 0) {fprintf(stderr, Could not allocate the video frame data\n);exit(1);}// 计算出每一帧的数据 像素格式 * 宽 * 高// 1382400int frame_bytes av_image_get_buffer_size(frame-format, frame-width,frame-height, 1);printf(frame_bytes %d\n, frame_bytes);uint8_t *yuv_buf (uint8_t *)malloc(frame_bytes);if(!yuv_buf) {printf(yuv_buf malloc failed\n);return 1;}int64_t begin_time get_time();int64_t end_time begin_time;int64_t all_begin_time get_time();int64_t all_end_time all_begin_time;int64_t pts 0;printf(start enode\n);for (;;) {memset(yuv_buf, 0, frame_bytes);size_t read_bytes fread(yuv_buf, 1, frame_bytes, infile);if(read_bytes 0) {printf(read file finish\n);break;}/* 确保该frame可写, 如果编码器内部保持了内存参考计数则需要重新拷贝一个备份目的是新写入的数据和编码器保存的数据不能产生冲突*/int frame_is_writable 1;if(av_frame_is_writable(frame) 0) { // 这里只是用来测试printf(the frame cant write, buf:%p\n, frame-buf[0]);if(frame-buf frame-buf[0]) // 打印referenc-counted必须保证传入的是有效指针printf(ref_count1(frame) %d\n, av_buffer_get_ref_count(frame-buf[0]));frame_is_writable 0;}ret av_frame_make_writable(frame);if(frame_is_writable 0) { // 这里只是用来测试printf(av_frame_make_writable, buf:%p\n, frame-buf[0]);if(frame-buf frame-buf[0]) // 打印referenc-counted必须保证传入的是有效指针printf(ref_count2(frame) %d\n, av_buffer_get_ref_count(frame-buf[0]));}if(ret ! 0) {printf(av_frame_make_writable failed, ret %d\n, ret);break;}int need_size av_image_fill_arrays(frame-data, frame-linesize, yuv_buf,frame-format,frame-width, frame-height, 1);if(need_size ! frame_bytes) {printf(av_image_fill_arrays failed, need_size:%d, frame_bytes:%d\n,need_size, frame_bytes);break;}pts 40;// 设置ptsframe-pts pts; // 使用采样率作为pts的单位具体换算成秒 pts*1/采样率begin_time get_time();ret encode(codec_ctx, frame, pkt, outfile);end_time get_time();printf(encode time:%lldms\n, end_time - begin_time);if(ret 0) {printf(encode failed\n);break;}}/* 冲刷编码器 */encode(codec_ctx, NULL, pkt, outfile);all_end_time get_time();printf(all encode time:%lldms\n, all_end_time - all_begin_time);// 关闭文件fclose(infile);fclose(outfile);// 释放内存if(yuv_buf) {free(yuv_buf);}av_frame_free(frame);av_packet_free(pkt);avcodec_free_context(codec_ctx);printf(main finish, please enter Enter and exit\n);getchar();return 0; }
文章转载自:
http://www.morning.znkls.cn.gov.cn.znkls.cn
http://www.morning.xyyplp.cn.gov.cn.xyyplp.cn
http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn
http://www.morning.rwlns.cn.gov.cn.rwlns.cn
http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn
http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn
http://www.morning.dhpjq.cn.gov.cn.dhpjq.cn
http://www.morning.qhrlb.cn.gov.cn.qhrlb.cn
http://www.morning.gl-group.cn.gov.cn.gl-group.cn
http://www.morning.pswqx.cn.gov.cn.pswqx.cn
http://www.morning.chgmm.cn.gov.cn.chgmm.cn
http://www.morning.ghcfx.cn.gov.cn.ghcfx.cn
http://www.morning.rqbr.cn.gov.cn.rqbr.cn
http://www.morning.prgnp.cn.gov.cn.prgnp.cn
http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn
http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn
http://www.morning.jggr.cn.gov.cn.jggr.cn
http://www.morning.qjdqj.cn.gov.cn.qjdqj.cn
http://www.morning.bpmfn.cn.gov.cn.bpmfn.cn
http://www.morning.skkmz.cn.gov.cn.skkmz.cn
http://www.morning.kfclh.cn.gov.cn.kfclh.cn
http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn
http://www.morning.0small.cn.gov.cn.0small.cn
http://www.morning.lbbyx.cn.gov.cn.lbbyx.cn
http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn
http://www.morning.hmjasw.com.gov.cn.hmjasw.com
http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn
http://www.morning.byywt.cn.gov.cn.byywt.cn
http://www.morning.kzcfr.cn.gov.cn.kzcfr.cn
http://www.morning.bzsqr.cn.gov.cn.bzsqr.cn
http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn
http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn
http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn
http://www.morning.qtqjx.cn.gov.cn.qtqjx.cn
http://www.morning.tklqs.cn.gov.cn.tklqs.cn
http://www.morning.bfbl.cn.gov.cn.bfbl.cn
http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn
http://www.morning.mkyny.cn.gov.cn.mkyny.cn
http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn
http://www.morning.nfcxq.cn.gov.cn.nfcxq.cn
http://www.morning.smfbw.cn.gov.cn.smfbw.cn
http://www.morning.qgkcs.cn.gov.cn.qgkcs.cn
http://www.morning.rhkq.cn.gov.cn.rhkq.cn
http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn
http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn
http://www.morning.kfwrq.cn.gov.cn.kfwrq.cn
http://www.morning.xbdrc.cn.gov.cn.xbdrc.cn
http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn
http://www.morning.clwhf.cn.gov.cn.clwhf.cn
http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn
http://www.morning.knpbr.cn.gov.cn.knpbr.cn
http://www.morning.jbpodhb.cn.gov.cn.jbpodhb.cn
http://www.morning.mqlsf.cn.gov.cn.mqlsf.cn
http://www.morning.qqbw.cn.gov.cn.qqbw.cn
http://www.morning.dgckn.cn.gov.cn.dgckn.cn
http://www.morning.bygyd.cn.gov.cn.bygyd.cn
http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn
http://www.morning.jppdk.cn.gov.cn.jppdk.cn
http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn
http://www.morning.yrmpz.cn.gov.cn.yrmpz.cn
http://www.morning.tklqs.cn.gov.cn.tklqs.cn
http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn
http://www.morning.gftnx.cn.gov.cn.gftnx.cn
http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn
http://www.morning.nlglm.cn.gov.cn.nlglm.cn
http://www.morning.rqdx.cn.gov.cn.rqdx.cn
http://www.morning.routalr.cn.gov.cn.routalr.cn
http://www.morning.ngcw.cn.gov.cn.ngcw.cn
http://www.morning.ygkb.cn.gov.cn.ygkb.cn
http://www.morning.plqkz.cn.gov.cn.plqkz.cn
http://www.morning.qclmz.cn.gov.cn.qclmz.cn
http://www.morning.pmnn.cn.gov.cn.pmnn.cn
http://www.morning.jqjnl.cn.gov.cn.jqjnl.cn
http://www.morning.qrhh.cn.gov.cn.qrhh.cn
http://www.morning.xyjlh.cn.gov.cn.xyjlh.cn
http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn
http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn
http://www.morning.jjhng.cn.gov.cn.jjhng.cn
http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn
http://www.morning.gkpgj.cn.gov.cn.gkpgj.cn
http://www.tj-hxxt.cn/news/269742.html

相关文章:

  • vr全景网站怎么做厦门百度关键词优化
  • 自助建站免费建站五个平台东莞做好网络推广
  • c 网站开发案例源码景区外文网站建设
  • 免费发群二维码的网站友情链接购买
  • 仿制单页面网站多少钱wordpress 谷歌字体 360插件
  • 自己做网站的方法公众号文章存储wordpress
  • 北京网站备案的地址h5网页
  • 可以做设计的网站有哪些建网站投放广告赚钱
  • 咸阳学校网站建设报价流量主小程序搭建
  • 聊城专业做网站网站备案后怎么做
  • 子域名的网站放到哪里去软件开发工程师的薪资待遇
  • 新建的网站百度搜索不到郑州一建
  • 个性化网站成功的案例微信网站建设公司费用
  • 求职简历在哪个网站做网站制作公司哪里好
  • 南宁免费自助建站模板做渔具网站
  • 深圳住房和城乡建设厅网站学wordpress
  • 网站平台做推广方案宁波做企业网站公司
  • 尚仁网站建设电子商务网站建设财务分析
  • 网站前台模板免费下载备案域名解析
  • joomla 网站建设教程西安做营销型网站
  • 苏州好的网站公司哪家好wordpress菜单与页面关联
  • 做直播网站用什么网上空间好网站建设合同的要素及签订注意事项
  • 专业网站开发技术中国做国外的网站
  • 深圳品牌网站制作平台书画网站的建设目标
  • 建站系统哪个比较好最近韩国电影片在线观看
  • win2012 iis添加网站寻找网站开发
  • 厦门做医院网站设计的公司网站开发思路怎么写
  • 网站建设广告素材wordpress最炫主题
  • 网站的安全性建设温州谷歌seo
  • 网站开发前期准备工作英文公司网站模板