Revision d74bb0e5

View differences:

Makefile
37 37
LDLIBS = -ltrading -lcb -ltopman
38 38
endif
39 39

  
40
OBJS = dumbstreamer.o streaming.o output.o net_helpers.o input.o out-stream.o
40
OBJS = dumbstreamer.o streaming.o output.o net_helpers.o input.o
41 41
ifdef THREADS
42 42
OBJS += loop-mt.o
43 43
CFLAGS += -pthread
......
48 48

  
49 49
ifdef FFDIR
50 50
FFSRC ?= $(FFDIR)
51
OBJS += Chunkiser/input-stream-avs.o
51
OBJS += Chunkiser/input-stream-avs.o out-stream-avf.o
52 52
LDFLAGS += -L$(FFDIR)/libavcodec -L$(FFDIR)/libavformat -L$(FFDIR)/libavutil
53 53
LDLIBS += -lavformat -lavcodec -lavutil
54 54
LDLIBS += -lm
55 55
LDLIBS += $(call ld-option, -lz)
56 56
LDLIBS += $(call ld-option, -lbz2)
57 57
else
58
OBJS += input-stream-dummy.o
58
OBJS += input-stream-dummy.o out-stream.o
59 59
endif
60 60

  
61 61
EXECTARGET = dumbstreamer
......
71 71
$(EXECTARGET): $(OBJS) $(GRAPES)/som/Tests/net_helper-ml.o $(GRAPES)/som/Tests/ml_helpers.o
72 72
endif
73 73

  
74
Chunkiser/input-stream-avs.o: CPPFLAGS += -I$(FFSRC) 
74
out-stream-avf.o Chunkiser/input-stream-avs.o: CPPFLAGS += -I$(FFSRC) 
75 75

  
76 76
GRAPES:
77 77
	git clone http://www.disi.unitn.it/~abeni/PublicGits/GRAPES.git
out-stream-avf.c
1
#include <libavformat/avformat.h>
2
#include <stdio.h>
3

  
4
#include "out-stream.h"
5
#include "dbg.h"
6

  
7
void chunk_write(int id, const uint8_t *data, int size)
8
{
9
  static AVFormatContext *outctx;
10
  const int header_size = 1 + 2 + 2 + 2 + 2 + 1; // 1 Frame type + 2 width + 2 height + 2 frame rate num + 2 frame rate den + 1 number of frames
11
  int frames, i;
12

  
13
  if (data[0] != 1) {
14
    fprintf(stderr, "Error! Non video chunk: %x!!!\n", data[0]);
15
    return;
16
  }
17
  if (outctx == NULL) {
18
    int width, height, frame_rate_n, frame_rate_d;
19
    AVOutputFormat *outfmt;
20
    AVCodecContext *c;
21

  
22
    av_register_all();
23

  
24
    width = data[1] << 8 | data[2];
25
    height = data[3] << 8 | data[4];
26
    frame_rate_n = data[5] << 8 | data[6];
27
    frame_rate_d = data[7] << 8 | data[8];
28
    dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
29

  
30
    outfmt = av_guess_format("nut", NULL, NULL);
31
    outctx = avformat_alloc_context();
32
    if (outctx == NULL) {
33
      return;
34
    }
35
    outctx->oformat = outfmt;
36
    snprintf(outctx->filename, sizeof(outctx->filename), "%s", "out.nut");
37
    av_new_stream(outctx, 0);
38
    c = outctx->streams[0]->codec;
39
    c->codec_id = CODEC_ID_MPEG4;	// FIXME!!!
40
    c->codec_type = CODEC_TYPE_VIDEO;
41
    c->width = width;
42
    c->height= height;
43
    c->time_base.den = frame_rate_n;
44
    c->time_base.num = frame_rate_d;
45
    outctx->streams[0]->avg_frame_rate.num = frame_rate_n;
46
    outctx->streams[0]->avg_frame_rate.den = frame_rate_d;
47
    c->pix_fmt = PIX_FMT_YUV420P;
48
    av_set_parameters(outctx, NULL);
49
    dump_format(outctx, 0, "out.nut", 1);
50
    url_fopen(&outctx->pb, "out.nut", URL_WRONLY);
51
    av_write_header(outctx);
52
  }
53

  
54
  frames = data[9];
55
  for (i = 0; i < frames; i++) {
56
    AVPacket pkt;
57

  
58
    dprintf("Frame %d has size %d\n", i, data[10 + 2 * i] << 8 | data[11 + 2 * i]);
59
    av_init_packet(&pkt);
60
    pkt.stream_index = 0;	// FIXME!
61
    pkt.pts = AV_NOPTS_VALUE;	// FIXME!
62
    pkt.data = data + header_size + frames * 2;
63
    pkt.size = data[10 + 2 * i] << 8 | data[11 + 2 * i];
64
    av_interleaved_write_frame(outctx, &pkt);
65
  }
66
}

Also available in: Unified diff