Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ffmpeg-doc / usr / share / doc / ffmpeg-doc / api / scaling__video_8c_source.html
Size: Mime:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FFmpeg: doc/examples/scaling_video.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">FFmpeg
   &#160;<span id="projectnumber">2.7.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">doc/examples/scaling_video.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="scaling__video_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2012 Stefano Sabatini</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a name="l00005"></a>00005 <span class="comment"> * of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<a name="l00006"></a>00006 <span class="comment"> * in the Software without restriction, including without limitation the rights</span>
<a name="l00007"></a>00007 <span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<a name="l00008"></a>00008 <span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span>
<a name="l00009"></a>00009 <span class="comment"> * furnished to do so, subject to the following conditions:</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
<a name="l00012"></a>00012 <span class="comment"> * all copies or substantial portions of the Software.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00015"></a>00015 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
<a name="l00017"></a>00017 <span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00019"></a>00019 <span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<a name="l00020"></a>00020 <span class="comment"> * THE SOFTWARE.</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">/**</span>
<a name="l00024"></a>00024 <span class="comment"> * @file</span>
<a name="l00025"></a>00025 <span class="comment"> * libswscale API use example.</span>
<a name="l00026"></a>00026 <span class="comment"> * @example scaling_video.c</span>
<a name="l00027"></a>00027 <span class="comment"> */</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;<a class="code" href="imgutils_8h.html" title="misc image utilities">libavutil/imgutils.h</a>&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;<a class="code" href="parseutils_8h.html" title="misc parsing utilities">libavutil/parseutils.h</a>&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;<a class="code" href="swscale_8h.html" title="external API header">libswscale/swscale.h</a>&gt;</span>
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="scaling__video_8c.html#aa900f1f8fe783be800a3caea221d8917">00033</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="scaling__video_8c.html#aa900f1f8fe783be800a3caea221d8917">fill_yuv_image</a>(uint8_t *data[4], <span class="keywordtype">int</span> linesize[4],
<a name="l00034"></a>00034                            <span class="keywordtype">int</span> <a class="code" href="demuxing__decoding_8c.html#a2474a5474cbff19523a51eb1de01cda4">width</a>, <span class="keywordtype">int</span> <a class="code" href="demuxing__decoding_8c.html#ad12fc34ce789bce6c8a05d8a17138534">height</a>, <span class="keywordtype">int</span> frame_index)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036     <span class="keywordtype">int</span> x, y;
<a name="l00037"></a>00037 
<a name="l00038"></a>00038     <span class="comment">/* Y */</span>
<a name="l00039"></a>00039     <span class="keywordflow">for</span> (y = 0; y &lt; <a class="code" href="demuxing__decoding_8c.html#ad12fc34ce789bce6c8a05d8a17138534">height</a>; y++)
<a name="l00040"></a>00040         <span class="keywordflow">for</span> (x = 0; x &lt; <a class="code" href="demuxing__decoding_8c.html#a2474a5474cbff19523a51eb1de01cda4">width</a>; x++)
<a name="l00041"></a>00041             data[0][y * linesize[0] + x] = x + y + frame_index * 3;
<a name="l00042"></a>00042 
<a name="l00043"></a>00043     <span class="comment">/* Cb and Cr */</span>
<a name="l00044"></a>00044     <span class="keywordflow">for</span> (y = 0; y &lt; height / 2; y++) {
<a name="l00045"></a>00045         <span class="keywordflow">for</span> (x = 0; x &lt; width / 2; x++) {
<a name="l00046"></a>00046             data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
<a name="l00047"></a>00047             data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049     }
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a><a class="code" href="scaling__video_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">00052</a> <span class="keywordtype">int</span> <a class="code" href="avio__list__dir_8c.html#a0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054     uint8_t *src_data[4], *dst_data[4];
<a name="l00055"></a>00055     <span class="keywordtype">int</span> src_linesize[4], dst_linesize[4];
<a name="l00056"></a>00056     <span class="keywordtype">int</span> src_w = 320, src_h = 240, dst_w, dst_h;
<a name="l00057"></a>00057     <span class="keyword">enum</span> <a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5" title="Pixel format.">AVPixelFormat</a> src_pix_fmt = <a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5a1aa7677092740d8def31655b5d7f0cc2" title="planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)">AV_PIX_FMT_YUV420P</a>, dst_pix_fmt = <a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5a107eadfcfe8c9fc751289eeb7744a6d3" title="packed RGB 8:8:8, 24bpp, RGBRGB...">AV_PIX_FMT_RGB24</a>;
<a name="l00058"></a>00058     <span class="keyword">const</span> <span class="keywordtype">char</span> *dst_size = NULL;
<a name="l00059"></a>00059     <span class="keyword">const</span> <span class="keywordtype">char</span> *dst_filename = NULL;
<a name="l00060"></a>00060     FILE *dst_file;
<a name="l00061"></a>00061     <span class="keywordtype">int</span> dst_bufsize;
<a name="l00062"></a>00062     <span class="keyword">struct </span>SwsContext *sws_ctx;
<a name="l00063"></a>00063     <span class="keywordtype">int</span> i, ret;
<a name="l00064"></a>00064 
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (argc != 3) {
<a name="l00066"></a>00066         fprintf(stderr, <span class="stringliteral">&quot;Usage: %s output_file output_size\n&quot;</span>
<a name="l00067"></a>00067                 <span class="stringliteral">&quot;API example program to show how to scale an image with libswscale.\n&quot;</span>
<a name="l00068"></a>00068                 <span class="stringliteral">&quot;This program generates a series of pictures, rescales them to the given &quot;</span>
<a name="l00069"></a>00069                 <span class="stringliteral">&quot;output_size and saves them to an output file named output_file\n.&quot;</span>
<a name="l00070"></a>00070                 <span class="stringliteral">&quot;\n&quot;</span>, argv[0]);
<a name="l00071"></a>00071         exit(1);
<a name="l00072"></a>00072     }
<a name="l00073"></a>00073     dst_filename = argv[1];
<a name="l00074"></a>00074     dst_size     = argv[2];
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="keywordflow">if</span> (<a class="code" href="parseutils_8h.html#a4dcdb8a2792f2074ca4a1e1f4ddce2bf" title="Parse str and put in width_ptr and height_ptr the detected values.">av_parse_video_size</a>(&amp;dst_w, &amp;dst_h, dst_size) &lt; 0) {
<a name="l00077"></a>00077         fprintf(stderr,
<a name="l00078"></a>00078                 <span class="stringliteral">&quot;Invalid size &#39;%s&#39;, must be in the form WxH or a valid size abbreviation\n&quot;</span>,
<a name="l00079"></a>00079                 dst_size);
<a name="l00080"></a>00080         exit(1);
<a name="l00081"></a>00081     }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083     dst_file = fopen(dst_filename, <span class="stringliteral">&quot;wb&quot;</span>);
<a name="l00084"></a>00084     <span class="keywordflow">if</span> (!dst_file) {
<a name="l00085"></a>00085         fprintf(stderr, <span class="stringliteral">&quot;Could not open destination file %s\n&quot;</span>, dst_filename);
<a name="l00086"></a>00086         exit(1);
<a name="l00087"></a>00087     }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089     <span class="comment">/* create scaling context */</span>
<a name="l00090"></a>00090     sws_ctx = <a class="code" href="group__libsws.html#gaf360d1a9e0e60f906f74d7d44f9abfdd" title="Allocate and return an SwsContext.">sws_getContext</a>(src_w, src_h, src_pix_fmt,
<a name="l00091"></a>00091                              dst_w, dst_h, dst_pix_fmt,
<a name="l00092"></a>00092                              <a class="code" href="group__libsws.html#ga26b45a2c6df7c1637feab34fbb21a9bb">SWS_BILINEAR</a>, NULL, NULL, NULL);
<a name="l00093"></a>00093     <span class="keywordflow">if</span> (!sws_ctx) {
<a name="l00094"></a>00094         fprintf(stderr,
<a name="l00095"></a>00095                 <span class="stringliteral">&quot;Impossible to create scale context for the conversion &quot;</span>
<a name="l00096"></a>00096                 <span class="stringliteral">&quot;fmt:%s s:%dx%d -&gt; fmt:%s s:%dx%d\n&quot;</span>,
<a name="l00097"></a>00097                 <a class="code" href="pixdesc_8h.html#ab92e2a8a9b58c982560c49df9f01e47e" title="Return the short name for a pixel format, NULL in case pix_fmt is unknown.">av_get_pix_fmt_name</a>(src_pix_fmt), src_w, src_h,
<a name="l00098"></a>00098                 <a class="code" href="pixdesc_8h.html#ab92e2a8a9b58c982560c49df9f01e47e" title="Return the short name for a pixel format, NULL in case pix_fmt is unknown.">av_get_pix_fmt_name</a>(dst_pix_fmt), dst_w, dst_h);
<a name="l00099"></a>00099         ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(EINVAL);
<a name="l00100"></a>00100         <span class="keywordflow">goto</span> end;
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     <span class="comment">/* allocate source and destination image buffers */</span>
<a name="l00104"></a>00104     <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavu__picture.html#ga841e0a89a642e24141af1918a2c10448" title="Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...">av_image_alloc</a>(src_data, src_linesize,
<a name="l00105"></a>00105                               src_w, src_h, src_pix_fmt, 16)) &lt; 0) {
<a name="l00106"></a>00106         fprintf(stderr, <span class="stringliteral">&quot;Could not allocate source image\n&quot;</span>);
<a name="l00107"></a>00107         <span class="keywordflow">goto</span> end;
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     <span class="comment">/* buffer is going to be written to rawvideo file, no alignment */</span>
<a name="l00111"></a>00111     <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavu__picture.html#ga841e0a89a642e24141af1918a2c10448" title="Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...">av_image_alloc</a>(dst_data, dst_linesize,
<a name="l00112"></a>00112                               dst_w, dst_h, dst_pix_fmt, 1)) &lt; 0) {
<a name="l00113"></a>00113         fprintf(stderr, <span class="stringliteral">&quot;Could not allocate destination image\n&quot;</span>);
<a name="l00114"></a>00114         <span class="keywordflow">goto</span> end;
<a name="l00115"></a>00115     }
<a name="l00116"></a>00116     dst_bufsize = ret;
<a name="l00117"></a>00117 
<a name="l00118"></a>00118     <span class="keywordflow">for</span> (i = 0; i &lt; 100; i++) {
<a name="l00119"></a>00119         <span class="comment">/* generate synthetic video */</span>
<a name="l00120"></a>00120         <a class="code" href="scaling__video_8c.html#aa900f1f8fe783be800a3caea221d8917">fill_yuv_image</a>(src_data, src_linesize, src_w, src_h, i);
<a name="l00121"></a>00121 
<a name="l00122"></a>00122         <span class="comment">/* convert to destination format */</span>
<a name="l00123"></a>00123         <a class="code" href="group__libsws.html#gae531c9754c9205d90ad6800015046d74" title="Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...">sws_scale</a>(sws_ctx, (<span class="keyword">const</span> uint8_t * <span class="keyword">const</span>*)src_data,
<a name="l00124"></a>00124                   src_linesize, 0, src_h, dst_data, dst_linesize);
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="comment">/* write scaled image to file */</span>
<a name="l00127"></a>00127         fwrite(dst_data[0], 1, dst_bufsize, dst_file);
<a name="l00128"></a>00128     }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     fprintf(stderr, <span class="stringliteral">&quot;Scaling succeeded. Play the output file with the command:\n&quot;</span>
<a name="l00131"></a>00131            <span class="stringliteral">&quot;ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n&quot;</span>,
<a name="l00132"></a>00132            <a class="code" href="pixdesc_8h.html#ab92e2a8a9b58c982560c49df9f01e47e" title="Return the short name for a pixel format, NULL in case pix_fmt is unknown.">av_get_pix_fmt_name</a>(dst_pix_fmt), dst_w, dst_h, dst_filename);
<a name="l00133"></a>00133 
<a name="l00134"></a>00134 end:
<a name="l00135"></a>00135     fclose(dst_file);
<a name="l00136"></a>00136     <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;src_data[0]);
<a name="l00137"></a>00137     <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;dst_data[0]);
<a name="l00138"></a>00138     <a class="code" href="group__libsws.html#gad3af0ca76f071dbe0173444db9882932" title="Free the swscaler context swsContext.">sws_freeContext</a>(sws_ctx);
<a name="l00139"></a>00139     <span class="keywordflow">return</span> ret &lt; 0;
<a name="l00140"></a>00140 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>