Lines 168-173
extern "C" {
Link Here
|
168 |
#endif |
168 |
#endif |
169 |
#endif |
169 |
#endif |
170 |
|
170 |
|
|
|
171 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
172 |
# define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER |
173 |
#endif |
174 |
|
175 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
176 |
# define AV_PKT_FLAG_KEY PKT_FLAG_KEY |
177 |
#endif |
178 |
|
171 |
#if USE_AV_INTERRUPT_CALLBACK |
179 |
#if USE_AV_INTERRUPT_CALLBACK |
172 |
#define LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS 30000 |
180 |
#define LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS 30000 |
173 |
#define LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS 30000 |
181 |
#define LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS 30000 |
Lines 1554-1560
static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc,
Link Here
|
1554 |
// some formats want stream headers to be seperate |
1562 |
// some formats want stream headers to be seperate |
1555 |
if(oc->oformat->flags & AVFMT_GLOBALHEADER) |
1563 |
if(oc->oformat->flags & AVFMT_GLOBALHEADER) |
1556 |
{ |
1564 |
{ |
1557 |
c->flags |= CODEC_FLAG_GLOBAL_HEADER; |
1565 |
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
1558 |
} |
1566 |
} |
1559 |
#endif |
1567 |
#endif |
1560 |
|
1568 |
|
Lines 1582-1604
static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st,
Link Here
|
1582 |
#endif |
1590 |
#endif |
1583 |
int ret = OPENCV_NO_FRAMES_WRITTEN_CODE; |
1591 |
int ret = OPENCV_NO_FRAMES_WRITTEN_CODE; |
1584 |
|
1592 |
|
|
|
1593 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
1585 |
if (oc->oformat->flags & AVFMT_RAWPICTURE) { |
1594 |
if (oc->oformat->flags & AVFMT_RAWPICTURE) { |
1586 |
/* raw video case. The API will change slightly in the near |
1595 |
/* raw video case. The API will change slightly in the near |
1587 |
futur for that */ |
1596 |
futur for that */ |
1588 |
AVPacket pkt; |
1597 |
AVPacket pkt; |
1589 |
av_init_packet(&pkt); |
1598 |
av_init_packet(&pkt); |
1590 |
|
1599 |
|
1591 |
#ifndef PKT_FLAG_KEY |
1600 |
pkt.flags |= AV_PKT_FLAG_KEY; |
1592 |
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY |
|
|
1593 |
#endif |
1594 |
|
1595 |
pkt.flags |= PKT_FLAG_KEY; |
1596 |
pkt.stream_index= video_st->index; |
1601 |
pkt.stream_index= video_st->index; |
1597 |
pkt.data= (uint8_t *)picture; |
1602 |
pkt.data= (uint8_t *)picture; |
1598 |
pkt.size= sizeof(AVPicture); |
1603 |
pkt.size= sizeof(AVPicture); |
1599 |
|
1604 |
|
1600 |
ret = av_write_frame(oc, &pkt); |
1605 |
ret = av_write_frame(oc, &pkt); |
1601 |
} else { |
1606 |
} else { |
|
|
1607 |
#endif |
1602 |
/* encode the image */ |
1608 |
/* encode the image */ |
1603 |
AVPacket pkt; |
1609 |
AVPacket pkt; |
1604 |
av_init_packet(&pkt); |
1610 |
av_init_packet(&pkt); |
Lines 1633-1639
static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st,
Link Here
|
1633 |
pkt.pts = c->coded_frame->pts; |
1639 |
pkt.pts = c->coded_frame->pts; |
1634 |
#endif |
1640 |
#endif |
1635 |
if(c->coded_frame->key_frame) |
1641 |
if(c->coded_frame->key_frame) |
1636 |
pkt.flags |= PKT_FLAG_KEY; |
1642 |
pkt.flags |= AV_PKT_FLAG_KEY; |
1637 |
pkt.stream_index= video_st->index; |
1643 |
pkt.stream_index= video_st->index; |
1638 |
pkt.data= outbuf; |
1644 |
pkt.data= outbuf; |
1639 |
pkt.size= out_size; |
1645 |
pkt.size= out_size; |
Lines 1642-1648
static int icv_av_write_frame_FFMPEG( AVFormatContext * oc, AVStream * video_st,
Link Here
|
1642 |
ret = av_write_frame(oc, &pkt); |
1648 |
ret = av_write_frame(oc, &pkt); |
1643 |
} |
1649 |
} |
1644 |
#endif |
1650 |
#endif |
|
|
1651 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
1645 |
} |
1652 |
} |
|
|
1653 |
#endif |
1646 |
return ret; |
1654 |
return ret; |
1647 |
} |
1655 |
} |
1648 |
|
1656 |
|
Lines 1756-1770
void CvVideoWriter_FFMPEG::close()
Link Here
|
1756 |
/* write the trailer, if any */ |
1764 |
/* write the trailer, if any */ |
1757 |
if(ok && oc) |
1765 |
if(ok && oc) |
1758 |
{ |
1766 |
{ |
|
|
1767 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
1759 |
if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 ) |
1768 |
if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 ) |
1760 |
{ |
1769 |
{ |
|
|
1770 |
#endif |
1761 |
for(;;) |
1771 |
for(;;) |
1762 |
{ |
1772 |
{ |
1763 |
int ret = icv_av_write_frame_FFMPEG( oc, video_st, outbuf, outbuf_size, NULL); |
1773 |
int ret = icv_av_write_frame_FFMPEG( oc, video_st, outbuf, outbuf_size, NULL); |
1764 |
if( ret == OPENCV_NO_FRAMES_WRITTEN_CODE || ret < 0 ) |
1774 |
if( ret == OPENCV_NO_FRAMES_WRITTEN_CODE || ret < 0 ) |
1765 |
break; |
1775 |
break; |
1766 |
} |
1776 |
} |
|
|
1777 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
1767 |
} |
1778 |
} |
|
|
1779 |
#endif |
1768 |
av_write_trailer(oc); |
1780 |
av_write_trailer(oc); |
1769 |
} |
1781 |
} |
1770 |
|
1782 |
|
Lines 2055-2066
bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc,
Link Here
|
2055 |
|
2067 |
|
2056 |
outbuf = NULL; |
2068 |
outbuf = NULL; |
2057 |
|
2069 |
|
|
|
2070 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
2058 |
if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { |
2071 |
if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { |
|
|
2072 |
#endif |
2059 |
/* allocate output buffer */ |
2073 |
/* allocate output buffer */ |
2060 |
/* assume we will never get codec output with more than 4 bytes per pixel... */ |
2074 |
/* assume we will never get codec output with more than 4 bytes per pixel... */ |
2061 |
outbuf_size = width*height*4; |
2075 |
outbuf_size = width*height*4; |
2062 |
outbuf = (uint8_t *) av_malloc(outbuf_size); |
2076 |
outbuf = (uint8_t *) av_malloc(outbuf_size); |
|
|
2077 |
#if LIBAVFORMAT_VERSION_MAJOR < 58 |
2063 |
} |
2078 |
} |
|
|
2079 |
#endif |
2064 |
|
2080 |
|
2065 |
bool need_color_convert; |
2081 |
bool need_color_convert; |
2066 |
need_color_convert = (c->pix_fmt != input_pix_fmt); |
2082 |
need_color_convert = (c->pix_fmt != input_pix_fmt); |
Lines 2360-2366
AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CV_CODEC
Link Here
|
2360 |
// some formats want stream headers to be seperate |
2376 |
// some formats want stream headers to be seperate |
2361 |
if (oc->oformat->flags & AVFMT_GLOBALHEADER) |
2377 |
if (oc->oformat->flags & AVFMT_GLOBALHEADER) |
2362 |
{ |
2378 |
{ |
2363 |
c->flags |= CODEC_FLAG_GLOBAL_HEADER; |
2379 |
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
2364 |
} |
2380 |
} |
2365 |
#endif |
2381 |
#endif |
2366 |
|
2382 |
|
Lines 2461-2467
void OutputMediaStream_FFMPEG::write(unsigned char* data, int size, int keyFrame
Link Here
|
2461 |
av_init_packet(&pkt); |
2477 |
av_init_packet(&pkt); |
2462 |
|
2478 |
|
2463 |
if (keyFrame) |
2479 |
if (keyFrame) |
2464 |
pkt.flags |= PKT_FLAG_KEY; |
2480 |
pkt.flags |= AV_PKT_FLAG_KEY; |
2465 |
|
2481 |
|
2466 |
pkt.stream_index = video_st_->index; |
2482 |
pkt.stream_index = video_st_->index; |
2467 |
pkt.data = data; |
2483 |
pkt.data = data; |