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: doc/examples/transcoding.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
 <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 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 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/transcoding.c</div> </div>
</div><!--header-->
<div class="contents">
<a href="transcoding_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) 2010 Nicolas George</span>
<a name="l00003"></a>00003 <span class="comment"> * Copyright (c) 2011 Stefano Sabatini</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (c) 2014 Andrey Utkin</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a name="l00007"></a>00007 <span class="comment"> * of this software and associated documentation files (the "Software"), to deal</span>
<a name="l00008"></a>00008 <span class="comment"> * in the Software without restriction, including without limitation the rights</span>
<a name="l00009"></a>00009 <span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<a name="l00010"></a>00010 <span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span>
<a name="l00011"></a>00011 <span class="comment"> * furnished to do so, subject to the following conditions:</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
<a name="l00014"></a>00014 <span class="comment"> * all copies or substantial portions of the Software.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00017"></a>00017 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00018"></a>00018 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
<a name="l00019"></a>00019 <span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00021"></a>00021 <span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<a name="l00022"></a>00022 <span class="comment"> * THE SOFTWARE.</span>
<a name="l00023"></a>00023 <span class="comment"> */</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00025"></a>00025 <span class="comment">/**</span>
<a name="l00026"></a>00026 <span class="comment"> * @file</span>
<a name="l00027"></a>00027 <span class="comment"> * API example for demuxing, decoding, filtering, encoding and muxing</span>
<a name="l00028"></a>00028 <span class="comment"> * @example transcoding.c</span>
<a name="l00029"></a>00029 <span class="comment"> */</span>
<a name="l00030"></a>00030
<a name="l00031"></a>00031 <span class="preprocessor">#include <<a class="code" href="libavcodec_2avcodec_8h.html" title="Libavcodec external API header.">libavcodec/avcodec.h</a>></span>
<a name="l00032"></a>00032 <span class="preprocessor">#include <<a class="code" href="avformat_8h.html" title="Main libavformat public API header.">libavformat/avformat.h</a>></span>
<a name="l00033"></a>00033 <span class="preprocessor">#include <<a class="code" href="avfiltergraph_8h.html">libavfilter/avfiltergraph.h</a>></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include <<a class="code" href="libavfilter_2avcodec_8h.html" title="libavcodec/libavfilter gluing utilities">libavfilter/avcodec.h</a>></span>
<a name="l00035"></a>00035 <span class="preprocessor">#include <<a class="code" href="buffersink_8h.html" title="memory buffer sink API for audio and video">libavfilter/buffersink.h</a>></span>
<a name="l00036"></a>00036 <span class="preprocessor">#include <<a class="code" href="buffersrc_8h.html" title="Memory buffer source API.">libavfilter/buffersrc.h</a>></span>
<a name="l00037"></a>00037 <span class="preprocessor">#include <<a class="code" href="opt_8h.html" title="AVOptions.">libavutil/opt.h</a>></span>
<a name="l00038"></a>00038 <span class="preprocessor">#include <<a class="code" href="pixdesc_8h.html">libavutil/pixdesc.h</a>></span>
<a name="l00039"></a>00039
<a name="l00040"></a><a class="code" href="transcoding_8c.html#a24170971d926c1359c289f2515dec3d7">00040</a> <span class="keyword">static</span> <a class="code" href="structAVFormatContext.html" title="Format I/O context.">AVFormatContext</a> *<a class="code" href="transcoding_8c.html#a24170971d926c1359c289f2515dec3d7">ifmt_ctx</a>;
<a name="l00041"></a><a class="code" href="transcoding_8c.html#aad50129a22f90b00b5d5cc7551175093">00041</a> <span class="keyword">static</span> <a class="code" href="structAVFormatContext.html" title="Format I/O context.">AVFormatContext</a> *<a class="code" href="transcoding_8c.html#aad50129a22f90b00b5d5cc7551175093">ofmt_ctx</a>;
<a name="l00042"></a><a class="code" href="structFilteringContext.html">00042</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structFilteringContext.html">FilteringContext</a> {
<a name="l00043"></a><a class="code" href="structFilteringContext.html#a4476c9e6fb492172c909ae4a47c47233">00043</a> <a class="code" href="structAVFilterContext.html" title="An instance of a filter.">AVFilterContext</a> *<a class="code" href="structFilteringContext.html#a4476c9e6fb492172c909ae4a47c47233">buffersink_ctx</a>;
<a name="l00044"></a><a class="code" href="structFilteringContext.html#a25c500d3728df3a9f904e6d86cf55f11">00044</a> <a class="code" href="structAVFilterContext.html" title="An instance of a filter.">AVFilterContext</a> *<a class="code" href="structFilteringContext.html#a25c500d3728df3a9f904e6d86cf55f11">buffersrc_ctx</a>;
<a name="l00045"></a><a class="code" href="structFilteringContext.html#aaf35e44d4e6100095b1db444e2d316cd">00045</a> <a class="code" href="structAVFilterGraph.html">AVFilterGraph</a> *<a class="code" href="structFilteringContext.html#aaf35e44d4e6100095b1db444e2d316cd">filter_graph</a>;
<a name="l00046"></a>00046 } <a class="code" href="structFilteringContext.html">FilteringContext</a>;
<a name="l00047"></a><a class="code" href="transcoding_8c.html#aac21c1c8f68cdafd001a6a13dc4d7fb7">00047</a> <span class="keyword">static</span> <a class="code" href="structFilteringContext.html">FilteringContext</a> *<a class="code" href="transcoding_8c.html#aac21c1c8f68cdafd001a6a13dc4d7fb7">filter_ctx</a>;
<a name="l00048"></a>00048
<a name="l00049"></a><a class="code" href="transcoding_8c.html#abd04bf1a933d4d2698482f4949c61fed">00049</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#abd04bf1a933d4d2698482f4949c61fed">open_input_file</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 <span class="keywordtype">int</span> ret;
<a name="l00052"></a>00052 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00053"></a>00053
<a name="l00054"></a>00054 ifmt_ctx = NULL;
<a name="l00055"></a>00055 <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavf__decoding.html#ga10a404346c646e4ab58f4ed798baca32" title="Open an input stream and read the header.">avformat_open_input</a>(&ifmt_ctx, filename, NULL, NULL)) < 0) {
<a name="l00056"></a>00056 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot open input file\n"</span>);
<a name="l00057"></a>00057 <span class="keywordflow">return</span> ret;
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059
<a name="l00060"></a>00060 <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavf__decoding.html#gad42172e27cddafb81096939783b157bb" title="Read packets of a media file to get stream information.">avformat_find_stream_info</a>(ifmt_ctx, NULL)) < 0) {
<a name="l00061"></a>00061 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot find stream information\n"</span>);
<a name="l00062"></a>00062 <span class="keywordflow">return</span> ret;
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064
<a name="l00065"></a>00065 <span class="keywordflow">for</span> (i = 0; i < ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>; i++) {
<a name="l00066"></a>00066 <a class="code" href="structAVStream.html" title="Stream structure.">AVStream</a> *stream;
<a name="l00067"></a>00067 <a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *codec_ctx;
<a name="l00068"></a>00068 stream = ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i];
<a name="l00069"></a>00069 codec_ctx = stream-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>;
<a name="l00070"></a>00070 <span class="comment">/* Reencode video & audio and remux subtitles etc. */</span>
<a name="l00071"></a>00071 <span class="keywordflow">if</span> (codec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>
<a name="l00072"></a>00072 || codec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48a7b4e33b8f30ac94d34ce8d9f7c33927a">AVMEDIA_TYPE_AUDIO</a>) {
<a name="l00073"></a>00073 <span class="comment">/* Open decoder */</span>
<a name="l00074"></a>00074 ret = <a class="code" href="group__lavc__core.html#ga11f785a188d7d9df71621001465b0f1d" title="Initialize the AVCodecContext to use the given AVCodec.">avcodec_open2</a>(codec_ctx,
<a name="l00075"></a>00075 <a class="code" href="group__lavc__decoding.html#ga19a0ca553277f019dd5b0fec6e1f9dca" title="Find a registered decoder with a matching codec ID.">avcodec_find_decoder</a>(codec_ctx-><a class="code" href="structAVCodecContext.html#adc5f65d6099fd8339c1580c091777223">codec_id</a>), NULL);
<a name="l00076"></a>00076 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00077"></a>00077 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Failed to open decoder for stream #%u\n"</span>, i);
<a name="l00078"></a>00078 <span class="keywordflow">return</span> ret;
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082
<a name="l00083"></a>00083 <a class="code" href="group__lavf__misc.html#gae2645941f2dc779c307eb6314fd39f10" title="Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.">av_dump_format</a>(ifmt_ctx, 0, filename, 0);
<a name="l00084"></a>00084 <span class="keywordflow">return</span> 0;
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086
<a name="l00087"></a><a class="code" href="transcoding_8c.html#ab6c33edf9a42e2f71594a7cdc6276407">00087</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#ab6c33edf9a42e2f71594a7cdc6276407">open_output_file</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089 <a class="code" href="structAVStream.html" title="Stream structure.">AVStream</a> *out_stream;
<a name="l00090"></a>00090 <a class="code" href="structAVStream.html" title="Stream structure.">AVStream</a> *in_stream;
<a name="l00091"></a>00091 <a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *<a class="code" href="filtering__audio_8c.html#ac2bf6798f37e95d3d2ff2d44e4ab3c12">dec_ctx</a>, *enc_ctx;
<a name="l00092"></a>00092 <a class="code" href="structAVCodec.html" title="AVCodec.">AVCodec</a> *encoder;
<a name="l00093"></a>00093 <span class="keywordtype">int</span> ret;
<a name="l00094"></a>00094 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00095"></a>00095
<a name="l00096"></a>00096 ofmt_ctx = NULL;
<a name="l00097"></a>00097 <a class="code" href="avformat_8h.html#a6ddf3d982feb45fa5081420ee911f5d5" title="Allocate an AVFormatContext for an output format.">avformat_alloc_output_context2</a>(&ofmt_ctx, NULL, NULL, filename);
<a name="l00098"></a>00098 <span class="keywordflow">if</span> (!ofmt_ctx) {
<a name="l00099"></a>00099 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Could not create output context\n"</span>);
<a name="l00100"></a>00100 <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#ga4ebaa288c7684a26a591c501208910e4" title="Unknown error, typically from an external library.">AVERROR_UNKNOWN</a>;
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102
<a name="l00103"></a>00103
<a name="l00104"></a>00104 <span class="keywordflow">for</span> (i = 0; i < ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>; i++) {
<a name="l00105"></a>00105 out_stream = <a class="code" href="group__lavf__core.html#gadcb0fd3e507d9b58fe78f61f8ad39827" title="Add a new stream to a media file.">avformat_new_stream</a>(ofmt_ctx, NULL);
<a name="l00106"></a>00106 <span class="keywordflow">if</span> (!out_stream) {
<a name="l00107"></a>00107 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Failed allocating output stream\n"</span>);
<a name="l00108"></a>00108 <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#ga4ebaa288c7684a26a591c501208910e4" title="Unknown error, typically from an external library.">AVERROR_UNKNOWN</a>;
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110
<a name="l00111"></a>00111 in_stream = ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i];
<a name="l00112"></a>00112 dec_ctx = in_stream-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>;
<a name="l00113"></a>00113 enc_ctx = out_stream-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>;
<a name="l00114"></a>00114
<a name="l00115"></a>00115 <span class="keywordflow">if</span> (dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>
<a name="l00116"></a>00116 || dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48a7b4e33b8f30ac94d34ce8d9f7c33927a">AVMEDIA_TYPE_AUDIO</a>) {
<a name="l00117"></a>00117 <span class="comment">/* in this example, we choose transcoding to same codec */</span>
<a name="l00118"></a>00118 encoder = <a class="code" href="group__lavc__encoding.html#ga9f820c481615c3a02d0407bac0bdbf25" title="Find a registered encoder with a matching codec ID.">avcodec_find_encoder</a>(dec_ctx-><a class="code" href="structAVCodecContext.html#adc5f65d6099fd8339c1580c091777223">codec_id</a>);
<a name="l00119"></a>00119 <span class="keywordflow">if</span> (!encoder) {
<a name="l00120"></a>00120 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#ga96970a2980bf6ad28cd403e7dc52d6c5" title="Something went wrong and recovery is not possible.">AV_LOG_FATAL</a>, <span class="stringliteral">"Necessary encoder not found\n"</span>);
<a name="l00121"></a>00121 <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#gaa6e5781e75b15ce44b0baea170c98a45" title="Invalid data found when processing input.">AVERROR_INVALIDDATA</a>;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123
<a name="l00124"></a>00124 <span class="comment">/* In this example, we transcode to same properties (picture size,</span>
<a name="l00125"></a>00125 <span class="comment"> * sample rate etc.). These properties can be changed for output</span>
<a name="l00126"></a>00126 <span class="comment"> * streams easily using filters */</span>
<a name="l00127"></a>00127 <span class="keywordflow">if</span> (dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>) {
<a name="l00128"></a>00128 enc_ctx-><a class="code" href="structAVCodecContext.html#a0449afd803eb107bd4dbc8b5ea22e363">height</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#a0449afd803eb107bd4dbc8b5ea22e363">height</a>;
<a name="l00129"></a>00129 enc_ctx-><a class="code" href="structAVCodecContext.html#a0d8f46461754e8abea0847dcbc41b956" title="picture width / height.">width</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#a0d8f46461754e8abea0847dcbc41b956" title="picture width / height.">width</a>;
<a name="l00130"></a>00130 enc_ctx-><a class="code" href="structAVCodecContext.html#a5252d34fbce300228d4dbda19a8c3293" title="sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...">sample_aspect_ratio</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#a5252d34fbce300228d4dbda19a8c3293" title="sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...">sample_aspect_ratio</a>;
<a name="l00131"></a>00131 <span class="comment">/* take first format from list of supported formats */</span>
<a name="l00132"></a>00132 enc_ctx-><a class="code" href="structAVCodecContext.html#a0425c77b3d06d71e5db88b1d7e1b37f2" title="Pixel format, see AV_PIX_FMT_xxx.">pix_fmt</a> = encoder-><a class="code" href="structAVCodec.html#ac2b97bd3c19686025e1b7d577329c250" title="array of supported pixel formats, or NULL if unknown, array is terminated by -1">pix_fmts</a>[0];
<a name="l00133"></a>00133 <span class="comment">/* video time_base can be set to whatever is handy and supported by encoder */</span>
<a name="l00134"></a>00134 enc_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>;
<a name="l00135"></a>00135 } <span class="keywordflow">else</span> {
<a name="l00136"></a>00136 enc_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a>;
<a name="l00137"></a>00137 enc_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a> = dec_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>;
<a name="l00138"></a>00138 enc_ctx-><a class="code" href="structAVCodecContext.html#ac1e6c2cd1269caa7570575725c682a49" title="number of audio channels">channels</a> = <a class="code" href="group__channel__mask__c.html#gac95619abeb32e4a3daa18e3ff3419380" title="Return the number of channels in the channel layout.">av_get_channel_layout_nb_channels</a>(enc_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>);
<a name="l00139"></a>00139 <span class="comment">/* take first format from list of supported formats */</span>
<a name="l00140"></a>00140 enc_ctx-><a class="code" href="structAVCodecContext.html#a1bdba69ea111e2a9d03fdaa7a46a4c45" title="audio sample format">sample_fmt</a> = encoder-><a class="code" href="structAVCodec.html#aac19f4c45370f715412ad5c7b78daacf" title="array of supported sample formats, or NULL if unknown, array is terminated by -1">sample_fmts</a>[0];
<a name="l00141"></a>00141 enc_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a> = (<a class="code" href="structAVRational.html" title="rational number numerator/denominator">AVRational</a>){1, enc_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a>};
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143
<a name="l00144"></a>00144 <span class="comment">/* Third parameter can be used to pass settings to encoder */</span>
<a name="l00145"></a>00145 ret = <a class="code" href="group__lavc__core.html#ga11f785a188d7d9df71621001465b0f1d" title="Initialize the AVCodecContext to use the given AVCodec.">avcodec_open2</a>(enc_ctx, encoder, NULL);
<a name="l00146"></a>00146 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00147"></a>00147 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot open video encoder for stream #%u\n"</span>, i);
<a name="l00148"></a>00148 <span class="keywordflow">return</span> ret;
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48afdadbd6c4f612c59f6b6c7c6f84fd347" title="Usually treated as AVMEDIA_TYPE_DATA.">AVMEDIA_TYPE_UNKNOWN</a>) {
<a name="l00151"></a>00151 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#ga96970a2980bf6ad28cd403e7dc52d6c5" title="Something went wrong and recovery is not possible.">AV_LOG_FATAL</a>, <span class="stringliteral">"Elementary stream #%d is of unknown type, cannot proceed\n"</span>, i);
<a name="l00152"></a>00152 <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#gaa6e5781e75b15ce44b0baea170c98a45" title="Invalid data found when processing input.">AVERROR_INVALIDDATA</a>;
<a name="l00153"></a>00153 } <span class="keywordflow">else</span> {
<a name="l00154"></a>00154 <span class="comment">/* if this stream must be remuxed */</span>
<a name="l00155"></a>00155 ret = <a class="code" href="group__lavc__core.html#ga3933b21b9dcb9173df3e56673b7a7d76" title="Copy the settings of the source AVCodecContext into the destination AVCodecContext.">avcodec_copy_context</a>(ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>,
<a name="l00156"></a>00156 ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>);
<a name="l00157"></a>00157 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00158"></a>00158 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Copying stream context failed\n"</span>);
<a name="l00159"></a>00159 <span class="keywordflow">return</span> ret;
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162
<a name="l00163"></a>00163 <span class="keywordflow">if</span> (ofmt_ctx-><a class="code" href="structAVFormatContext.html#a20d80ac07e38ff5c268d15aaf2798b98" title="The output container format.">oformat</a>-><a class="code" href="structAVOutputFormat.html#aad55a00e728a020c1dcfaaf695320445" title="can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT">flags</a> & <a class="code" href="avformat_8h.html#ab203c7b734e9c31b7c37d34f6e2c6aef" title="Format wants global header.">AVFMT_GLOBALHEADER</a>)
<a name="l00164"></a>00164 enc_ctx-><a class="code" href="structAVCodecContext.html#abb01e291550fa3fb96188af4d494587e" title="CODEC_FLAG_*.">flags</a> |= <a class="code" href="group__lavc__core.html#gaab6ceefd617cf265ef7ea1b87ed5933e" title="Place global headers in extradata instead of every keyframe.">CODEC_FLAG_GLOBAL_HEADER</a>;
<a name="l00165"></a>00165
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 <a class="code" href="group__lavf__misc.html#gae2645941f2dc779c307eb6314fd39f10" title="Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.">av_dump_format</a>(ofmt_ctx, 0, filename, 1);
<a name="l00168"></a>00168
<a name="l00169"></a>00169 <span class="keywordflow">if</span> (!(ofmt_ctx-><a class="code" href="structAVFormatContext.html#a20d80ac07e38ff5c268d15aaf2798b98" title="The output container format.">oformat</a>-><a class="code" href="structAVOutputFormat.html#aad55a00e728a020c1dcfaaf695320445" title="can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT">flags</a> & <a class="code" href="avformat_8h.html#a752cce390d480521919aa5d8be24ac0b" title="Demuxer will use avio_open, no opened file should be provided by the caller.">AVFMT_NOFILE</a>)) {
<a name="l00170"></a>00170 ret = <a class="code" href="avio_8h.html#a371a670112abc5f3e15bc570da076301" title="Create and initialize a AVIOContext for accessing the resource indicated by url.">avio_open</a>(&ofmt_ctx-><a class="code" href="structAVFormatContext.html#a1e7324262b6b78522e52064daaa7bc87" title="I/O context.">pb</a>, filename, <a class="code" href="avio_8h.html#a5c9308f296545a8f3b7687d277a6dabc" title="write-only">AVIO_FLAG_WRITE</a>);
<a name="l00171"></a>00171 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00172"></a>00172 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Could not open output file '%s'"</span>, filename);
<a name="l00173"></a>00173 <span class="keywordflow">return</span> ret;
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176
<a name="l00177"></a>00177 <span class="comment">/* init muxer, write output file header */</span>
<a name="l00178"></a>00178 ret = <a class="code" href="group__lavf__encoding.html#ga78d4e734fecb1d2385536e6dd5b7b9f5" title="Allocate the stream private data and write the stream header to an output media file.">avformat_write_header</a>(ofmt_ctx, NULL);
<a name="l00179"></a>00179 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00180"></a>00180 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Error occurred when opening output file\n"</span>);
<a name="l00181"></a>00181 <span class="keywordflow">return</span> ret;
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183
<a name="l00184"></a>00184 <span class="keywordflow">return</span> 0;
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186
<a name="l00187"></a><a class="code" href="transcoding_8c.html#a54ad76df48ef886861a2f12bc7a9e7e4">00187</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#a54ad76df48ef886861a2f12bc7a9e7e4">init_filter</a>(<a class="code" href="structFilteringContext.html">FilteringContext</a>* fctx, <a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *<a class="code" href="filtering__audio_8c.html#ac2bf6798f37e95d3d2ff2d44e4ab3c12">dec_ctx</a>,
<a name="l00188"></a>00188 <a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *enc_ctx, <span class="keyword">const</span> <span class="keywordtype">char</span> *filter_spec)
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190 <span class="keywordtype">char</span> args[512];
<a name="l00191"></a>00191 <span class="keywordtype">int</span> ret = 0;
<a name="l00192"></a>00192 <a class="code" href="structAVFilter.html" title="Filter definition.">AVFilter</a> *buffersrc = NULL;
<a name="l00193"></a>00193 <a class="code" href="structAVFilter.html" title="Filter definition.">AVFilter</a> *buffersink = NULL;
<a name="l00194"></a>00194 <a class="code" href="structAVFilterContext.html" title="An instance of a filter.">AVFilterContext</a> *<a class="code" href="filtering__audio_8c.html#a8dce1714a267758c056947f105f66a82">buffersrc_ctx</a> = NULL;
<a name="l00195"></a>00195 <a class="code" href="structAVFilterContext.html" title="An instance of a filter.">AVFilterContext</a> *<a class="code" href="filtering__audio_8c.html#a5a75197a9aaa609af34cfc0d199acbda">buffersink_ctx</a> = NULL;
<a name="l00196"></a>00196 <a class="code" href="structAVFilterInOut.html" title="A linked-list of the inputs/outputs of the filter chain.">AVFilterInOut</a> *outputs = <a class="code" href="group__lavfi.html#ga6e1c2931e15eb4283c59c6ccc8b83919" title="Allocate a single AVFilterInOut entry.">avfilter_inout_alloc</a>();
<a name="l00197"></a>00197 <a class="code" href="structAVFilterInOut.html" title="A linked-list of the inputs/outputs of the filter chain.">AVFilterInOut</a> *inputs = <a class="code" href="group__lavfi.html#ga6e1c2931e15eb4283c59c6ccc8b83919" title="Allocate a single AVFilterInOut entry.">avfilter_inout_alloc</a>();
<a name="l00198"></a>00198 <a class="code" href="structAVFilterGraph.html">AVFilterGraph</a> *<a class="code" href="filtering__audio_8c.html#a36c24d3c84d08e2f5a69e7368c211412">filter_graph</a> = <a class="code" href="group__lavfi.html#ga6c778454b86f845805ffd814b4ce51d4" title="Allocate a filter graph.">avfilter_graph_alloc</a>();
<a name="l00199"></a>00199
<a name="l00200"></a>00200 <span class="keywordflow">if</span> (!outputs || !inputs || !filter_graph) {
<a name="l00201"></a>00201 ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00202"></a>00202 <span class="keywordflow">goto</span> end;
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204
<a name="l00205"></a>00205 <span class="keywordflow">if</span> (dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>) {
<a name="l00206"></a>00206 buffersrc = <a class="code" href="group__lavfi.html#gadd774ec49e50edf00158248e1bfe4ae6" title="Get a filter definition matching the given name.">avfilter_get_by_name</a>(<span class="stringliteral">"buffer"</span>);
<a name="l00207"></a>00207 buffersink = <a class="code" href="group__lavfi.html#gadd774ec49e50edf00158248e1bfe4ae6" title="Get a filter definition matching the given name.">avfilter_get_by_name</a>(<span class="stringliteral">"buffersink"</span>);
<a name="l00208"></a>00208 <span class="keywordflow">if</span> (!buffersrc || !buffersink) {
<a name="l00209"></a>00209 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"filtering source or sink element not found\n"</span>);
<a name="l00210"></a>00210 ret = <a class="code" href="group__lavu__error.html#ga4ebaa288c7684a26a591c501208910e4" title="Unknown error, typically from an external library.">AVERROR_UNKNOWN</a>;
<a name="l00211"></a>00211 <span class="keywordflow">goto</span> end;
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213
<a name="l00214"></a>00214 snprintf(args, <span class="keyword">sizeof</span>(args),
<a name="l00215"></a>00215 <span class="stringliteral">"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d"</span>,
<a name="l00216"></a>00216 dec_ctx-><a class="code" href="structAVCodecContext.html#a0d8f46461754e8abea0847dcbc41b956" title="picture width / height.">width</a>, dec_ctx-><a class="code" href="structAVCodecContext.html#a0449afd803eb107bd4dbc8b5ea22e363">height</a>, dec_ctx-><a class="code" href="structAVCodecContext.html#a0425c77b3d06d71e5db88b1d7e1b37f2" title="Pixel format, see AV_PIX_FMT_xxx.">pix_fmt</a>,
<a name="l00217"></a>00217 dec_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>.<a class="code" href="structAVRational.html#ae9a98c10a301c5e937095105b6f0fdb9" title="numerator">num</a>, dec_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>.<a class="code" href="structAVRational.html#aee46bdac67d965ac0a4204e753f910c3" title="denominator">den</a>,
<a name="l00218"></a>00218 dec_ctx-><a class="code" href="structAVCodecContext.html#a5252d34fbce300228d4dbda19a8c3293" title="sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...">sample_aspect_ratio</a>.<a class="code" href="structAVRational.html#ae9a98c10a301c5e937095105b6f0fdb9" title="numerator">num</a>,
<a name="l00219"></a>00219 dec_ctx-><a class="code" href="structAVCodecContext.html#a5252d34fbce300228d4dbda19a8c3293" title="sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...">sample_aspect_ratio</a>.<a class="code" href="structAVRational.html#aee46bdac67d965ac0a4204e753f910c3" title="denominator">den</a>);
<a name="l00220"></a>00220
<a name="l00221"></a>00221 ret = <a class="code" href="group__lavfi.html#gac0788a9ab6966dba9318b5d5c7524fea" title="Create and add a filter instance into an existing graph.">avfilter_graph_create_filter</a>(&buffersrc_ctx, buffersrc, <span class="stringliteral">"in"</span>,
<a name="l00222"></a>00222 args, NULL, filter_graph);
<a name="l00223"></a>00223 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00224"></a>00224 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot create buffer source\n"</span>);
<a name="l00225"></a>00225 <span class="keywordflow">goto</span> end;
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227
<a name="l00228"></a>00228 ret = <a class="code" href="group__lavfi.html#gac0788a9ab6966dba9318b5d5c7524fea" title="Create and add a filter instance into an existing graph.">avfilter_graph_create_filter</a>(&buffersink_ctx, buffersink, <span class="stringliteral">"out"</span>,
<a name="l00229"></a>00229 NULL, NULL, filter_graph);
<a name="l00230"></a>00230 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00231"></a>00231 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot create buffer sink\n"</span>);
<a name="l00232"></a>00232 <span class="keywordflow">goto</span> end;
<a name="l00233"></a>00233 }
<a name="l00234"></a>00234
<a name="l00235"></a>00235 ret = <a class="code" href="group__opt__set__funcs.html#ga6c32155fd8a96bed2f8cf5ebc030dadf">av_opt_set_bin</a>(buffersink_ctx, <span class="stringliteral">"pix_fmts"</span>,
<a name="l00236"></a>00236 (uint8_t*)&enc_ctx-><a class="code" href="structAVCodecContext.html#a0425c77b3d06d71e5db88b1d7e1b37f2" title="Pixel format, see AV_PIX_FMT_xxx.">pix_fmt</a>, <span class="keyword">sizeof</span>(enc_ctx-><a class="code" href="structAVCodecContext.html#a0425c77b3d06d71e5db88b1d7e1b37f2" title="Pixel format, see AV_PIX_FMT_xxx.">pix_fmt</a>),
<a name="l00237"></a>00237 <a class="code" href="group__avoptions.html#ga25801ba4fc9b5313eb33ec84e082dd72" title="Search in possible children of the given object first.">AV_OPT_SEARCH_CHILDREN</a>);
<a name="l00238"></a>00238 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00239"></a>00239 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot set output pixel format\n"</span>);
<a name="l00240"></a>00240 <span class="keywordflow">goto</span> end;
<a name="l00241"></a>00241 }
<a name="l00242"></a>00242 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (dec_ctx-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48a7b4e33b8f30ac94d34ce8d9f7c33927a">AVMEDIA_TYPE_AUDIO</a>) {
<a name="l00243"></a>00243 buffersrc = <a class="code" href="group__lavfi.html#gadd774ec49e50edf00158248e1bfe4ae6" title="Get a filter definition matching the given name.">avfilter_get_by_name</a>(<span class="stringliteral">"abuffer"</span>);
<a name="l00244"></a>00244 buffersink = <a class="code" href="group__lavfi.html#gadd774ec49e50edf00158248e1bfe4ae6" title="Get a filter definition matching the given name.">avfilter_get_by_name</a>(<span class="stringliteral">"abuffersink"</span>);
<a name="l00245"></a>00245 <span class="keywordflow">if</span> (!buffersrc || !buffersink) {
<a name="l00246"></a>00246 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"filtering source or sink element not found\n"</span>);
<a name="l00247"></a>00247 ret = <a class="code" href="group__lavu__error.html#ga4ebaa288c7684a26a591c501208910e4" title="Unknown error, typically from an external library.">AVERROR_UNKNOWN</a>;
<a name="l00248"></a>00248 <span class="keywordflow">goto</span> end;
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250
<a name="l00251"></a>00251 <span class="keywordflow">if</span> (!dec_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>)
<a name="l00252"></a>00252 dec_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a> =
<a name="l00253"></a>00253 <a class="code" href="group__channel__mask__c.html#gacb84f3e93a583e1f84a5283162a606a2" title="Return default channel layout for a given number of channels.">av_get_default_channel_layout</a>(dec_ctx-><a class="code" href="structAVCodecContext.html#ac1e6c2cd1269caa7570575725c682a49" title="number of audio channels">channels</a>);
<a name="l00254"></a>00254 snprintf(args, <span class="keyword">sizeof</span>(args),
<a name="l00255"></a>00255 <span class="stringliteral">"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"</span>PRIx64,
<a name="l00256"></a>00256 dec_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>.<a class="code" href="structAVRational.html#ae9a98c10a301c5e937095105b6f0fdb9" title="numerator">num</a>, dec_ctx-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>.<a class="code" href="structAVRational.html#aee46bdac67d965ac0a4204e753f910c3" title="denominator">den</a>, dec_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a>,
<a name="l00257"></a>00257 <a class="code" href="group__lavu__sampfmts.html#ga31b9d149b2de9821a65f4f5612970838" title="Return the name of sample_fmt, or NULL if sample_fmt is not recognized.">av_get_sample_fmt_name</a>(dec_ctx-><a class="code" href="structAVCodecContext.html#a1bdba69ea111e2a9d03fdaa7a46a4c45" title="audio sample format">sample_fmt</a>),
<a name="l00258"></a>00258 dec_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>);
<a name="l00259"></a>00259 ret = <a class="code" href="group__lavfi.html#gac0788a9ab6966dba9318b5d5c7524fea" title="Create and add a filter instance into an existing graph.">avfilter_graph_create_filter</a>(&buffersrc_ctx, buffersrc, <span class="stringliteral">"in"</span>,
<a name="l00260"></a>00260 args, NULL, filter_graph);
<a name="l00261"></a>00261 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00262"></a>00262 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot create audio buffer source\n"</span>);
<a name="l00263"></a>00263 <span class="keywordflow">goto</span> end;
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265
<a name="l00266"></a>00266 ret = <a class="code" href="group__lavfi.html#gac0788a9ab6966dba9318b5d5c7524fea" title="Create and add a filter instance into an existing graph.">avfilter_graph_create_filter</a>(&buffersink_ctx, buffersink, <span class="stringliteral">"out"</span>,
<a name="l00267"></a>00267 NULL, NULL, filter_graph);
<a name="l00268"></a>00268 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00269"></a>00269 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot create audio buffer sink\n"</span>);
<a name="l00270"></a>00270 <span class="keywordflow">goto</span> end;
<a name="l00271"></a>00271 }
<a name="l00272"></a>00272
<a name="l00273"></a>00273 ret = <a class="code" href="group__opt__set__funcs.html#ga6c32155fd8a96bed2f8cf5ebc030dadf">av_opt_set_bin</a>(buffersink_ctx, <span class="stringliteral">"sample_fmts"</span>,
<a name="l00274"></a>00274 (uint8_t*)&enc_ctx-><a class="code" href="structAVCodecContext.html#a1bdba69ea111e2a9d03fdaa7a46a4c45" title="audio sample format">sample_fmt</a>, <span class="keyword">sizeof</span>(enc_ctx-><a class="code" href="structAVCodecContext.html#a1bdba69ea111e2a9d03fdaa7a46a4c45" title="audio sample format">sample_fmt</a>),
<a name="l00275"></a>00275 <a class="code" href="group__avoptions.html#ga25801ba4fc9b5313eb33ec84e082dd72" title="Search in possible children of the given object first.">AV_OPT_SEARCH_CHILDREN</a>);
<a name="l00276"></a>00276 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00277"></a>00277 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot set output sample format\n"</span>);
<a name="l00278"></a>00278 <span class="keywordflow">goto</span> end;
<a name="l00279"></a>00279 }
<a name="l00280"></a>00280
<a name="l00281"></a>00281 ret = <a class="code" href="group__opt__set__funcs.html#ga6c32155fd8a96bed2f8cf5ebc030dadf">av_opt_set_bin</a>(buffersink_ctx, <span class="stringliteral">"channel_layouts"</span>,
<a name="l00282"></a>00282 (uint8_t*)&enc_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>,
<a name="l00283"></a>00283 <span class="keyword">sizeof</span>(enc_ctx-><a class="code" href="structAVCodecContext.html#aeb08c575a79eb84fc4155dda88f46c06" title="Audio channel layout.">channel_layout</a>), <a class="code" href="group__avoptions.html#ga25801ba4fc9b5313eb33ec84e082dd72" title="Search in possible children of the given object first.">AV_OPT_SEARCH_CHILDREN</a>);
<a name="l00284"></a>00284 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00285"></a>00285 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot set output channel layout\n"</span>);
<a name="l00286"></a>00286 <span class="keywordflow">goto</span> end;
<a name="l00287"></a>00287 }
<a name="l00288"></a>00288
<a name="l00289"></a>00289 ret = <a class="code" href="group__opt__set__funcs.html#ga6c32155fd8a96bed2f8cf5ebc030dadf">av_opt_set_bin</a>(buffersink_ctx, <span class="stringliteral">"sample_rates"</span>,
<a name="l00290"></a>00290 (uint8_t*)&enc_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a>, <span class="keyword">sizeof</span>(enc_ctx-><a class="code" href="structAVCodecContext.html#a8ff0b000c463361e234af48d03aadfc0" title="samples per second">sample_rate</a>),
<a name="l00291"></a>00291 <a class="code" href="group__avoptions.html#ga25801ba4fc9b5313eb33ec84e082dd72" title="Search in possible children of the given object first.">AV_OPT_SEARCH_CHILDREN</a>);
<a name="l00292"></a>00292 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00293"></a>00293 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Cannot set output sample rate\n"</span>);
<a name="l00294"></a>00294 <span class="keywordflow">goto</span> end;
<a name="l00295"></a>00295 }
<a name="l00296"></a>00296 } <span class="keywordflow">else</span> {
<a name="l00297"></a>00297 ret = <a class="code" href="group__lavu__error.html#ga4ebaa288c7684a26a591c501208910e4" title="Unknown error, typically from an external library.">AVERROR_UNKNOWN</a>;
<a name="l00298"></a>00298 <span class="keywordflow">goto</span> end;
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300
<a name="l00301"></a>00301 <span class="comment">/* Endpoints for the filter graph. */</span>
<a name="l00302"></a>00302 outputs-><a class="code" href="structAVFilterInOut.html#a88afecac258f51aab7e9a9db9e7a4d58" title="unique name for this input/output in the list">name</a> = <a class="code" href="group__lavu__mem.html#ga7c352f4cff02184f005323691375fea9" title="Duplicate the string s.">av_strdup</a>(<span class="stringliteral">"in"</span>);
<a name="l00303"></a>00303 outputs-><a class="code" href="structAVFilterInOut.html#a3227857d0b955b639f4950d13e4e6f40" title="filter context associated to this input/output">filter_ctx</a> = <a class="code" href="filtering__audio_8c.html#a8dce1714a267758c056947f105f66a82">buffersrc_ctx</a>;
<a name="l00304"></a>00304 outputs-><a class="code" href="structAVFilterInOut.html#a386ff90d40aa22f5612dd5eca734ed48" title="index of the filt_ctx pad to use for linking">pad_idx</a> = 0;
<a name="l00305"></a>00305 outputs-><a class="code" href="structAVFilterInOut.html#af8c8cf9ffb650974d19e791f5bb7cf33" title="next input/input in the list, NULL if this is the last">next</a> = NULL;
<a name="l00306"></a>00306
<a name="l00307"></a>00307 inputs-><a class="code" href="structAVFilterInOut.html#a88afecac258f51aab7e9a9db9e7a4d58" title="unique name for this input/output in the list">name</a> = <a class="code" href="group__lavu__mem.html#ga7c352f4cff02184f005323691375fea9" title="Duplicate the string s.">av_strdup</a>(<span class="stringliteral">"out"</span>);
<a name="l00308"></a>00308 inputs-><a class="code" href="structAVFilterInOut.html#a3227857d0b955b639f4950d13e4e6f40" title="filter context associated to this input/output">filter_ctx</a> = <a class="code" href="filtering__audio_8c.html#a5a75197a9aaa609af34cfc0d199acbda">buffersink_ctx</a>;
<a name="l00309"></a>00309 inputs-><a class="code" href="structAVFilterInOut.html#a386ff90d40aa22f5612dd5eca734ed48" title="index of the filt_ctx pad to use for linking">pad_idx</a> = 0;
<a name="l00310"></a>00310 inputs-><a class="code" href="structAVFilterInOut.html#af8c8cf9ffb650974d19e791f5bb7cf33" title="next input/input in the list, NULL if this is the last">next</a> = NULL;
<a name="l00311"></a>00311
<a name="l00312"></a>00312 <span class="keywordflow">if</span> (!outputs-><a class="code" href="structAVFilterInOut.html#a88afecac258f51aab7e9a9db9e7a4d58" title="unique name for this input/output in the list">name</a> || !inputs-><a class="code" href="structAVFilterInOut.html#a88afecac258f51aab7e9a9db9e7a4d58" title="unique name for this input/output in the list">name</a>) {
<a name="l00313"></a>00313 ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00314"></a>00314 <span class="keywordflow">goto</span> end;
<a name="l00315"></a>00315 }
<a name="l00316"></a>00316
<a name="l00317"></a>00317 <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavfi.html#ga34f4ff420bd58da6747a3ff1fbedd001" title="Add a graph described by a string to a graph.">avfilter_graph_parse_ptr</a>(filter_graph, filter_spec,
<a name="l00318"></a>00318 &inputs, &outputs, NULL)) < 0)
<a name="l00319"></a>00319 <span class="keywordflow">goto</span> end;
<a name="l00320"></a>00320
<a name="l00321"></a>00321 <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavfi.html#ga1896c46b7bc6ff1bdb1a4815faa9ad07" title="Check validity and configure all the links and formats in the graph.">avfilter_graph_config</a>(filter_graph, NULL)) < 0)
<a name="l00322"></a>00322 <span class="keywordflow">goto</span> end;
<a name="l00323"></a>00323
<a name="l00324"></a>00324 <span class="comment">/* Fill FilteringContext */</span>
<a name="l00325"></a>00325 fctx-><a class="code" href="structFilteringContext.html#a25c500d3728df3a9f904e6d86cf55f11">buffersrc_ctx</a> = <a class="code" href="filtering__audio_8c.html#a8dce1714a267758c056947f105f66a82">buffersrc_ctx</a>;
<a name="l00326"></a>00326 fctx-><a class="code" href="structFilteringContext.html#a4476c9e6fb492172c909ae4a47c47233">buffersink_ctx</a> = <a class="code" href="filtering__audio_8c.html#a5a75197a9aaa609af34cfc0d199acbda">buffersink_ctx</a>;
<a name="l00327"></a>00327 fctx-><a class="code" href="structFilteringContext.html#aaf35e44d4e6100095b1db444e2d316cd">filter_graph</a> = <a class="code" href="filtering__audio_8c.html#a36c24d3c84d08e2f5a69e7368c211412">filter_graph</a>;
<a name="l00328"></a>00328
<a name="l00329"></a>00329 end:
<a name="l00330"></a>00330 <a class="code" href="group__lavfi.html#ga294500a9856260eb1552354fd9d9a6c4" title="Free the supplied list of AVFilterInOut and set *inout to NULL.">avfilter_inout_free</a>(&inputs);
<a name="l00331"></a>00331 <a class="code" href="group__lavfi.html#ga294500a9856260eb1552354fd9d9a6c4" title="Free the supplied list of AVFilterInOut and set *inout to NULL.">avfilter_inout_free</a>(&outputs);
<a name="l00332"></a>00332
<a name="l00333"></a>00333 <span class="keywordflow">return</span> ret;
<a name="l00334"></a>00334 }
<a name="l00335"></a>00335
<a name="l00336"></a><a class="code" href="transcoding_8c.html#a05c93a3c60f2fc12e3fb7884be1128d6">00336</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#a05c93a3c60f2fc12e3fb7884be1128d6">init_filters</a>(<span class="keywordtype">void</span>)
<a name="l00337"></a>00337 {
<a name="l00338"></a>00338 <span class="keyword">const</span> <span class="keywordtype">char</span> *filter_spec;
<a name="l00339"></a>00339 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00340"></a>00340 <span class="keywordtype">int</span> ret;
<a name="l00341"></a>00341 filter_ctx = <a class="code" href="group__lavu__mem.html#gab62b093b46dce5fe4e3e1d58bdb255da">av_malloc_array</a>(ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>, <span class="keyword">sizeof</span>(*filter_ctx));
<a name="l00342"></a>00342 <span class="keywordflow">if</span> (!filter_ctx)
<a name="l00343"></a>00343 <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00344"></a>00344
<a name="l00345"></a>00345 <span class="keywordflow">for</span> (i = 0; i < ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>; i++) {
<a name="l00346"></a>00346 filter_ctx[i].<a class="code" href="structFilteringContext.html#a25c500d3728df3a9f904e6d86cf55f11">buffersrc_ctx</a> = NULL;
<a name="l00347"></a>00347 filter_ctx[i].<a class="code" href="structFilteringContext.html#a4476c9e6fb492172c909ae4a47c47233">buffersink_ctx</a> = NULL;
<a name="l00348"></a>00348 filter_ctx[i].<a class="code" href="structFilteringContext.html#aaf35e44d4e6100095b1db444e2d316cd">filter_graph</a> = NULL;
<a name="l00349"></a>00349 <span class="keywordflow">if</span> (!(ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48a7b4e33b8f30ac94d34ce8d9f7c33927a">AVMEDIA_TYPE_AUDIO</a>
<a name="l00350"></a>00350 || ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>))
<a name="l00351"></a>00351 <span class="keywordflow">continue</span>;
<a name="l00352"></a>00352
<a name="l00353"></a>00353
<a name="l00354"></a>00354 <span class="keywordflow">if</span> (ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>)
<a name="l00355"></a>00355 filter_spec = <span class="stringliteral">"null"</span>; <span class="comment">/* passthrough (dummy) filter for video */</span>
<a name="l00356"></a>00356 <span class="keywordflow">else</span>
<a name="l00357"></a>00357 filter_spec = <span class="stringliteral">"anull"</span>; <span class="comment">/* passthrough (dummy) filter for audio */</span>
<a name="l00358"></a>00358 ret = <a class="code" href="transcoding_8c.html#a54ad76df48ef886861a2f12bc7a9e7e4">init_filter</a>(&filter_ctx[i], ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>,
<a name="l00359"></a>00359 ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>, filter_spec);
<a name="l00360"></a>00360 <span class="keywordflow">if</span> (ret)
<a name="l00361"></a>00361 <span class="keywordflow">return</span> ret;
<a name="l00362"></a>00362 }
<a name="l00363"></a>00363 <span class="keywordflow">return</span> 0;
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365
<a name="l00366"></a><a class="code" href="transcoding_8c.html#afb371e273a9d2e9cc0539a6453913533">00366</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#afb371e273a9d2e9cc0539a6453913533">encode_write_frame</a>(<a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *filt_frame, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> stream_index, <span class="keywordtype">int</span> *got_frame) {
<a name="l00367"></a>00367 <span class="keywordtype">int</span> ret;
<a name="l00368"></a>00368 <span class="keywordtype">int</span> got_frame_local;
<a name="l00369"></a>00369 <a class="code" href="structAVPacket.html" title="This structure stores compressed data.">AVPacket</a> enc_pkt;
<a name="l00370"></a>00370 int (*enc_func)(<a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *, <a class="code" href="structAVPacket.html" title="This structure stores compressed data.">AVPacket</a> *, <span class="keyword">const</span> <a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *, <span class="keywordtype">int</span> *) =
<a name="l00371"></a>00371 (ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a> ==
<a name="l00372"></a>00372 <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>) ? <a class="code" href="group__lavc__encoding.html#gaa2dc9e9ea2567ebb2801a08153c7306b" title="Encode a frame of video.">avcodec_encode_video2</a> : <a class="code" href="group__lavc__encoding.html#ga93a49fbd0973b216dcb8a8c5dffe1d82" title="Encode a frame of audio.">avcodec_encode_audio2</a>;
<a name="l00373"></a>00373
<a name="l00374"></a>00374 <span class="keywordflow">if</span> (!got_frame)
<a name="l00375"></a>00375 got_frame = &got_frame_local;
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gad172eacfed8653e454c6fdcbe53baab3" title="Standard information.">AV_LOG_INFO</a>, <span class="stringliteral">"Encoding frame\n"</span>);
<a name="l00378"></a>00378 <span class="comment">/* encode filtered frame */</span>
<a name="l00379"></a>00379 enc_pkt.<a class="code" href="structAVPacket.html#aaf4fe58dfcc7c232c1f2268b539d8367">data</a> = NULL;
<a name="l00380"></a>00380 enc_pkt.<a class="code" href="structAVPacket.html#a4d1ea19f63eb107111fd650ca514d1f4">size</a> = 0;
<a name="l00381"></a>00381 <a class="code" href="group__lavc__packet.html#gac9cb9756175b96e7441575803757fb73" title="Initialize optional fields of a packet with default values.">av_init_packet</a>(&enc_pkt);
<a name="l00382"></a>00382 ret = enc_func(ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>, &enc_pkt,
<a name="l00383"></a>00383 filt_frame, got_frame);
<a name="l00384"></a>00384 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&filt_frame);
<a name="l00385"></a>00385 <span class="keywordflow">if</span> (ret < 0)
<a name="l00386"></a>00386 <span class="keywordflow">return</span> ret;
<a name="l00387"></a>00387 <span class="keywordflow">if</span> (!(*got_frame))
<a name="l00388"></a>00388 <span class="keywordflow">return</span> 0;
<a name="l00389"></a>00389
<a name="l00390"></a>00390 <span class="comment">/* prepare packet for muxing */</span>
<a name="l00391"></a>00391 enc_pkt.<a class="code" href="structAVPacket.html#a0d1cb9b5a32b00fb6edc81ea3aae2a49">stream_index</a> = stream_index;
<a name="l00392"></a>00392 <a class="code" href="group__lavc__packet.html#gae5c86e4d93f6e7aa62ef2c60763ea67e" title="Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...">av_packet_rescale_ts</a>(&enc_pkt,
<a name="l00393"></a>00393 ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>,
<a name="l00394"></a>00394 ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a9db755451f14e2bf590d4b85d82b32e6" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>);
<a name="l00395"></a>00395
<a name="l00396"></a>00396 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#ga5b7221c3afd06848486776bd834a58a5" title="Stuff which is only useful for libav* developers.">AV_LOG_DEBUG</a>, <span class="stringliteral">"Muxing frame\n"</span>);
<a name="l00397"></a>00397 <span class="comment">/* mux encoded frame */</span>
<a name="l00398"></a>00398 ret = <a class="code" href="group__lavf__encoding.html#ga37352ed2c63493c38219d935e71db6c1" title="Write a packet to an output media file ensuring correct interleaving.">av_interleaved_write_frame</a>(ofmt_ctx, &enc_pkt);
<a name="l00399"></a>00399 <span class="keywordflow">return</span> ret;
<a name="l00400"></a>00400 }
<a name="l00401"></a>00401
<a name="l00402"></a><a class="code" href="transcoding_8c.html#a255192428438daf73b9f8060c0815712">00402</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#a255192428438daf73b9f8060c0815712">filter_encode_write_frame</a>(<a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *<a class="code" href="demuxing__decoding_8c.html#ad7d33d579a8d4241a5e643e39287a209">frame</a>, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> stream_index)
<a name="l00403"></a>00403 {
<a name="l00404"></a>00404 <span class="keywordtype">int</span> ret;
<a name="l00405"></a>00405 <a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *filt_frame;
<a name="l00406"></a>00406
<a name="l00407"></a>00407 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gad172eacfed8653e454c6fdcbe53baab3" title="Standard information.">AV_LOG_INFO</a>, <span class="stringliteral">"Pushing decoded frame to filters\n"</span>);
<a name="l00408"></a>00408 <span class="comment">/* push the decoded frame into the filtergraph */</span>
<a name="l00409"></a>00409 ret = <a class="code" href="group__lavfi__buffersrc.html#ga54133fc5421777515032c593bc00f191" title="Add a frame to the buffer source.">av_buffersrc_add_frame_flags</a>(filter_ctx[stream_index].<a class="code" href="filtering__audio_8c.html#a8dce1714a267758c056947f105f66a82">buffersrc_ctx</a>,
<a name="l00410"></a>00410 frame, 0);
<a name="l00411"></a>00411 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00412"></a>00412 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Error while feeding the filtergraph\n"</span>);
<a name="l00413"></a>00413 <span class="keywordflow">return</span> ret;
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415
<a name="l00416"></a>00416 <span class="comment">/* pull filtered frames from the filtergraph */</span>
<a name="l00417"></a>00417 <span class="keywordflow">while</span> (1) {
<a name="l00418"></a>00418 filt_frame = <a class="code" href="group__lavu__frame.html#gac700017c5270c79c1e1befdeeb008b2f" title="Allocate an AVFrame and set its fields to default values.">av_frame_alloc</a>();
<a name="l00419"></a>00419 <span class="keywordflow">if</span> (!filt_frame) {
<a name="l00420"></a>00420 ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00421"></a>00421 <span class="keywordflow">break</span>;
<a name="l00422"></a>00422 }
<a name="l00423"></a>00423 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gad172eacfed8653e454c6fdcbe53baab3" title="Standard information.">AV_LOG_INFO</a>, <span class="stringliteral">"Pulling filtered frame from filters\n"</span>);
<a name="l00424"></a>00424 ret = <a class="code" href="group__lavfi__buffersink.html#ga653228f4cbca427c654d844a5fc59cfa" title="Get a frame with filtered data from sink and put it in frame.">av_buffersink_get_frame</a>(filter_ctx[stream_index].<a class="code" href="filtering__audio_8c.html#a5a75197a9aaa609af34cfc0d199acbda">buffersink_ctx</a>,
<a name="l00425"></a>00425 filt_frame);
<a name="l00426"></a>00426 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00427"></a>00427 <span class="comment">/* if no more frames for output - returns AVERROR(EAGAIN)</span>
<a name="l00428"></a>00428 <span class="comment"> * if flushed and no more frames for output - returns AVERROR_EOF</span>
<a name="l00429"></a>00429 <span class="comment"> * rewrite retcode to 0 to show it as normal procedure completion</span>
<a name="l00430"></a>00430 <span class="comment"> */</span>
<a name="l00431"></a>00431 <span class="keywordflow">if</span> (ret == <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(EAGAIN) || ret == <a class="code" href="group__lavu__error.html#gab4faa0afdf35076914824200331defff" title="End of file.">AVERROR_EOF</a>)
<a name="l00432"></a>00432 ret = 0;
<a name="l00433"></a>00433 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&filt_frame);
<a name="l00434"></a>00434 <span class="keywordflow">break</span>;
<a name="l00435"></a>00435 }
<a name="l00436"></a>00436
<a name="l00437"></a>00437 filt_frame-><a class="code" href="structAVFrame.html#af9920fc3fbfa347b8943ae461b50d18b" title="Picture type of the frame.">pict_type</a> = <a class="code" href="group__lavu__picture.html#ggae6cbcab1f70d8e476757f1c1f5a0a78ea33183189d771e3325ccdd36fa980b6f6" title="Undefined.">AV_PICTURE_TYPE_NONE</a>;
<a name="l00438"></a>00438 ret = <a class="code" href="transcoding_8c.html#afb371e273a9d2e9cc0539a6453913533">encode_write_frame</a>(filt_frame, stream_index, NULL);
<a name="l00439"></a>00439 <span class="keywordflow">if</span> (ret < 0)
<a name="l00440"></a>00440 <span class="keywordflow">break</span>;
<a name="l00441"></a>00441 }
<a name="l00442"></a>00442
<a name="l00443"></a>00443 <span class="keywordflow">return</span> ret;
<a name="l00444"></a>00444 }
<a name="l00445"></a>00445
<a name="l00446"></a><a class="code" href="transcoding_8c.html#ad55ba3d9c6ebe490eb8766a91b627d3e">00446</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="transcoding_8c.html#ad55ba3d9c6ebe490eb8766a91b627d3e">flush_encoder</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> stream_index)
<a name="l00447"></a>00447 {
<a name="l00448"></a>00448 <span class="keywordtype">int</span> ret;
<a name="l00449"></a>00449 <span class="keywordtype">int</span> got_frame;
<a name="l00450"></a>00450
<a name="l00451"></a>00451 <span class="keywordflow">if</span> (!(ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#ab00398f08f8622c3e6c0f1a12eb99808">codec</a>-><a class="code" href="structAVCodec.html#af51f7ff3dac8b730f46b9713e49a2518" title="Codec capabilities.">capabilities</a> &
<a name="l00452"></a>00452 <a class="code" href="group__lavc__core.html#gad81abca6e6ea7e0ac25f328e7425698f" title="Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...">CODEC_CAP_DELAY</a>))
<a name="l00453"></a>00453 <span class="keywordflow">return</span> 0;
<a name="l00454"></a>00454
<a name="l00455"></a>00455 <span class="keywordflow">while</span> (1) {
<a name="l00456"></a>00456 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gad172eacfed8653e454c6fdcbe53baab3" title="Standard information.">AV_LOG_INFO</a>, <span class="stringliteral">"Flushing stream #%u encoder\n"</span>, stream_index);
<a name="l00457"></a>00457 ret = <a class="code" href="transcoding_8c.html#afb371e273a9d2e9cc0539a6453913533">encode_write_frame</a>(NULL, stream_index, &got_frame);
<a name="l00458"></a>00458 <span class="keywordflow">if</span> (ret < 0)
<a name="l00459"></a>00459 <span class="keywordflow">break</span>;
<a name="l00460"></a>00460 <span class="keywordflow">if</span> (!got_frame)
<a name="l00461"></a>00461 <span class="keywordflow">return</span> 0;
<a name="l00462"></a>00462 }
<a name="l00463"></a>00463 <span class="keywordflow">return</span> ret;
<a name="l00464"></a>00464 }
<a name="l00465"></a>00465
<a name="l00466"></a><a class="code" href="transcoding_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">00466</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="l00467"></a>00467 {
<a name="l00468"></a>00468 <span class="keywordtype">int</span> ret;
<a name="l00469"></a>00469 <a class="code" href="structAVPacket.html" title="This structure stores compressed data.">AVPacket</a> packet = { .<a class="code" href="structAVPacket.html#aaf4fe58dfcc7c232c1f2268b539d8367">data</a> = NULL, .size = 0 };
<a name="l00470"></a>00470 <a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *<a class="code" href="demuxing__decoding_8c.html#ad7d33d579a8d4241a5e643e39287a209">frame</a> = NULL;
<a name="l00471"></a>00471 <span class="keyword">enum</span> <a class="code" href="group__lavu__misc.html#ga9a84bba4713dfced21a1a56163be1f48">AVMediaType</a> type;
<a name="l00472"></a>00472 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> stream_index;
<a name="l00473"></a>00473 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00474"></a>00474 <span class="keywordtype">int</span> got_frame;
<a name="l00475"></a>00475 int (*dec_func)(<a class="code" href="structAVCodecContext.html" title="main external API structure.">AVCodecContext</a> *, <a class="code" href="structAVFrame.html" title="This structure describes decoded (raw) audio or video data.">AVFrame</a> *, <span class="keywordtype">int</span> *, <span class="keyword">const</span> <a class="code" href="structAVPacket.html" title="This structure stores compressed data.">AVPacket</a> *);
<a name="l00476"></a>00476
<a name="l00477"></a>00477 <span class="keywordflow">if</span> (argc != 3) {
<a name="l00478"></a>00478 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Usage: %s <input file> <output file>\n"</span>, argv[0]);
<a name="l00479"></a>00479 <span class="keywordflow">return</span> 1;
<a name="l00480"></a>00480 }
<a name="l00481"></a>00481
<a name="l00482"></a>00482 <a class="code" href="group__lavf__core.html#ga917265caec45ef5a0646356ed1a507e3" title="Initialize libavformat and register all the muxers, demuxers and protocols.">av_register_all</a>();
<a name="l00483"></a>00483 <a class="code" href="group__lavfi.html#ga2bf8f0a6e2599faf4bf97b04a5a25149" title="Initialize the filter system.">avfilter_register_all</a>();
<a name="l00484"></a>00484
<a name="l00485"></a>00485 <span class="keywordflow">if</span> ((ret = <a class="code" href="transcoding_8c.html#abd04bf1a933d4d2698482f4949c61fed">open_input_file</a>(argv[1])) < 0)
<a name="l00486"></a>00486 <span class="keywordflow">goto</span> end;
<a name="l00487"></a>00487 <span class="keywordflow">if</span> ((ret = <a class="code" href="transcoding_8c.html#ab6c33edf9a42e2f71594a7cdc6276407">open_output_file</a>(argv[2])) < 0)
<a name="l00488"></a>00488 <span class="keywordflow">goto</span> end;
<a name="l00489"></a>00489 <span class="keywordflow">if</span> ((ret = <a class="code" href="transcoding_8c.html#a05c93a3c60f2fc12e3fb7884be1128d6">init_filters</a>()) < 0)
<a name="l00490"></a>00490 <span class="keywordflow">goto</span> end;
<a name="l00491"></a>00491
<a name="l00492"></a>00492 <span class="comment">/* read all packets */</span>
<a name="l00493"></a>00493 <span class="keywordflow">while</span> (1) {
<a name="l00494"></a>00494 <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lavf__decoding.html#ga4fdb3084415a82e3810de6ee60e46a61" title="Return the next frame of a stream.">av_read_frame</a>(ifmt_ctx, &packet)) < 0)
<a name="l00495"></a>00495 <span class="keywordflow">break</span>;
<a name="l00496"></a>00496 stream_index = packet.<a class="code" href="structAVPacket.html#a0d1cb9b5a32b00fb6edc81ea3aae2a49">stream_index</a>;
<a name="l00497"></a>00497 type = ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[packet.<a class="code" href="structAVPacket.html#a0d1cb9b5a32b00fb6edc81ea3aae2a49">stream_index</a>]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#a3f99ca3115c44e6d7772c9384faf15e6">codec_type</a>;
<a name="l00498"></a>00498 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#ga5b7221c3afd06848486776bd834a58a5" title="Stuff which is only useful for libav* developers.">AV_LOG_DEBUG</a>, <span class="stringliteral">"Demuxer gave frame of stream_index %u\n"</span>,
<a name="l00499"></a>00499 stream_index);
<a name="l00500"></a>00500
<a name="l00501"></a>00501 <span class="keywordflow">if</span> (filter_ctx[stream_index].<a class="code" href="filtering__audio_8c.html#a36c24d3c84d08e2f5a69e7368c211412">filter_graph</a>) {
<a name="l00502"></a>00502 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#ga5b7221c3afd06848486776bd834a58a5" title="Stuff which is only useful for libav* developers.">AV_LOG_DEBUG</a>, <span class="stringliteral">"Going to reencode&filter the frame\n"</span>);
<a name="l00503"></a>00503 frame = <a class="code" href="group__lavu__frame.html#gac700017c5270c79c1e1befdeeb008b2f" title="Allocate an AVFrame and set its fields to default values.">av_frame_alloc</a>();
<a name="l00504"></a>00504 <span class="keywordflow">if</span> (!frame) {
<a name="l00505"></a>00505 ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00506"></a>00506 <span class="keywordflow">break</span>;
<a name="l00507"></a>00507 }
<a name="l00508"></a>00508 <a class="code" href="group__lavc__packet.html#gae5c86e4d93f6e7aa62ef2c60763ea67e" title="Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...">av_packet_rescale_ts</a>(&packet,
<a name="l00509"></a>00509 ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a9db755451f14e2bf590d4b85d82b32e6" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>,
<a name="l00510"></a>00510 ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>-><a class="code" href="structAVCodecContext.html#ab7bfeb9fa5840aac090e2b0bd0ef7589" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>);
<a name="l00511"></a>00511 dec_func = (type == <a class="code" href="group__lavu__misc.html#gga9a84bba4713dfced21a1a56163be1f48ac1a46f59be5c6c2d3412ab172d6b8cf5">AVMEDIA_TYPE_VIDEO</a>) ? <a class="code" href="group__lavc__decoding.html#ga99ee61b6dcffb7817a275d39da58cc74" title="Decode the video frame of size avpkt->size from avpkt->data into picture.">avcodec_decode_video2</a> :
<a name="l00512"></a>00512 <a class="code" href="group__lavc__decoding.html#ga834bb1b062fbcc2de4cf7fb93f154a3e" title="Decode the audio frame of size avpkt->size from avpkt->data into frame.">avcodec_decode_audio4</a>;
<a name="l00513"></a>00513 ret = dec_func(ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>, frame,
<a name="l00514"></a>00514 &got_frame, &packet);
<a name="l00515"></a>00515 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00516"></a>00516 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&frame);
<a name="l00517"></a>00517 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Decoding failed\n"</span>);
<a name="l00518"></a>00518 <span class="keywordflow">break</span>;
<a name="l00519"></a>00519 }
<a name="l00520"></a>00520
<a name="l00521"></a>00521 <span class="keywordflow">if</span> (got_frame) {
<a name="l00522"></a>00522 frame-><a class="code" href="structAVFrame.html#a0452833e3ab6ddd7acbf82817a7818a4" title="Presentation timestamp in time_base units (time when frame should be shown to user).">pts</a> = <a class="code" href="group__lavu__frame.html#gacb9d9082c10e625e51a68caceabd4458" title="Accessors for some AVFrame fields.">av_frame_get_best_effort_timestamp</a>(frame);
<a name="l00523"></a>00523 ret = <a class="code" href="transcoding_8c.html#a255192428438daf73b9f8060c0815712">filter_encode_write_frame</a>(frame, stream_index);
<a name="l00524"></a>00524 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&frame);
<a name="l00525"></a>00525 <span class="keywordflow">if</span> (ret < 0)
<a name="l00526"></a>00526 <span class="keywordflow">goto</span> end;
<a name="l00527"></a>00527 } <span class="keywordflow">else</span> {
<a name="l00528"></a>00528 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&frame);
<a name="l00529"></a>00529 }
<a name="l00530"></a>00530 } <span class="keywordflow">else</span> {
<a name="l00531"></a>00531 <span class="comment">/* remux this frame without reencoding */</span>
<a name="l00532"></a>00532 <a class="code" href="group__lavc__packet.html#gae5c86e4d93f6e7aa62ef2c60763ea67e" title="Convert valid timing fields (timestamps / durations) in a packet from one timebase to another...">av_packet_rescale_ts</a>(&packet,
<a name="l00533"></a>00533 ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a9db755451f14e2bf590d4b85d82b32e6" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>,
<a name="l00534"></a>00534 ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[stream_index]-><a class="code" href="structAVStream.html#a9db755451f14e2bf590d4b85d82b32e6" title="This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...">time_base</a>);
<a name="l00535"></a>00535
<a name="l00536"></a>00536 ret = <a class="code" href="group__lavf__encoding.html#ga37352ed2c63493c38219d935e71db6c1" title="Write a packet to an output media file ensuring correct interleaving.">av_interleaved_write_frame</a>(ofmt_ctx, &packet);
<a name="l00537"></a>00537 <span class="keywordflow">if</span> (ret < 0)
<a name="l00538"></a>00538 <span class="keywordflow">goto</span> end;
<a name="l00539"></a>00539 }
<a name="l00540"></a>00540 <a class="code" href="group__lavc__packet.html#gae65881462e78f98b268f34661d921ee0" title="Free a packet.">av_free_packet</a>(&packet);
<a name="l00541"></a>00541 }
<a name="l00542"></a>00542
<a name="l00543"></a>00543 <span class="comment">/* flush filters and encoders */</span>
<a name="l00544"></a>00544 <span class="keywordflow">for</span> (i = 0; i < ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>; i++) {
<a name="l00545"></a>00545 <span class="comment">/* flush filter */</span>
<a name="l00546"></a>00546 <span class="keywordflow">if</span> (!filter_ctx[i].<a class="code" href="filtering__audio_8c.html#a36c24d3c84d08e2f5a69e7368c211412">filter_graph</a>)
<a name="l00547"></a>00547 <span class="keywordflow">continue</span>;
<a name="l00548"></a>00548 ret = <a class="code" href="transcoding_8c.html#a255192428438daf73b9f8060c0815712">filter_encode_write_frame</a>(NULL, i);
<a name="l00549"></a>00549 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00550"></a>00550 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Flushing filter failed\n"</span>);
<a name="l00551"></a>00551 <span class="keywordflow">goto</span> end;
<a name="l00552"></a>00552 }
<a name="l00553"></a>00553
<a name="l00554"></a>00554 <span class="comment">/* flush encoder */</span>
<a name="l00555"></a>00555 ret = <a class="code" href="transcoding_8c.html#ad55ba3d9c6ebe490eb8766a91b627d3e">flush_encoder</a>(i);
<a name="l00556"></a>00556 <span class="keywordflow">if</span> (ret < 0) {
<a name="l00557"></a>00557 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Flushing encoder failed\n"</span>);
<a name="l00558"></a>00558 <span class="keywordflow">goto</span> end;
<a name="l00559"></a>00559 }
<a name="l00560"></a>00560 }
<a name="l00561"></a>00561
<a name="l00562"></a>00562 <a class="code" href="group__lavf__encoding.html#ga7f14007e7dc8f481f054b21614dfec13" title="Write the stream trailer to an output media file and free the file private data.">av_write_trailer</a>(ofmt_ctx);
<a name="l00563"></a>00563 end:
<a name="l00564"></a>00564 <a class="code" href="group__lavc__packet.html#gae65881462e78f98b268f34661d921ee0" title="Free a packet.">av_free_packet</a>(&packet);
<a name="l00565"></a>00565 <a class="code" href="group__lavu__frame.html#ga979d73f3228814aee56aeca0636e37cc" title="Free the frame and any dynamically allocated objects in it, e.g.">av_frame_free</a>(&frame);
<a name="l00566"></a>00566 <span class="keywordflow">for</span> (i = 0; i < ifmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a>; i++) {
<a name="l00567"></a>00567 <a class="code" href="group__lavc__core.html#gaf4daa92361efb3523ef5afeb0b54077f" title="Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...">avcodec_close</a>(ifmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>);
<a name="l00568"></a>00568 <span class="keywordflow">if</span> (ofmt_ctx && ofmt_ctx-><a class="code" href="structAVFormatContext.html#a0b748d924898b08b89ff4974afd17285" title="Number of elements in AVFormatContext.streams.">nb_streams</a> > i && ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i] && ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>)
<a name="l00569"></a>00569 <a class="code" href="group__lavc__core.html#gaf4daa92361efb3523ef5afeb0b54077f" title="Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...">avcodec_close</a>(ofmt_ctx-><a class="code" href="structAVFormatContext.html#acfefb6b6cf21e87a0dcbd1a547ba2348" title="A list of all streams in the file.">streams</a>[i]-><a class="code" href="structAVStream.html#a56f20051fb99339cc588cd3a07ab8c96" title="Codec context associated with this stream.">codec</a>);
<a name="l00570"></a>00570 <span class="keywordflow">if</span> (filter_ctx && filter_ctx[i].<a class="code" href="filtering__audio_8c.html#a36c24d3c84d08e2f5a69e7368c211412">filter_graph</a>)
<a name="l00571"></a>00571 <a class="code" href="group__lavfi.html#ga871684449dac05050df238a18d0d493b" title="Free a graph, destroy its links, and set *graph to NULL.">avfilter_graph_free</a>(&filter_ctx[i].filter_graph);
<a name="l00572"></a>00572 }
<a name="l00573"></a>00573 <a class="code" href="group__lavu__mem.html#ga0c9096f498624c525aa2315b8a20c411" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc().">av_free</a>(filter_ctx);
<a name="l00574"></a>00574 <a class="code" href="group__lavf__decoding.html#gae804b99aec044690162b8b9b110236a4" title="Close an opened input AVFormatContext.">avformat_close_input</a>(&ifmt_ctx);
<a name="l00575"></a>00575 <span class="keywordflow">if</span> (ofmt_ctx && !(ofmt_ctx-><a class="code" href="structAVFormatContext.html#a20d80ac07e38ff5c268d15aaf2798b98" title="The output container format.">oformat</a>-><a class="code" href="structAVOutputFormat.html#aad55a00e728a020c1dcfaaf695320445" title="can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT">flags</a> & <a class="code" href="avformat_8h.html#a752cce390d480521919aa5d8be24ac0b" title="Demuxer will use avio_open, no opened file should be provided by the caller.">AVFMT_NOFILE</a>))
<a name="l00576"></a>00576 <a class="code" href="avio_8h.html#ae118a1f37f1e48617609ead9910aac15" title="Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...">avio_closep</a>(&ofmt_ctx-><a class="code" href="structAVFormatContext.html#a1e7324262b6b78522e52064daaa7bc87" title="I/O context.">pb</a>);
<a name="l00577"></a>00577 <a class="code" href="group__lavf__core.html#gac2990b13b68e831a408fce8e1d0d6445" title="Free an AVFormatContext and all its streams.">avformat_free_context</a>(ofmt_ctx);
<a name="l00578"></a>00578
<a name="l00579"></a>00579 <span class="keywordflow">if</span> (ret < 0)
<a name="l00580"></a>00580 <a class="code" href="group__lavu__log.html#gabd386ffd4b27637cf34e98d5d1a6e8ae" title="Send the specified message to the log if the level is less than or equal to the current av_log_level...">av_log</a>(NULL, <a class="code" href="group__lavu__log__constants.html#gaffe151ff4cd8a24b2e77ac8d9616c85c" title="Something went wrong and cannot losslessly be recovered.">AV_LOG_ERROR</a>, <span class="stringliteral">"Error occurred: %s\n"</span>, <a class="code" href="group__lavu__error.html#gac4f6e109c242c81aeee21868d3f35e12" title="Convenience macro, the return value should be used only directly in function arguments but never stan...">av_err2str</a>(ret));
<a name="l00581"></a>00581
<a name="l00582"></a>00582 <span class="keywordflow">return</span> ret ? 1 : 0;
<a name="l00583"></a>00583 }
</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"> </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>