目录
1 所需软件、源码及下载地址----------------------------------------------------------------------------------------------------------------------------------- 1
2安装软件及编译------------------------------------------------------------------------------------------------------------------------------------------------------ 1
2.1 安装Windows版的VLC播放器(勾选上插件,默认已经勾选)--------------------------------------------------------------------- 1
2.2 编译live555-------------------------------------------------------------------------------------------------------------------------------------------------- 1
2.3 编译ffmpeg-------------------------------------------------------------------------------------------------------------------------------------------------- 1
2.3.1 编译yasm------------------------------------------------------------------------------------------------------------------------------------------- 2
2.3.2 编译v4l-utils--------------------------------------------------------------------------------------------------------------------------------------- 2
2.3.3 编译libx264---------------------------------------------------------------------------------------------------------------------------------------- 2
2.3.4 编译ffmpeg---------------------------------------------------------------------------------------------------------------------------------------- 2
3服务器程序------------------------------------------------------------------------------------------------------------------------------------------------------------- 2
3.1 源码------------------------------------------------------------------------------------------------------------------------------------------------------------- 2
3.2 编译步骤------------------------------------------------------------------------------------------------------------------------------------------------------ 6
4 html页面源码--------------------------------------------------------------------------------------------------------------------------------------------------------- 6
5 运行---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7
QQ:809205580
博客地址: http://blog.csdn.net/zjhsucceed_329
QCW(Qt自定义控件)下载地址: https://sourceforge.net/projects/qcw/files/?source=navbar
VLC播放器:http://www.videolan.org/
live555-latest.tar.gz:http://www.live555.com/liveMedia/public/
ffmpeg:http://ffmpeg.org/olddownload.html、
yasm:http://yasm.tortall.net/Download.html
v4l-utils:http://www.linuxtv.org/downloads/v4l-utils/
libx264:ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
root@zjh:/home/work#tar zxvf live555-latest.tar.gz
root@zjh:/home/work#cd live
root@zjh:/home/work/live#./genMakefiles linux
root@zjh:/home/work/live#make
root@zjh:/home/work/live#ls mediaServer/
live555MediaServer
编译说明文档下载地址:http://yunpan.cn/QD8RRSPCIV4aS
encoding.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
intstop = 0;
constchar *FIFO = "test.264";
/*
* Video encoding example
*/
staticvoid 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);
if (!codec)
{
fprintf(stderr, "Codec notfound\n");
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c)
{
fprintf(stderr, "Could notallocate video codec context\n");
exit(1);
}
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
/* frames per second */
c->time_base= (AVRational){1,25};
c->gop_size = 10; /* emit one intraframe 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 opencodec\n");
exit(1);
}
f = fopen(filename, "w");
if (!f)
{
fprintf(stderr, "Could not open%s\n", filename);
exit(1);
}
frame = avcodec_alloc_frame();
if (!frame)
{
fprintf(stderr, "Could notallocate 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 meansand av_image_alloc() is
* just the most convenient way ifav_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 notallocate raw picture buffer\n");
exit(1);
}
/* encode time second of video */
i = 0;
while (!stop)
{
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by theencoder
pkt.size = 0;
fflush(stdout);
/* prepare a dummy image */
/* Y */
for(y=0;y
for(x=0;x
frame->data[0][y *frame->linesize[0] + x] = x + y + i * 3;
}
}
/* Cb and Cr */
for(y=0;y
for(x=0;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, "Errorencoding 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);
}
i++;
}
/* 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, "Errorencoding 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 realmpeg 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");
}
voidhandle(int sig)
{
if (sig == SIGINT)
stop = 1;
}
intmain(int argc, char **argv)
{
signal(SIGINT, handle);
signal(SIGPIPE, SIG_IGN);
/* register all the codecs */
avcodec_register_all();
if (mkfifo(FIFO, 0644)< 0)
{
if (EEXIST != errno)
{
perror("mkfifo");
exit(1);
}
}
video_encode_example(FIFO,AV_CODEC_ID_H264);
return 0;
}
将encoding.c拷贝到ffmpeg源码目录的ffmpeg-1.1/doc/examples目录下,进入该目录,修改Makefile
EXAMPLES= decoding_encoding \
demuxing \
filtering_video \
filtering_audio \
metadata \
muxing \
resampling_audio \
scaling_video \
encoding
然后执行make将生成可执行文件encoding
vod.html
var itemId = 0;
function getVLC(name)
{
if(window.document[name])
{
returnwindow.document[name];
}
if(navigator.appName.indexOf("Microsoft Internet")== -1)
{
if (document.embeds&& document.embeds[name])
return document.embeds[name];
}
else
{
returndocument.getElementById(name);
}
}
function doAddPlaylist()
{
var vlc =getVLC("vlc");
itemId=vlc.playlist.add("rtsp://192.168.230.141/test.264");
document.getElementById("btn_stop").disabled= false;
}
width="352" height="288" id="vlc" events="true"> type="application/x-vlc-plugin" version="videolan.vlcplugin.2" width="352" height="288" name="vlc">