/*
* Copyright (c) 2013-2022 Andreas Unterweger
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file audio transcoding to MPEG/AAC API usage example
* @example transcode_aac.c
*
* Convert an input audio file to AAC in an MP4 container. Formats other than
* MP4 are supported based on the output file extension.
* @author Andreas Unterweger (dustsigns@gmail.com)
*/
#include <stdio.h>
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include "libavcodec/avcodec.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/frame.h"
#include "libavutil/opt.h"
#include "libswresample/swresample.h"
/* The output bit rate in bit/s */
#define OUTPUT_BIT_RATE 96000
/* The number of output channels */
#define OUTPUT_CHANNELS 2
/**
* Open an input file and the required decoder.
* @param filename File to be opened
* @param[out] input_format_context Format context of opened file
* @param[out] input_codec_context Codec context of opened file
* @return Error code (0 if successful)
*/
static int open_input_file(const char *filename,
AVFormatContext **input_format_context,
AVCodecContext **input_codec_context)
{
AVCodecContext *avctx;
const AVCodec *input_codec;
const AVStream *stream;
int error;
/* Open the input file to read from it. */
if ((error = avformat_open_input(input_format_context, filename, NULL,
NULL)) < 0) {
fprintf(stderr, "Could not open input file '%s' (error '%s')\n",
filename, av_err2str(error));
*input_format_context = NULL;
return error;
}
/* Get information on the input file (number of streams etc.). */
if ((error = avformat_find_stream_info(*input_format_context, NULL)) < 0) {
fprintf(stderr, "Could not open find stream info (error '%s')\n",
av_err2str(error));
avformat_close_input(input_format_context);
return error;
}
/* Make sure that there is only one stream in the input file. */
if ((*input_format_context)->nb_streams != 1) {
fprintf(stderr, "Expected one audio input stream, but found %d\n",
(*input_format_context)->nb_streams);
avformat_close_input(input_format_context);
return AVERROR_EXIT;
}
stream = (*input_format_context)->streams[0];
/* Find a decoder for the audio stream. */
if (!(input_codec = avcodec_find_decoder(stream->codecpar->codec_id))) {
fprintf(stderr, "Could not find input codec\n");
avformat_close_input(input_format_context);
return AVERROR_EXIT;
}
/* Allocate a new decoding context. */
avctx = avcodec_alloc_context3(input_codec);
if (!avctx) {
fprintf(stderr, "Could not allocate a decoding context\n");
avformat_close_input(input_format_context);
return AVERROR(ENOMEM);
}
/* Initialize the stream parameters with demuxer information. */
error = avcodec_parameters_to_context(avctx, stream->codecpar);
if (error < 0) {
avformat_close_input(input_format_context);
avcodec_free_context(&avctx);
return error;
}
/* Open the decoder for the audio stream to use it later. */
if ((error = avcodec_open2(avctx, input_codec, NULL)) < 0) {
fprintf(stderr, "Could not open input codec (error '%s')\n",
av_err2str(error));
avcodec_free_context(&avctx);
avformat_close_input(input_format_context);
return error;
}
/* Set the packet timebase for the decoder. */
avctx->pkt_timebase = stream->time_base;
/* Save the decoder context for easier access later. */
*input_codec_context = avctx;
return 0;
}
/**
* Open an output file and the required encoder.
* Also set some basic encoder parameters.
* Some of these parameters are based on the input file's parameters.
* @param filename File to be opened
* @param input_codec_context Codec context of input file
* @param[out] output_format_context Format context of output file
* @param[out] output_codec_context Codec context of output file
* @return Error code (0 if successful)
*/
static int open_output_file(const char *filename,
AVCodecContext *input_codec_context,
AVFormatContext **output_format_context,
AVCodecContext **output_codec_context)
{
AVCodecContext *avctx = NULL;
AVIOContext *output_io_context = NULL;
AVStream *stream = NULL;
const AVCodec *output_codec = NULL;
int error;
/* Open the output file to write to it. */
if ((error = avio_open(&output_io_context, filename,
AVIO_FLAG_WRITE)) < 0) {
fprintf(stderr, "Could not open output file '%s' (error '%s')\n",
filename, av_err2str(error));
return error;
}
/* Create a new format context for the output container format. */
if (!(*output_format_context = avformat_alloc_context())) {
fprintf(stderr, "Could not allocate output format context\n");
return AVERROR(ENOMEM);
}
/* Associate the output file (pointer) with the container format context. */
(*output_format_context)->pb = output_io_context;
/* Guess the desired container format based on the file extension. */
if (!((*output_format_context)->oformat = av_guess_format(NULL, filename,
NULL))) {
fprintf(stderr, "Could not find output file format\n");
goto cleanup;
}
if (!((*output_format_context)->url = av_strdup(filename))) {
fprintf(stderr, "Could not allocate url.\n");
error = AVERROR(ENOMEM);
goto cleanup;
}
/* Find the encoder to be used by its name. */
if (!(output_codec = avcodec_find_encoder(AV_CODEC_ID_AAC))) {
fprintf(stderr, "Could not find an AAC encoder.\n");
goto cleanup;
}
/* Create a new audio stream in the output file container. */
if (!(stream = avformat_new_stream(*output_format_context, NULL))) {
fprintf(stderr, "Could not create new stream\n");
error = AVERROR(ENOMEM);
goto cleanup;
}
avctx = avcodec_alloc_context3(output_codec);
if (!avctx) {
fprintf(stderr, "Could not allocate an encoding context\n");
error = AVERROR(ENOMEM);
goto cleanup;
}
/* Set the basic encoder parameters.
* The input file's sample rate is used to avoid a sample rate conversion. */
av_channel_layout_default(&avctx->ch_layout, OUTPUT_CHANNELS);
avctx->sample_rate = input_codec_context->sample_rate;
avctx->sample_fmt = output_codec->sample_fmts[0];
avctx->bit_rate = OUTPUT_BIT_RATE;
/* Set the sample rate for the container. */
stream->time_base.den = input_codec_context->sample_rate;
stream->time_base.num = 1;
/* Some container formats (like MP4) require global headers to be present.
* Mark the encoder so that it behaves accordingly. */
没有合适的资源?快使用搜索试试~ 我知道了~
FFMPEG 6.0 ubuntu20.04 编译好的文件
共204个文件
h:138个
c:24个
so:8个
5星 · 超过95%的资源 需积分: 1 10 下载量 135 浏览量
2023-04-15
13:17:45
上传
评论
收藏 88.4MB ZIP 举报
温馨提示
FFMPEG 6.0 ubuntu20.04 编译好的文件 支持rtsp http https x264 x265
资源推荐
资源详情
资源评论
收起资源包目录
FFMPEG 6.0 ubuntu20.04 编译好的文件 (204个子文件)
libavcodec.so.60.9.100 13.22MB
libavfilter.so.9.5.100 4.29MB
libavutil.so.58.6.100 903KB
libswscale.so.7.2.100 566KB
libswresample.so.4.11.100 126KB
libavdevice.so.60.2.100 108KB
libpostproc.so.57.2.100 70KB
libavformat.so.60.4.101 2.51MB
libswresample.so.4 25B
libpostproc.so.57 23B
libavutil.so.58 21B
libavformat.so.60 23B
libavdevice.so.60 23B
libavcodec.so.60 22B
libswscale.so.7 21B
libavfilter.so.9 22B
libavcodec.a 199.98MB
libavfilter.a 57.32MB
libavformat.a 54.45MB
libavutil.a 7.31MB
libswscale.a 7.3MB
libavdevice.a 2.2MB
libswresample.a 827KB
libpostproc.a 556KB
transcode_aac.c 34KB
transcode.c 22KB
mux.c 20KB
qsv_transcode.c 15KB
demux_decode.c 13KB
filter_audio.c 12KB
decode_filter_audio.c 10KB
vaapi_transcode.c 10KB
decode_filter_video.c 9KB
resample_audio.c 8KB
hw_decode.c 8KB
decode_audio.c 7KB
qsv_decode.c 7KB
vaapi_encode.c 7KB
encode_audio.c 7KB
encode_video.c 6KB
remux.c 6KB
extract_mvs.c 6KB
decode_video.c 5KB
avio_http_serve_files.c 5KB
scale_video.c 5KB
avio_list_dir.c 4KB
avio_read_callback.c 4KB
show_metadata.c 2KB
avcodec.h 115KB
avformat.h 107KB
avfilter.h 55KB
pixfmt.h 40KB
opt.h 36KB
frame.h 33KB
channel_layout.h 32KB
avio.h 31KB
swresample.h 25KB
hwcontext.h 24KB
packet.h 23KB
mem.h 20KB
intreadwrite.h 18KB
codec_id.h 17KB
common.h 17KB
swscale.h 16KB
pixdesc.h 16KB
fifo.h 15KB
avstring.h 15KB
hdr_dynamic_metadata.h 14KB
imgutils.h 14KB
avdevice.h 13KB
codec.h 13KB
log.h 12KB
buffer.h 12KB
bsf.h 11KB
samplefmt.h 10KB
hdr_dynamic_vivid_metadata.h 10KB
avutil.h 10KB
hwcontext_vulkan.h 9KB
dict.h 9KB
bprint.h 8KB
film_grain_params.h 8KB
hash.h 8KB
mathematics.h 8KB
spherical.h 8KB
parseutils.h 8KB
timecode.h 8KB
dovi_meta.h 7KB
codec_par.h 7KB
encryption_info.h 7KB
buffersink.h 7KB
buffersrc.h 7KB
defs.h 7KB
hwcontext_d3d11va.h 7KB
eval.h 6KB
cpu.h 6KB
xvmc.h 6KB
tx.h 6KB
rational.h 6KB
video_enc_params.h 6KB
audio_fifo.h 6KB
共 204 条
- 1
- 2
- 3
资源评论
- 无能为力就要努力2023-07-25这个编译好的文件给我留下了深刻的印象,它提供了丰富的功能和工具,让我可以轻松地处理各种音视频文件。
- 经年哲思2023-07-25我很喜欢这个编译好的文件,它的操作界面简洁明了,功能强大,让我可以方便地完成我所需的所有音视频处理任务。
- 卡哥Carlos2023-07-25FFMPEG 6.0编译好的文件对于我来说非常实用,它帮助我快速编辑和处理多媒体文件。
- 普通网友2023-07-25作为一个Ubuntu用户,我发现这个编译好的文件与系统完美地配合,在使用过程中没有出现任何兼容性问题。
- 英次2023-07-25这个编译好的文件非常稳定,我在Ubuntu20.04上使用了一段时间,没有遇到任何问题。
成长的小树
- 粉丝: 31
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功