Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(422993)

Unified Diff: examples/encoder_example.c

Issue 547: Added filter prior to encoding giving BDR gains on certain sequences like KristenAndSara.
Patch Set: Added filter prior to encoding giving BDR gains on certain sequences like KristenAndSara. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Makefile.am ('k') | examples/prefilter.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/encoder_example.c
diff --git a/examples/encoder_example.c b/examples/encoder_example.c
index 51a91c20d2f1556c6912b5e25a70070594a1d34c..b540f617ec3d421e37dae386ec18358a82dc1832 100644
--- a/examples/encoder_example.c
+++ b/examples/encoder_example.c
@@ -35,6 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
#include <getopt.h>
#include "../src/logging.h"
#include "daala/daalaenc.h"
+#include "prefilter.h"
#if defined(_WIN32)
# include <fcntl.h>
# include <io.h>
@@ -62,7 +63,11 @@ struct av_input{
char video_chroma_type[16];
int video_nplanes;
daala_plane_info video_plane_info[OD_NPLANES_MAX];
- od_img video_img;
+ od_img video_buf1;
+ od_img video_buf2;
+ od_img video_filt;
+ od_img *video_img;
+ od_img *video_img_prev;
int video_cur_img;
};
@@ -239,20 +244,23 @@ static void id_y4m_file(av_input *avin, const char *file, FILE *test) {
avin->video_chroma_type);
exit(1);
}
- img = &avin->video_img;
+ img = avin->video_img;
img->nplanes = avin->video_nplanes;
img->width = avin->video_pic_w;
img->height = avin->video_pic_h;
for (pli = 0; pli < img->nplanes; pli++) {
od_img_plane *iplane;
+ int size;
iplane = img->planes + pli;
iplane->xdec = avin->video_plane_info[pli].xdec;
iplane->ydec = avin->video_plane_info[pli].ydec;
iplane->xstride = 1;
iplane->ystride = (avin->video_pic_w
+ (1 << iplane->xdec) - 1) >> iplane->xdec;
- iplane->data = (unsigned char *)_ogg_malloc(iplane->ystride*
- ((avin->video_pic_h + (1 << iplane->ydec) - 1) >> iplane->ydec));
+ size = iplane->ystride*((avin->video_pic_h + (1 << iplane->ydec) - 1)
+ >> iplane->ydec);
+ iplane->data = (unsigned char *)_ogg_malloc(size);
+ memset(iplane->data, pli ? 128 : 0, size);
}
}
@@ -291,9 +299,17 @@ static void id_file(av_input *avin, const char *file) {
}
}
+static od_img *get_next_video_img(av_input *avin) {
+ od_img *r = avin->video_img;
+ r = avin->video_img == &avin->video_buf1
+ ? &avin->video_buf2 : &avin->video_buf1;
+ avin->video_img_prev = r;
+ return avin->video_img;
+ }
+
int fetch_and_process_video(av_input *avin, ogg_page *page,
ogg_stream_state *vo, daala_enc_ctx *dd, int video_ready,
- int *limit, int *skip) {
+ int *limit, int skip, int prefilter, int input_q) {
ogg_packet op;
while (!video_ready) {
size_t ret;
@@ -321,7 +337,7 @@ int fetch_and_process_video(av_input *avin, ogg_page *page,
}
}
/*Read the frame data.*/
- img = &avin->video_img;
+ img = get_next_video_img(avin);
for (pli = 0; pli < img->nplanes; pli++) {
od_img_plane *iplane;
size_t plane_sz;
@@ -341,6 +357,20 @@ int fetch_and_process_video(av_input *avin, ogg_page *page,
(*skip)--;
continue;
}
+
+ if (prefilter) {
+ pre_filter(avin->video_filt.planes[0].data,
+ avin->video_filt.planes[1].data,
+ avin->video_filt.planes[2].data,
+ avin->video_img->planes[0].data,
+ avin->video_img->planes[1].data,
+ avin->video_img->planes[2].data,
+ avin->video_img_prev->planes[0].data,
+ avin->video_img_prev->planes[1].data,
+ avin->video_img_prev->planes[2].data,
+ avin->video_pic_w, avin->video_pic_h, input_q);
+ }
+
if (limit) {
last = (*limit) == 0;
(*limit)--;
@@ -355,12 +385,12 @@ int fetch_and_process_video(av_input *avin, ogg_page *page,
ogg_stream_packetin(vo, &op);
}
/*Submit the current frame for encoding.*/
- if (!last) daala_encode_img_in(dd, &avin->video_img, 0);
+ if (!last) daala_encode_img_in(dd, avin->video_img, 0);
}
return video_ready;
}
-static const char *OPTSTRING = "ho:k:v:V:s:S:l:z:";
+static const char *OPTSTRING = "ho:k:v:V:s:S:l:z:f:";
static const struct option OPTIONS[] = {
{ "help", no_argument, NULL, 'h' },
@@ -381,6 +411,7 @@ static const struct option OPTIONS[] = {
{ "mv-level-min", required_argument, NULL, 0 },
{ "mv-level-max", required_argument, NULL, 0 },
{ "version", no_argument, NULL, 0},
+ { "filter", no_argument, NULL, 'f' },
{ NULL, 0, NULL, 0 }
};
@@ -424,6 +455,8 @@ static void usage(void) {
" --mv-level-max <n> Maximum motion vectors level between\n"
" 0 and 6 (default).\n"
" --version Displays version information."
+ " 0 and 4 (default).\n"
+ " -f --filter Enable pre encode filter.\n"
" encoder_example accepts only uncompressed YUV4MPEG2 video.\n\n");
exit(1);
}
@@ -453,6 +486,7 @@ int main(int argc, char **argv) {
int video_keyframe_rate;
int video_ready;
int pli;
+ int prefilter;
int fixedserial;
unsigned int serial;
int skip;
@@ -483,6 +517,7 @@ int main(int argc, char **argv) {
video_keyframe_rate = 256;
video_r = -1;
video_bytesout = 0;
+ prefilter = 0;
fixedserial = 0;
skip = 0;
limit = -1;
@@ -547,6 +582,8 @@ int main(int argc, char **argv) {
"Illegal number of frames to skip (must be non-negative)\n");
exit(1);
}
+ case 'f': {
+ prefilter = 1;
break;
}
case 'l': {
@@ -627,12 +664,37 @@ int main(int argc, char **argv) {
default: usage(); break;
}
}
+ avin.video_img = &avin.video_buf1;
+
/*Assume anything following the options must be a file name.*/
for (; optind < argc; optind++) id_file(&avin, argv[optind]);
if (!avin.has_video) {
fprintf(stderr, "No video files submitted for compression.\n");
exit(1);
}
+
+ /* Alloc space for storing the previous frame */
+ avin.video_buf2 = avin.video_buf1;
+ for(pli=0;pli<avin.video_buf2.nplanes;pli++){
+ od_img_plane *iplane;
+ int size;
+ iplane=avin.video_buf2.planes+pli;
+ size=iplane->ystride*((avin.video_pic_h+(1<<iplane->ydec)-1)>>iplane->ydec);
+ iplane->data=_ogg_malloc(size);
+ memset(iplane->data, pli ? 128 : 0, size);
+ }
+
+ /* Alloc space for storing a temporally filtered frame */
+ avin.video_filt = avin.video_buf1;
+ for(pli=0;pli<avin.video_filt.nplanes;pli++){
+ od_img_plane *iplane;
+ int size;
+ iplane=avin.video_filt.planes+pli;
+ size=iplane->ystride*((avin.video_pic_h+(1<<iplane->ydec)-1)>>iplane->ydec);
+ iplane->data=_ogg_malloc(size);
+ memset(iplane->data, pli ? 128 : 0, size);
+ }
+
if (!fixedserial) {
srand(time(NULL));
serial = rand();
@@ -720,6 +782,9 @@ int main(int argc, char **argv) {
size_t bytes_written;
video_ready = fetch_and_process_video(&avin, &video_page, &vo,
dd, video_ready, limit >= 0 ? &limit : NULL, skip > 0 ? &skip : NULL);
+ video_ready = fetch_and_process_video(&avin, &video_page,
+ &vo, dd, video_ready, limit >= 0 ? &limit : NULL,
+ skip > 0 ? &skip : NULL, prefilter, input_q);
/*TODO: Fetch the next video page.*/
/*If no more pages are available, we've hit the end of the stream.*/
if (!video_ready) break;
@@ -755,8 +820,9 @@ int main(int argc, char **argv) {
ogg_stream_clear(&vo);
daala_encode_free(dd);
daala_comment_clear(&dc);
- for (pli = 0; pli < avin.video_img.nplanes; pli++) {
- _ogg_free(avin.video_img.planes[pli].data);
+ for(pli = 0; pli < avin.video_buf1.nplanes; pli++) {
+ _ogg_free(avin.video_buf1.planes[pli].data);
+ _ogg_free(avin.video_buf2.planes[pli].data);
}
if (outfile != NULL && outfile != stdout) fclose(outfile);
fprintf(stderr, "\r \ndone.\n\r");
« no previous file with comments | « Makefile.am ('k') | examples/prefilter.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld