1 @TEMPLATE encoder_tmpl.c
2 VP8 Set Reference Frame
3 =======================
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
5 This is an example demonstrating how to overwrite the VP8 encoder's
6 internal reference frame. In the sample we set the last frame to the
7 current frame. If this is done at a cut scene it will avoid a keyframe.
8 This technique could be used to bounce between two cameras.
10 Note that the decoder would also have to set the reference frame to the
11 same value on the same frame, or the video will become corrupt.
12 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INTRODUCTION
17 This example adds a single argument to the `simple_encoder` example,
18 which specifies the frame number to update the reference frame on.
19 The parameter is parsed as follows:
21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
23 die("Usage: %s <width> <height> <infile> <outfile> <frame>\n",
26 update_frame_num = atoi(argv[5]);
28 die("Couldn't parse frame number '%s'\n", argv[5]);
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
35 This example maintains the frame number passed on the command line
36 in the `update_frame_num` variable:
38 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TWOPASS_VARS
39 int update_frame_num = 0;
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TWOPASS_VARS
46 The reference frame is updated on the frame specified on the command
49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENCODE_FRAME
50 frame_avail = read_frame(infile, &raw);
52 if(frame_cnt + 1 == update_frame_num) {
55 ref.frame_type = VP8_LAST_FRAME;
58 if(vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref))
59 die_codec(&codec, "Failed to set reference frame");
62 if(vpx_codec_encode(&codec, frame_avail? &raw : NULL, frame_cnt,
63 1, flags, VPX_DL_REALTIME))
64 die_codec(&codec, "Failed to encode frame");
65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENCODE_FRAME
70 Use the `simple_encoder` example to encode a sample with a cut scene.
71 Determine the frame number of the cut scene by looking for a generated
72 key-frame (indicated by a 'K'). Supply that frame number as an argument
73 to this example, and observe that no key-frame is generated.