/*
* Copyright (c) 2013-2018 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
* Simple audio converter
*
* @example transcode_aac.c
* Convert an input audio file to AAC in an MP4 container using FFmpeg.
* 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/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;
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, 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;
}
/* Find a decoder for the audio stream. */
if (!(input_codec = avcodec_find_decoder((*input_format_context)->streams[0]->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, (*input_format_context)->streams[0]->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;
}
/* 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;
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. */
avctx->channels = OUTPUT_CHANNELS;
avctx->channel_layout = av_get_default_channel_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;
/* Allow the use of the experimental AAC encoder. */
avctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
/* 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+aach64测试例子
需积分: 0 0 下载量 73 浏览量
2022-11-16
18:59:29
上传
评论
收藏 85.58MB GZ 举报
温馨提示
共775个文件
h:349个
conf:283个
c:32个
aarch64+linux ffmpeg测试例子 Makefile test_avlog.c //测试avlog test_capture_audio_aac_new.c //ffmpeg 通过alsa捕获音频,编码为aac test_avfilter.c //测试ffmpeg filter功能 test_capture_video.c //ffmepg 通过v4l2 捕获一张摄像头图片 test_capture_video_save_h26x.c t //ffmepg 通过v4l2 捕获一段时间视频编码为h264 test_muxer_h26x_aac_to_mp4.c //h264 aac muxer为mp4 test_demuxer_mp4_to_h26x_aac.c //demixer mp4为h264 和 aac test_gen_test_pics.c //产生测试图片 test_v4l2.c //v4l2 获取摄像头
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg+aach64测试例子 (775个子文件)
libasound.so.2.0.0 4.52MB
libatopology.so.2.0.0 514KB
ffmpeg-all.1 1.67MB
ffprobe-all.1 1.34MB
ffmpeg-filters.1 872KB
ffmpeg-codecs.1 189KB
ffmpeg-formats.1 166KB
ffmpeg.1 122KB
ffmpeg-devices.1 77KB
ffmpeg-protocols.1 74KB
ffprobe.1 42KB
ffmpeg-utils.1 36KB
ffmpeg-bitstream-filters.1 33KB
ffmpeg-resampler.1 14KB
ffmpeg-scaler.1 9KB
libavcodec.so.58.134.100 10.48MB
libavfilter.so.7.110.100 3.13MB
libavformat.so.58.76.100 2.32MB
libavutil.so.56.70.100 536KB
libswscale.so.5.9.100 398KB
libswresample.so.3.9.100 82KB
libavdevice.so.58.13.100 69KB
libx264.so.157 1.55MB
libasound.so.2 4.52MB
libatopology.so.2 514KB
libswresample.so.3 82KB
libswresample.3 6KB
libswscale.3 5KB
libavutil.3 5KB
libavcodec.3 5KB
libavformat.3 5KB
libavdevice.3 5KB
libavfilter.3 5KB
libswscale.so.5 398KB
libavutil.so.56 536KB
libavcodec.so.58 10.48MB
libavformat.so.58 2.32MB
libavdevice.so.58 69KB
libavfilter.so.7 3.13MB
libavcodec.a 175.04MB
libavformat.a 57.69MB
libavfilter.a 42.92MB
libswscale.a 6.99MB
libavutil.a 4.64MB
libavdevice.a 1.77MB
libswresample.a 669KB
aserver 113KB
transcode_aac.c 34KB
test_capture_audio_aac_new.c 24KB
transcoding.c 22KB
test_gen_test_pics.c 21KB
muxing.c 21KB
test_capture_video_save_h26x.c 18KB
demuxing_decoding.c 13KB
test_muxer_h26x_aac_to_mp4.c 13KB
test_v4l2.c 12KB
filter_audio.c 12KB
test_avfilter.c 11KB
filtering_audio.c 10KB
vaapi_transcode.c 10KB
filtering_video.c 9KB
test_demuxer_mp4_to_h26x_aac.c 9KB
qsvdec.c 8KB
resampling_audio.c 8KB
hw_decode.c 8KB
decode_audio.c 7KB
vaapi_encode.c 7KB
encode_audio.c 6KB
remuxing.c 6KB
extract_mvs.c 6KB
encode_video.c 5KB
decode_video.c 5KB
http_multiclient.c 5KB
scaling_video.c 5KB
avio_list_dir.c 4KB
avio_reading.c 4KB
test_capture_video.c 4KB
metadata.c 2KB
test_avlog.c 892B
skl_hda_dsp_generic-tplg.conf 190KB
bxt_i2s.conf 73KB
skl_i2s.conf 65KB
alsa.conf 10KB
USB-Audio.conf 9KB
Audigy2.conf 8KB
HDA-Intel.conf 7KB
broadwell.conf 6KB
Audigy.conf 6KB
EMU10K1.conf 6KB
NFORCE.conf 5KB
PlatformEnableSeq.conf 5KB
HiFi.conf 4KB
Echo_Echo3G.conf 4KB
HiFi.conf 4KB
CA0106.conf 4KB
ICH.conf 3KB
CMI8738-MC8.conf 3KB
CS46xx.conf 3KB
ICE1724.conf 3KB
ICH4.conf 3KB
共 775 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
萌主墩墩
- 粉丝: 65
- 资源: 161
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功