Skip to content

Commit

Permalink
fix read_data_from_file function which produce errors to get frames f…
Browse files Browse the repository at this point in the history
…rom files with moov atom at the end, or to get last frames from videos
  • Loading branch information
wandenberg committed Aug 10, 2013
1 parent f696121 commit bd4a77a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/ngx_http_video_thumbextractor_module_utils.c
Expand Up @@ -71,10 +71,8 @@ int ngx_http_video_thumbextractor_read_data_from_file(void *opaque, uint8_t *buf
fseek(info->fd, info->offset, SEEK_SET);
}

if (fread(buf, sizeof(uint8_t), buf_len, info->fd) == (u_int) buf_len) {
return buf_len;
}
return -1;
int r = fread(buf, sizeof(uint8_t), buf_len, info->fd);
return (r == -1) ? AVERROR(errno) : r;
}


Expand Down
Binary file added test/test_video_moov_atom_at_end.mp4
Binary file not shown.
22 changes: 20 additions & 2 deletions test/video_thumbextractor_spec.rb
Expand Up @@ -11,6 +11,15 @@
end
end

context "when the moov atom is at the end of the file" do
it "should return a image equals to when it is at the beginning" do
nginx_run_server do
image_1 = image('/test_video_moov_atom_at_end.mp4?second=2')
image_1.should eq(image('/test_video.mp4?second=2'))
end
end
end

context "when the video does not exists" do
it "should return a 404" do
nginx_run_server do
Expand All @@ -37,9 +46,9 @@
end

context "and using exact time" do
it "should return a 404" do
it "should return a 200" do
nginx_run_server(:only_keyframe => "off") do
image('/test_video.mp4?second=12', {}, "404").should be_nil
image('/test_video.mp4?second=12', {}, "200").should_not be_nil
end
end
end
Expand All @@ -56,6 +65,15 @@
end
end

context "when the moov atom is at the end of the file" do
it "should return a image equals to when it is at the beginning" do
nginx_run_server do
image_1 = image('/test_video_moov_atom_at_end.mp4?second=2', {"Host" => 'proxied_server'})
image_1.should eq(image('/test_video.mp4?second=2', {"Host" => 'proxied_server'}))
end
end
end

it "should return an image equals to a an image from the real video file" do
nginx_run_server do
image_1 = image('/test_video.mp4?second=2', {"Host" => 'proxied_server'})
Expand Down

0 comments on commit bd4a77a

Please sign in to comment.