Home | History | Annotate | Download | only in examples
      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.
      9 
     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
     13 
     14 
     15 Usage
     16 -----
     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:
     20 
     21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
     22 if(argc!=6)
     23     die("Usage: %s <width> <height> <infile> <outfile> <frame>\n",
     24         argv[0]);
     25 
     26     update_frame_num = atoi(argv[5]);
     27     if(!update_frame_num)
     28         die("Couldn't parse frame number '%s'\n", argv[5]);
     29 
     30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE
     31 
     32 
     33 Extra Variables
     34 ---------------
     35 This example maintains the frame number passed on the command line
     36 in the `update_frame_num` variable:
     37 
     38 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TWOPASS_VARS
     39 int                  update_frame_num = 0;
     40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TWOPASS_VARS
     41 
     42 
     43 Configuration
     44 -------------
     45 
     46 The reference frame is updated on the frame specified on the command
     47 line.
     48 
     49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENCODE_FRAME
     50 frame_avail = read_frame(infile, &raw);
     51 
     52 if(frame_cnt + 1 == update_frame_num) {
     53     vpx_ref_frame_t ref;
     54 
     55     ref.frame_type = VP8_LAST_FRAME;
     56     ref.img        = raw;
     57 
     58     if(vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref))
     59         die_codec(&codec, "Failed to set reference frame");
     60 }
     61 
     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
     66 
     67 
     68 Observing The Effects
     69 ---------------------
     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.
     74