Repository URL to install this package:
Version:
7:2.7.1-1ubuntu2 ▾
|
<!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: scaling_video.c</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
 <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 Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><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>
<div class="header">
<div class="headertitle">
<div class="title">scaling_video.c</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * Copyright (c) 2012 Stefano Sabatini</span>
<span class="comment"> *</span>
<span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="comment"> * of this software and associated documentation files (the "Software"), to deal</span>
<span class="comment"> * in the Software without restriction, including without limitation the rights</span>
<span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span>
<span class="comment"> * furnished to do so, subject to the following conditions:</span>
<span class="comment"> *</span>
<span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
<span class="comment"> * all copies or substantial portions of the Software.</span>
<span class="comment"> *</span>
<span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
<span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span class="comment"> * THE SOFTWARE.</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * @file</span>
<span class="comment"> * libswscale API use example.</span>
<span class="comment"> * @example scaling_video.c</span>
<span class="comment"> */</span>
<span class="preprocessor">#include <<a class="code" href="imgutils_8h.html" title="misc image utilities">libavutil/imgutils.h</a>></span>
<span class="preprocessor">#include <<a class="code" href="parseutils_8h.html" title="misc parsing utilities">libavutil/parseutils.h</a>></span>
<span class="preprocessor">#include <<a class="code" href="swscale_8h.html" title="external API header">libswscale/swscale.h</a>></span>
<span class="keyword">static</span> <span class="keywordtype">void</span> <a name="a0"></a><a class="code" href="muxing_8c.html#acc346658c36a422fc9ab42bbb976138e">fill_yuv_image</a>(uint8_t *data[4], <span class="keywordtype">int</span> linesize[4],
<span class="keywordtype">int</span> <a name="a1"></a><a class="code" href="demuxing__decoding_8c.html#a2474a5474cbff19523a51eb1de01cda4">width</a>, <span class="keywordtype">int</span> <a name="a2"></a><a class="code" href="demuxing__decoding_8c.html#ad12fc34ce789bce6c8a05d8a17138534">height</a>, <span class="keywordtype">int</span> frame_index)
{
<span class="keywordtype">int</span> x, y;
<span class="comment">/* Y */</span>
<span class="keywordflow">for</span> (y = 0; y < <a class="code" href="demuxing__decoding_8c.html#ad12fc34ce789bce6c8a05d8a17138534">height</a>; y++)
<span class="keywordflow">for</span> (x = 0; x < <a class="code" href="demuxing__decoding_8c.html#a2474a5474cbff19523a51eb1de01cda4">width</a>; x++)
data[0][y * linesize[0] + x] = x + y + frame_index * 3;
<span class="comment">/* Cb and Cr */</span>
<span class="keywordflow">for</span> (y = 0; y < height / 2; y++) {
<span class="keywordflow">for</span> (x = 0; x < width / 2; x++) {
data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
}
}
}
<span class="keywordtype">int</span> <a name="a3"></a><a class="code" href="avio__list__dir_8c.html#a0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
uint8_t *src_data[4], *dst_data[4];
<span class="keywordtype">int</span> src_linesize[4], dst_linesize[4];
<span class="keywordtype">int</span> src_w = 320, src_h = 240, dst_w, dst_h;
<span class="keyword">enum</span> <a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5" title="Pixel format.">AVPixelFormat</a> src_pix_fmt = <a name="a4"></a><a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5a1aa7677092740d8def31655b5d7f0cc2" title="planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)">AV_PIX_FMT_YUV420P</a>, dst_pix_fmt = <a name="a5"></a><a class="code" href="pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5a107eadfcfe8c9fc751289eeb7744a6d3" title="packed RGB 8:8:8, 24bpp, RGBRGB...">AV_PIX_FMT_RGB24</a>;
<span class="keyword">const</span> <span class="keywordtype">char</span> *dst_size = NULL;
<span class="keyword">const</span> <span class="keywordtype">char</span> *dst_filename = NULL;
FILE *dst_file;
<span class="keywordtype">int</span> dst_bufsize;
<span class="keyword">struct </span>SwsContext *sws_ctx;
<span class="keywordtype">int</span> i, ret;
<span class="keywordflow">if</span> (argc != 3) {
fprintf(stderr, <span class="stringliteral">"Usage: %s output_file output_size\n"</span>
<span class="stringliteral">"API example program to show how to scale an image with libswscale.\n"</span>
<span class="stringliteral">"This program generates a series of pictures, rescales them to the given "</span>
<span class="stringliteral">"output_size and saves them to an output file named output_file\n."</span>
<span class="stringliteral">"\n"</span>, argv[0]);
exit(1);
}
dst_filename = argv[1];
dst_size = argv[2];
<span class="keywordflow">if</span> (<a name="a6"></a><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>(&dst_w, &dst_h, dst_size) < 0) {
fprintf(stderr,
<span class="stringliteral">"Invalid size '%s', must be in the form WxH or a valid size abbreviation\n"</span>,
dst_size);
exit(1);
}
dst_file = fopen(dst_filename, <span class="stringliteral">"wb"</span>);
<span class="keywordflow">if</span> (!dst_file) {
fprintf(stderr, <span class="stringliteral">"Could not open destination file %s\n"</span>, dst_filename);
exit(1);
}
<span class="comment">/* create scaling context */</span>
sws_ctx = <a name="a7"></a><a class="code" href="group__libsws.html#gaf360d1a9e0e60f906f74d7d44f9abfdd" title="Allocate and return an SwsContext.">sws_getContext</a>(src_w, src_h, src_pix_fmt,
dst_w, dst_h, dst_pix_fmt,
<a name="a8"></a><a class="code" href="group__libsws.html#ga26b45a2c6df7c1637feab34fbb21a9bb">SWS_BILINEAR</a>, NULL, NULL, NULL);
<span class="keywordflow">if</span> (!sws_ctx) {
fprintf(stderr,
<span class="stringliteral">"Impossible to create scale context for the conversion "</span>
<span class="stringliteral">"fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n"</span>,
<a name="a9"></a><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 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);
ret = <a name="a10"></a><a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(EINVAL);
<span class="keywordflow">goto</span> end;
}
<span class="comment">/* allocate source and destination image buffers */</span>
<span class="keywordflow">if</span> ((ret = <a name="a11"></a><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,
src_w, src_h, src_pix_fmt, 16)) < 0) {
fprintf(stderr, <span class="stringliteral">"Could not allocate source image\n"</span>);
<span class="keywordflow">goto</span> end;
}
<span class="comment">/* buffer is going to be written to rawvideo file, no alignment */</span>
<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,
dst_w, dst_h, dst_pix_fmt, 1)) < 0) {
fprintf(stderr, <span class="stringliteral">"Could not allocate destination image\n"</span>);
<span class="keywordflow">goto</span> end;
}
dst_bufsize = ret;
<span class="keywordflow">for</span> (i = 0; i < 100; i++) {
<span class="comment">/* generate synthetic video */</span>
<a class="code" href="muxing_8c.html#acc346658c36a422fc9ab42bbb976138e">fill_yuv_image</a>(src_data, src_linesize, src_w, src_h, i);
<span class="comment">/* convert to destination format */</span>
<a name="a12"></a><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,
src_linesize, 0, src_h, dst_data, dst_linesize);
<span class="comment">/* write scaled image to file */</span>
fwrite(dst_data[0], 1, dst_bufsize, dst_file);
}
fprintf(stderr, <span class="stringliteral">"Scaling succeeded. Play the output file with the command:\n"</span>
<span class="stringliteral">"ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n"</span>,
<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);
end:
fclose(dst_file);
<a name="a13"></a><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>(&src_data[0]);
<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>(&dst_data[0]);
<a name="a14"></a><a class="code" href="group__libsws.html#gad3af0ca76f071dbe0173444db9882932" title="Free the swscaler context swsContext.">sws_freeContext</a>(sws_ctx);
<span class="keywordflow">return</span> ret < 0;
}
</pre></div> </div><!-- contents -->
</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"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </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  <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>