1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
require 'formula'
class Phash < Formula
url 'http://www.phash.org/releases/pHash-0.9.4.tar.gz'
homepage 'http://www.phash.org/'
sha1 '9710b8a1d4d24e7fc3ac43c33eac8e89d9e727d7'
depends_on 'cimg' unless ARGV.include? "--disable-image-hash" and ARGV.include? "--disable-video-hash"
depends_on 'ffmpeg' unless ARGV.include? "--disable-video-hash"
unless ARGV.include? "--disable-audio-hash"
depends_on 'libsndfile'
depends_on 'libsamplerate'
depends_on 'mpg123'
end
def options
[
["--disable-image-hash", "Disable image hash"],
["--disable-video-hash", "Disable video hash"],
["--disable-audio-hash", "Disable audio hash"]
]
end
# fix compilation on ffmpeg <= 0.7
# source: https://launchpad.net/ubuntu/+source/libphash/0.9.4-1.2
def patches
DATA
end
def install
args = ["--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--enable-shared"]
# disable specific hashes if specified as an option
args << "--disable-image-hash" if ARGV.include? "--disable-image-hash"
args << "--disable-video-hash" if ARGV.include? "--disable-video-hash"
args << "--disable-audio-hash" if ARGV.include? "--disable-audio-hash"
system "./configure", *args
system "make install"
end
end
__END__
--- a/src/cimgffmpeg.cpp
+++ b/src/cimgffmpeg.cpp
@@ -67,7 +67,7 @@
// Find the video stream
for(i=0; i<st_info->pFormatCtx->nb_streams; i++)
{
- if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
+ if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
st_info->videoStream=i;
break;
@@ -123,6 +123,10 @@
int size = 0;
AVPacket packet;
+
+ AVPacket avpacket;
+ av_init_packet(&avpacket);
+
int result = 1;
CImg<uint8_t> next_image;
SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
@@ -131,7 +135,10 @@
if (result < 0)
break;
if(packet.stream_index==st_info->videoStream) {
- avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
+ avpacket.data = packet.data;
+ avpacket.size = packet.size;
+ avpacket.flags = AV_PKT_FLAG_KEY;
+ avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &avpacket);
if(frameFinished) {
if (st_info->current_index == st_info->next_index){
st_info->next_index += st_info->step;
@@ -213,7 +220,7 @@
// Find the video stream
for(i=0; i< st_info->pFormatCtx->nb_streams; i++)
{
- if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
+ if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
st_info->videoStream=i;
break;
@@ -268,6 +275,10 @@
int frameFinished;
int size = 0;
AVPacket packet;
+
+ AVPacket avpacket;
+ av_init_packet(&avpacket);
+
int result = 1;
CImg<uint8_t> next_image;
SwsContext *c = sws_getContext(st_info->pCodecCtx->width, st_info->pCodecCtx->height, st_info->pCodecCtx->pix_fmt, st_info->width, st_info->height, ffmpeg_pixfmt , SWS_BICUBIC, NULL, NULL, NULL);
@@ -279,8 +290,10 @@
break;
if(packet.stream_index == st_info->videoStream) {
- avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
- packet.data,packet.size);
+ avpacket.data = packet.data;
+ avpacket.size = packet.size;
+ avpacket.flags = AV_PKT_FLAG_KEY;
+ avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &avpacket);
if(frameFinished) {
if (st_info->current_index == st_info->next_index)
@@ -365,7 +378,7 @@
int videoStream=-1;
for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
{
- if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
+ if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoStream=i;
break;
@@ -407,7 +420,7 @@
int videoStream=-1;
for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
{
- if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
+ if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoStream=i;
break;
|