Revision 421c2dc2 out-stream-avf.c

View differences:

out-stream-avf.c
9 9

  
10 10
#include "out-stream.h"
11 11
#include "dbg.h"
12
#include "payload.h"
12 13

  
13 14
static const char *output_format = "nut";
14 15
static const char *output_file = "/dev/stdout";
15 16

  
16 17
static int64_t prev_pts, prev_dts;
17 18

  
18
#define VIDEO_PAYLOAD_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
19
#define FRAME_HEADER_SIZE (3 + 4 + 1)
20

  
21
static void frame_header_parse(const uint8_t *data, int *size, int32_t *pts, int32_t *dts)
22
{
23
  int i;
24

  
25
  *size = 0;
26
  for (i = 0; i < 3; i++) {
27
    *size = *size << 8;
28
    *size |= data[i];
29
  }
30
  *pts = 0;
31
  for (i = 0; i < 4; i++) {
32
    *pts = *pts << 8;
33
    *pts |= data[3 + i];
34
  }
35
  *dts = *pts - data[7];
36
}
37

  
38 19
static enum CodecID libav_codec_id(uint8_t mytype)
39 20
{
40 21
  switch (mytype) {
......
76 57
  AVCodecContext *c;
77 58
  AVOutputFormat *outfmt;
78 59
  int width, height, frame_rate_n, frame_rate_d;
60
  uint8_t codec;
79 61

  
80 62
  av_register_all();
81 63

  
82
  width = data[1] << 8 | data[2];
83
  height = data[3] << 8 | data[4];
84
  frame_rate_n = data[5] << 8 | data[6];
85
  frame_rate_d = data[7] << 8 | data[8];
64
  payload_header_parse(data, &codec, &width, &height, &frame_rate_n, &frame_rate_d);
86 65
  dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
87

  
88 66
  outfmt = av_guess_format(output_format, NULL, NULL);
89 67
  of = avformat_alloc_context();
90 68
  if (of == NULL) {
......
93 71
  of->oformat = outfmt;
94 72
  av_new_stream(of, 0);
95 73
  c = of->streams[0]->codec;
96
  c->codec_id = libav_codec_id(data[0]);
74
  c->codec_id = libav_codec_id(codec);
97 75
  c->codec_type = CODEC_TYPE_VIDEO;
98 76
  c->width = width;
99 77
  c->height= height;

Also available in: Unified diff