/*
* Copyright (c) 2010 Nicolas George
* Copyright (c) 2011 Stefano Sabatini
* Copyright (c) 2014 Andrey Utkin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file
* API example for demuxing, decoding, filtering, encoding and muxing
* @example transcoding.c
*/
{
int ret;
unsigned int i;
return ret;
}
return ret;
}
codec_ctx = stream->
codec;
/* Reencode video & audio and remux subtitles etc. */
/* Open decoder */
if (ret < 0) {
return ret;
}
}
}
return 0;
}
{
int ret;
unsigned int i;
if (!ofmt_ctx) {
}
if (!out_stream) {
}
dec_ctx = in_stream->
codec;
enc_ctx = out_stream->
codec;
/* in this example, we choose transcoding to same codec */
if (!encoder) {
}
/* In this example, we transcode to same properties (picture size,
* sample rate etc.). These properties can be changed for output
* streams easily using filters */
/* take first format from list of supported formats */
/* video time_base can be set to whatever is handy and supported by encoder */
} else {
/* take first format from list of supported formats */
}
/* Third parameter can be used to pass settings to encoder */
if (ret < 0) {
return ret;
}
} else {
/* if this stream must be remuxed */
if (ret < 0) {
return ret;
}
}
}
if (ret < 0) {
return ret;
}
}
/* init muxer, write output file header */
if (ret < 0) {
return ret;
}
return 0;
}
{
int ret = 0;
if (!outputs || !inputs || !filter_graph) {
}
if (!buffersrc || !buffersink) {
}
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
args,
NULL, filter_graph);
if (ret < 0) {
}
if (ret < 0) {
}
if (ret < 0) {
}
if (!buffersrc || !buffersink) {
}
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"PRIx64,
args,
NULL, filter_graph);
if (ret < 0) {
}
if (ret < 0) {
}
if (ret < 0) {
}
if (ret < 0) {
}
if (ret < 0) {
}
} else {
}
/* Endpoints for the filter graph. */
}
&inputs, &outputs,
NULL)) < 0)
/* Fill FilteringContext */
return ret;
}
{
const char *filter_spec;
unsigned int i;
int ret;
if (!filter_ctx)
continue;
filter_spec = "null"; /* passthrough (dummy) filter for video */
else
filter_spec = "anull"; /* passthrough (dummy) filter for audio */
if (ret)
return ret;
}
return 0;
}
int ret;
int got_frame_local;
if (!got_frame)
got_frame = &got_frame_local;
/* encode filtered frame */
ret = enc_func(ofmt_ctx->
streams[stream_index]->
codec, &enc_pkt,
filt_frame, got_frame);
if (ret < 0)
return ret;
if (!(*got_frame))
return 0;
/* prepare packet for muxing */
/* mux encoded frame */
return ret;
}
{
int ret;
AVFrame *filt_frame;
/* push the decoded frame into the filtergraph */
frame, 0);
if (ret < 0) {
return ret;
}
/* pull filtered frames from the filtergraph */
while (1) {
if (!filt_frame) {
break;
}
filt_frame);
if (ret < 0) {
/* if no more frames for output - returns AVERROR(EAGAIN)
* if flushed and no more frames for output - returns AVERROR_EOF
* rewrite retcode to 0 to show it as normal procedure completion
*/
ret = 0;
break;
}
if (ret < 0)
break;
}
return ret;
}
{
int ret;
int got_frame;
return 0;
while (1) {
if (ret < 0)
break;
if (!got_frame)
return 0;
}
return ret;
}
int main(
int argc,
char **argv)
{
int ret;
AVPacket packet = { .data =
NULL, .size = 0 };
unsigned int stream_index;
unsigned int i;
int got_frame;
int (*dec_func)(
AVCodecContext *, AVFrame *,
int *,
const AVPacket *);
if (argc != 3) {
return 1;
}
/* read all packets */
while (1) {
break;
stream_index);
if (filter_ctx[stream_index].filter_graph) {
if (!frame) {
break;
}
ret = dec_func(ifmt_ctx->
streams[stream_index]->
codec, frame,
&got_frame, &packet);
if (ret < 0) {
break;
}
if (got_frame) {
if (ret < 0)
} else {
}
} else {
/* remux this frame without reencoding */
if (ret < 0)
}
}
/* flush filters and encoders */
/* flush filter */
if (!filter_ctx[i].filter_graph)
continue;
if (ret < 0) {
}
/* flush encoder */
if (ret < 0) {
}
}
if (filter_ctx && filter_ctx[i].filter_graph)
}
if (ret < 0)
return ret ? 1 : 0;
}