- 浏览: 184399 次
- 性别:
- 来自: 长沙
文章分类
最新评论
-
LXX516:
<div class="quote_title ...
PC客户端与Android实现图片传送 -
LXX516:
你好,运行时出现如下问题:E/Trace(15019): er ...
PC客户端与Android实现图片传送 -
huzhenyu:
希望各位大顶起,支持国产免费软件
公式编辑器MathMarkEdit1.0发布 -
zhangyou1010:
默认是8000的端口,如果用sh catalina.sh jp ...
使用eclipse远程调试部署在tomcat上的应用程序 -
zhangyou1010:
有时间,也要玩玩QT,哈哈。
Qt Grid布局
#ifdef __cplusplus extern "C" { #endif #include "libavutil/opt.h" #include "libavcodec/avcodec.h" #include "libavutil/audioconvert.h" #include "libavutil/common.h" #include "libavutil/imgutils.h" #include "libavutil/mathematics.h" #include "libavutil/samplefmt.h" #define INBUF_SIZE 4096 #define AUDIO_INBUF_SIZE 20480 #define AUDIO_REFILL_THRESH 4096 //int main() //{ // std::cout << "Test"; // int i = 0; // std::cin >> i; // return 0; //} /* check that a given sample format is supported by the encoder */ static int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt) { const enum AVSampleFormat *p = codec->sample_fmts; while (*p != AV_SAMPLE_FMT_NONE) { if (*p == sample_fmt) return 1; p++; } return 0; } /* just pick the highest supported samplerate */ static int select_sample_rate(AVCodec *codec) { const int *p; int best_samplerate = 0; if (!codec->supported_samplerates) return 44100; p = codec->supported_samplerates; while (*p) { best_samplerate = FFMAX(*p, best_samplerate); p++; } return best_samplerate; } /* select layout with the highest channel count */ static int select_channel_layout(AVCodec *codec) { const uint64_t *p; uint64_t best_ch_layout = 0; int best_nb_channells = 0; if (!codec->channel_layouts) return AV_CH_LAYOUT_STEREO; p = codec->channel_layouts; while (*p) { int nb_channels = av_get_channel_layout_nb_channels(*p); if (nb_channels > best_nb_channells) { best_ch_layout = *p; best_nb_channells = nb_channels; } p++; } return best_ch_layout; } /* * Video encoding example */ static void video_encode_example(const char *filename, int codec_id) { AVCodec *codec; AVCodecContext *c= NULL; int i, ret, x, y, got_output; FILE *f; AVFrame *frame; AVPacket pkt; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; printf("Encode video file %s\n", filename); /* find the mpeg1 video encoder */ //codec = avcodec_find_encoder(codec_id); codec = avcodec_find_encoder(AV_CODEC_ID_H264); if (!codec) { fprintf(stderr, "Codec not found\n"); exit(1); } c = avcodec_alloc_context3(codec); /* put sample parameters */ c->bit_rate = 400000; /* resolution must be a multiple of two */ c->width = 352; c->height = 288; /* frames per second */ AVRational avr; avr.den = 25; avr.num = 1; c->time_base = avr; //c->time_base= (AVRational){1,25}; c->gop_size = 10; /* emit one intra frame every ten frames */ c->max_b_frames=1; c->pix_fmt = AV_PIX_FMT_YUV420P; if(codec_id == AV_CODEC_ID_H264) av_opt_set(c->priv_data, "preset", "slow", 0); /* open it */ if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "Could not open codec\n"); exit(1); } f = fopen(filename, "wb"); if (!f) { fprintf(stderr, "Could not open %s\n", filename); exit(1); } frame = avcodec_alloc_frame(); if (!frame) { fprintf(stderr, "Could not allocate video frame\n"); exit(1); } frame->format = c->pix_fmt; frame->width = c->width; frame->height = c->height; /* the image can be allocated by any means and av_image_alloc() is * just the most convenient way if av_malloc() is to be used */ ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32); if (ret < 0) { fprintf(stderr, "Could not allocate raw picture buffer\n"); exit(1); } /* encode 1 second of video */ for(i=0;i<25;i++) { av_init_packet(&pkt); pkt.data = NULL; // packet data will be allocated by the encoder pkt.size = 0; fflush(stdout); /* prepare a dummy image */ /* Y */ for(y=0;y<c->height;y++) { for(x=0;x<c->width;x++) { frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3; } } /* Cb and Cr */ for(y=0;y<c->height/2;y++) { for(x=0;x<c->width/2;x++) { frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2; frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5; } } frame->pts = i; /* encode the image */ ret = avcodec_encode_video2(c, &pkt, frame, &got_output); if (ret < 0) { fprintf(stderr, "Error encoding frame\n"); exit(1); } if (got_output) { printf("Write frame %3d (size=%5d)\n", i, pkt.size); fwrite(pkt.data, 1, pkt.size, f); av_free_packet(&pkt); } } /* get the delayed frames */ for (got_output = 1; got_output; i++) { fflush(stdout); ret = avcodec_encode_video2(c, &pkt, NULL, &got_output); if (ret < 0) { fprintf(stderr, "Error encoding frame\n"); exit(1); } if (got_output) { printf("Write frame %3d (size=%5d)\n", i, pkt.size); fwrite(pkt.data, 1, pkt.size, f); av_free_packet(&pkt); } } /* add sequence end code to have a real mpeg file */ fwrite(endcode, 1, sizeof(endcode), f); fclose(f); avcodec_close(c); av_free(c); av_freep(&frame->data[0]); avcodec_free_frame(&frame); printf("\n"); } /* * Video decoding example */ static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) { FILE *f; int i; f=fopen(filename,"w"); fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255); for(i=0;i<ysize;i++) fwrite(buf + i * wrap,1,xsize,f); fclose(f); } static void video_decode_example(const char *outfilename, const char *filename) { AVCodec *codec; AVCodecContext *c= NULL; int frame, got_picture, len; FILE *f; AVFrame *picture; uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; char buf[1024]; AVPacket avpkt; av_init_packet(&avpkt); /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */ memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE); printf("Decode video file %s to %s\n", filename, outfilename); /* find the mpeg1 video decoder */ codec = avcodec_find_decoder(AV_CODEC_ID_MPEG1VIDEO); if (!codec) { fprintf(stderr, "Codec not found\n"); exit(1); } c = avcodec_alloc_context3(codec); if(codec->capabilities&CODEC_CAP_TRUNCATED) c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */ /* For some codecs, such as msmpeg4 and mpeg4, width and height MUST be initialized there because this information is not available in the bitstream. */ /* open it */ if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "Could not open codec\n"); exit(1); } /* the codec gives us the frame size, in samples */ f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "Could not open %s\n", filename); exit(1); } picture = avcodec_alloc_frame(); if (!picture) { fprintf(stderr, "Could not allocate video frame\n"); exit(1); } frame = 0; for(;;) { avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); if (avpkt.size == 0) break; /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio) and this is the only method to use them because you cannot know the compressed data size before analysing it. BUT some other codecs (msmpeg4, mpeg4) are inherently frame based, so you must call them with all the data for one frame exactly. You must also initialize 'width' and 'height' before initializing them. */ /* NOTE2: some codecs allow the raw parameters (frame size, sample rate) to be changed at any frame. We handle this, so you should also take care of it */ /* here, we use a stream based decoder (mpeg1video), so we feed decoder and see if it could decode a frame */ avpkt.data = inbuf; while (avpkt.size > 0) { len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); if (len < 0) { fprintf(stderr, "Error while decoding frame %d\n", frame); exit(1); } if (got_picture) { printf("Saving frame %3d\n", frame); fflush(stdout); /* the picture is allocated by the decoder. no need to free it */ //snprintf(buf, sizeof(buf), outfilename, frame); pgm_save(picture->data[0], picture->linesize[0], c->width, c->height, buf); frame++; } avpkt.size -= len; avpkt.data += len; } } /* some codecs, such as MPEG, transmit the I and P frame with a latency of one frame. You must do the following to have a chance to get the last frame of the video */ avpkt.data = NULL; avpkt.size = 0; len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); if (got_picture) { printf("Saving last frame %3d\n", frame); fflush(stdout); /* the picture is allocated by the decoder. no need to free it */ //snprintf(buf, sizeof(buf), outfilename, frame); pgm_save(picture->data[0], picture->linesize[0], c->width, c->height, buf); frame++; } fclose(f); avcodec_close(c); av_free(c); avcodec_free_frame(&picture); printf("\n"); } int main(int argc, char **argv) { const char *output_type; /* register all the codecs */ avcodec_register_all(); /*if (argc < 2) { printf("usage: %s output_type\n" "API example program to decode/encode a media stream with libavcodec.\n" "This program generates a synthetic stream and encodes it to a file\n" "named test.h264, test.mp2 or test.mpg depending on output_type.\n" "The encoded stream is then decoded and written to a raw data output\n." "output_type must be choosen between 'h264', 'mp2', 'mpg'\n", argv[0]); return 1; } output_type = argv[1]; if (!strcmp(output_type, "h264")) { video_encode_example("test.h264", AV_CODEC_ID_H264); } else if (!strcmp(output_type, "mp2")) { audio_encode_example("test.mp2"); audio_decode_example("test.sw", "test.mp2"); } else if (!strcmp(output_type, "mpg")) { video_encode_example("test.mpg", AV_CODEC_ID_MPEG1VIDEO); video_decode_example("test%02d.pgm", "test.mpg"); } else { fprintf(stderr, "Invalid output type '%s', choose between 'h264', 'mp2', or 'mpg'\n", output_type); return 1; }*/ video_encode_example("test.h264", AV_CODEC_ID_H264); return 0; } #ifdef __cplusplus } #endif
http://blog.sina.com.cn/s/blog_51a320810100abuq.html
http://blog.sina.com.cn/s/blog_53b3dc830100llwg.html
- test_-_副本.png (281.3 KB)
- 下载次数: 11
发表评论
-
视频全程教你android ndk开发
2014-04-30 22:45 2147很多小伙伴觉得android ndk开发难配置,不清楚jav ... -
Qt Tcp示例
2013-03-22 16:25 1113http://blog.csdn.net/wyz365889/ ... -
Qt Grid布局
2013-03-20 22:59 1498布局效果: Qt代码实现: #include <QAp ... -
CDT JNI
2012-12-01 23:26 680http://www.blogjava.net/orangew ... -
C#语句收集
2012-11-14 14:12 941public static object GetPropert ... -
h.264
2012-05-30 00:03 1245http://www.elecfans.com/video/a ... -
wpf截取屏幕
2012-05-29 22:30 925private void button1_Click(obje ...
相关推荐
h264encode_src
关于Android平台的H.264 编码源代码的部分,感兴趣的朋友可以参考
用C语言写的H264编码和解码的源代码 解码效率还是很不错的 也可以自己参考代码 对自学有很大帮助的
配合这篇博客使用此资源https://blog.csdn.net/AIRKernel/article/details/121807558 将USB摄像头生成的YUV图像转换成H264文件输出,并可以在Ubuntu上播放此视频文件。完成对视频的压缩工作。
从V4L2获取视频数据.然后使用MediaCode编码
H264Android-264encode
h264_encode.rar
全志 a10开发板 专用的 H264 硬件 encoding 源码 H264 encoding sample source code using allwinner a10 hardware encoding function for development board
基于ARM6410开发板的H.264硬件编解码,利用开发板提供的MFC驱动-H.264 Hardware Encode and Decode program based on ARM6410,using MFC Driver
最新视频编码协议H.246的源代码,并配有实例,不可多得的好东西!仅供参考使用,希望能丰富你的知识
h264 多媒体技术 宏块级流程图MB-Encode
-C、C++方式实现,能和android界面完美融合。 -直接对原始的h264解码,对yuv编码。 -兼容上绝大多数android手机,2.3.3以上。 -稳定可靠,己在XX局视频会议等系统中使用了。
已产品化代码,用华恒S3C6410-R2开发板采集视频并压缩为H264格式,不带IDR帧,提供c源程序和MAKEFILE,头文件开发板配套资料有,使用时.c文件要改名为cam2fb.c
通过安卓底层的mediaCodec对音视频进行硬编码,并实现混合封装成MP4文件,和实现rtmp的视频流推流
hal_encode_decode_h264_h265.rar
H264 源代码,包含encode \decode
FFmpeg-X264-Encode-for-iOS, 利用FFmpeg x264将iOS摄像头实时视频流编码为h264文件
解码-编码-h264-演示 去跑* .go
github资源,ios8上使用videotoolbox h264编码 学习学习。。。