summaryrefslogtreecommitdiff
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-09-29 01:03:02 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-09-29 01:11:01 +0200
commitf9a2d0c3feccab94a86c92396f3e36110dc2227b (patch)
treee7d0fa58e78006fd1d26dab64c74f22355bd9ce8 /ffmpeg.c
parenta3a5c61c6175a0bf398cce6a51fe94fcfca1145b (diff)
parentdaf98908118074e96199ca7195663af4543d3808 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (23 commits) avconv: Reformat s16 volume adjustment. ARM: NEON optimised vector_fmac_scalar() dca: use vector_fmac_scalar from dsputil dsputil: add vector_fmac_scalar() latmenc: Fix private options vf_unsharp: store hsub/vsub in the filter context vf_unsharp: adopt a more natural order of params in apply_unsharp() vf_unsharp: rename method "unsharpen" to "apply_unsharp" vf_scale: apply the same transform to the aspect during init that is applied per frame vf_pad: fix "vsub" variable value computation vf_scale: add a "sar" variable lavfi: fix realloc size computation in avfilter_add_format() vsrc_color: use internal timebase lavfi: fix signature for avfilter_graph_parse() and avfilter_graph_config() graphparser: prefer void * over AVClass * for log contexts avfiltergraph: use meaningful error codes avconv: Initialize return value for codec copy path. fate: use 'run' helper for seek-test fate: remove seek-mpeg2reuse test Fix memory (re)allocation in matroskadec.c, related to MSVR-11-0080. ... Conflicts: doc/filters.texi libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/avfiltergraph.h libavfilter/graphparser.c libavfilter/vf_scale.c libavfilter/vsrc_color.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 0ced8f8e0b..b250f0a944 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -160,7 +160,7 @@ static uint8_t *audio_buf;
static uint8_t *audio_out;
static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
-static short *samples;
+static void *samples;
static uint8_t *input_tmp= NULL;
#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
@@ -1596,7 +1596,7 @@ static int output_packet(InputStream *ist, int ist_index,
{
AVFormatContext *os;
OutputStream *ost;
- int ret, i;
+ int ret = 0, i;
int got_output;
void *buffer_to_free = NULL;
static unsigned int samples_size= 0;
@@ -1651,8 +1651,8 @@ static int output_packet(InputStream *ist, int ist_index,
if (ist->decoding_needed) {
switch(ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:{
- if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
- samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ if(pkt && samples_size < FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
+ samples_size = FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE);
av_free(samples);
samples= av_malloc(samples_size);
}
@@ -1758,11 +1758,57 @@ static int output_packet(InputStream *ist, int ist_index,
// preprocess audio (volume)
if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (audio_volume != 256) {
- short *volp;
- volp = samples;
- for(i=0;i<(decoded_data_size / sizeof(short));i++) {
- int v = ((*volp) * audio_volume + 128) >> 8;
- *volp++ = av_clip_int16(v);
+ switch (ist->st->codec->sample_fmt) {
+ case AV_SAMPLE_FMT_U8:
+ {
+ uint8_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = (((*volp - 128) * audio_volume + 128) >> 8) + 128;
+ *volp++ = av_clip_uint8(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S16:
+ {
+ int16_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int v = ((*volp) * audio_volume + 128) >> 8;
+ *volp++ = av_clip_int16(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_S32:
+ {
+ int32_t *volp = samples;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ int64_t v = (((int64_t)*volp * audio_volume + 128) >> 8);
+ *volp++ = av_clipl_int32(v);
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_FLT:
+ {
+ float *volp = samples;
+ float scale = audio_volume / 256.f;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ case AV_SAMPLE_FMT_DBL:
+ {
+ double *volp = samples;
+ double scale = audio_volume / 256.;
+ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
+ *volp++ *= scale;
+ }
+ break;
+ }
+ default:
+ av_log(NULL, AV_LOG_FATAL,
+ "Audio volume adjustment on sample format %s is not supported.\n",
+ av_get_sample_fmt_name(ist->st->codec->sample_fmt));
+ exit_program(1);
}
}
}