/*
* 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
* simple audio converter
*
* @example transcode_aac.c
* Convert an input audio file to AAC in an MP4 container using FFmpeg.
* @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/frame.h"
#include "libavutil/opt.h"
#include "libswresample/swresample.h"
/** The output bit rate in kbit/s */
#define OUTPUT_BIT_RATE 48000
/** The number of output channels */
#define OUTPUT_CHANNELS 2
/** The audio sample output format */
#define OUTPUT_SAMPLE_FORMAT AV_SAMPLE_FMT_S16
/**
* Convert an error code into a text message.
* @param error Error code to be converted
* @return Corresponding error text (not thread-safe)
*/
static char *const get_error_text(const int error)
{
static char error_buffer[255];
av_strerror(error, error_buffer, sizeof(error_buffer));
return error_buffer;
}
/** Open an input file and the required decoder. */
static int open_input_file(const char *filename,
AVFormatContext **input_format_context,
AVCodecContext **input_codec_context)
{
AVCodec *input_codec;
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, get_error_text(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",
get_error_text(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;
}
/** Find a decoder for the audio stream. */
if (!(input_codec = avcodec_find_decoder((*input_format_context)->streams[0]->codec->codec_id))) {
fprintf(stderr, "Could not find input codec\n");
avformat_close_input(input_format_context);
return AVERROR_EXIT;
}
/** Open the decoder for the audio stream to use it later. */
if ((error = avcodec_open2((*input_format_context)->streams[0]->codec,
input_codec, NULL)) < 0) {
fprintf(stderr, "Could not open input codec (error '%s')\n",
get_error_text(error));
avformat_close_input(input_format_context);
return error;
}
/** Save the decoder context for easier access later. */
*input_codec_context = (*input_format_context)->streams[0]->codec;
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.
*/
static int open_output_file(const char *filename,
AVCodecContext *input_codec_context,
AVFormatContext **output_format_context,
AVCodecContext **output_codec_context)
{
AVIOContext *output_io_context = NULL;
AVStream *stream = NULL;
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, get_error_text(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;
}
av_strlcpy((*output_format_context)->filename, filename,
sizeof((*output_format_context)->filename));
/** 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, output_codec))) {
fprintf(stderr, "Could not create new stream\n");
error = AVERROR(ENOMEM);
goto cleanup;
}
/** Save the encoder context for easiert access later. */
*output_codec_context = stream->codec;
/**
* Set the basic encoder parameters.
* The input file's sample rate is used to avoid a sample rate conversion.
*/
(*output_codec_context)->channels = OUTPUT_CHANNELS;
(*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);
(*output_codec_context)->sample_rate = input_codec_context->sample_rate;
(*output_codec_context)->sample_fmt = AV_SAMPLE_FMT_S16;
(*output_codec_context)->bit_rate = OUTPUT_BIT_RATE;
/**
* Some container formats (like MP4) require global headers to be present
* Mark the encoder so that it behaves accordingly.
*/
if ((*output_format_context)->oformat->flags & AVFMT_GLOBALHEADER)
(*output_codec_context)->flags |= CODEC_FLAG_GLOBAL_HEADER;
/** Open the encoder for the audio stream to use it later. */
if ((error = avcodec_open2(*output_codec_context, output_codec, NULL)) < 0) {
fprintf(stderr, "Could not open output codec (error '%s')\n",
get_error_text(error));
goto cleanup;
}
return 0;
cleanup:
avio_close((*output_format_context)->pb);
avformat_free_context(*output_format_context);
*output_format_context = NULL;
return error < 0 ? error : AVERROR_EXIT;
}
/** Initialize one data packet for reading or writing. */
static void init_packet(AVPacket *packet)
{
av_init_packet(packet);
/** Set the packet data and size so that it is recognized as being empty. */
packet->data = NULL;
packet->size = 0;
}
/** Initialize one audio frame for reading from the input file */
static int init_input_frame(AVFrame **frame)
{
if (!(*frame = av_frame_alloc())) {
fprintf(stderr, "Could not alloca
没有合适的资源?快使用搜索试试~ 我知道了~
ffmpeg2.2libforWindows
共170个文件
h:81个
1:15个
a:14个
需积分: 11 10 下载量 54 浏览量
2014-05-15
18:36:22
上传
评论
收藏 23.81MB RAR 举报
温馨提示
ffmpeg2.2 for window lib
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg2.2libforWindows (170个子文件)
ffmpeg-all.1 720KB
ffprobe-all.1 548KB
ffplay-all.1 536KB
ffmpeg-filters.1 330KB
ffmpeg-codecs.1 127KB
ffmpeg.1 81KB
ffmpeg-formats.1 70KB
ffmpeg-devices.1 43KB
ffmpeg-protocols.1 43KB
ffprobe.1 37KB
ffmpeg-utils.1 35KB
ffplay.1 24KB
ffmpeg-resampler.1 14KB
ffmpeg-bitstream-filters.1 9KB
ffmpeg-scaler.1 7KB
libswresample.3 6KB
libswscale.3 5KB
libavutil.3 5KB
libavcodec.3 5KB
libavformat.3 5KB
libavdevice.3 5KB
libavfilter.3 5KB
libavcodec.a 61.09MB
libavformat.a 21.36MB
libavfilter.a 4.66MB
libswscale.a 2.21MB
libavutil.a 1.1MB
libavdevice.a 314KB
libswresample.a 303KB
libavutil.dll.a 269KB
libavcodec.dll.a 186KB
libavformat.dll.a 103KB
libswresample.dll.a 70KB
libavfilter.dll.a 56KB
libswscale.dll.a 23KB
libavdevice.dll.a 6KB
transcode_aac.c 27KB
muxing.c 20KB
avcodec.c 19KB
demuxing_decoding.c 14KB
filter_audio.c 12KB
filtering_audio.c 9KB
filtering_video.c 8KB
resampling_audio.c 8KB
remuxing.c 5KB
scaling_video.c 5KB
avio_reading.c 4KB
metadata.c 2KB
avutil-52.def 9KB
avcodec-55.def 7KB
swresample-0.def 4KB
avformat-55.def 4KB
avfilter-4.def 2KB
swscale-2.def 801B
avdevice-55.def 240B
avcodec-55.dll 7.78MB
avformat-55.dll 1.63MB
avfilter-4.dll 695KB
swscale-2.dll 425KB
avutil-52.dll 329KB
swresample-0.dll 102KB
avdevice-55.dll 31KB
ffmpeg.exe 215KB
ffprobe.exe 152KB
ffplay.exe 136KB
libvpx-1080p50_60.ffpreset 227B
libvpx-720p50_60.ffpreset 227B
libvpx-1080p.ffpreset 227B
libvpx-720p.ffpreset 227B
libvpx-360p.ffpreset 219B
libx264-ipod640.ffpreset 77B
libx264-ipod320.ffpreset 74B
avcodec.h 173KB
avformat.h 94KB
avfilter.h 55KB
opt.h 31KB
pixfmt.h 26KB
frame.h 22KB
intreadwrite.h 18KB
avio.h 17KB
old_pix_fmts.h 14KB
common.h 14KB
mem.h 13KB
avstring.h 12KB
swscale.h 12KB
swresample.h 12KB
old_codec_ids.h 10KB
pixdesc.h 10KB
samplefmt.h 10KB
buffer.h 10KB
log.h 9KB
channel_layout.h 9KB
avutil.h 8KB
imgutils.h 8KB
bprint.h 8KB
avdevice.h 7KB
buffersink.h 7KB
parseutils.h 7KB
dict.h 6KB
vdpau.h 6KB
共 170 条
- 1
- 2
资源评论
划过无痕
- 粉丝: 1
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功