Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Switching MKV to MP4 container reduces audio from 5.1 to stereo
5 avril 2016, par iPodwithnomusicI have been using ffmpeg to convert my MKV files to MP4 without having to re-encode anything. However, on some of my files, they have 5.1 audio before the conversion, and only 2 channels after. Here are some errors that appeared that probably have something to do with it:
[mp4 @ 000000a192cb4020] track 1: codec frame size is not set
[matroska,webm @ 000000a190f8a860] Read error at pos. 1171341828 (0x45d14204)
I'm sure it should come out with 5.1 audio, since at the top it even says:
Stream #0:1(eng): Audio: dts , 48000 Hz, 5.1(side), fltp, 1536 ks/s (default)
Does anyone have an idea how to fix this?
Also, here is the command I was using:
ffmpeg -i C:\Users\directory\video.mkv -c:v copy -c:a copy C:\Users\directory\video.mp4
-
FFMPEG Compiled Libraries And iOS
5 avril 2016, par Muzammal HussainI have copied compiled FFMPEG libraries from a test app into my xcode-project but inspite of adding them into my project i am unable to use them,
#include
avcodec.h> givers error even all the complied libraries (libavcodec.a, libavutil.a, libavformat.a, libavdevice.a> all are specified in link libraries as required framework.
-
Uninstall ffmpeg on Mac
5 avril 2016, par Monsieur PaulI have to uninstall ffmpeg. I just installed it through Homebrew and command line:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
and then :
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265
So to uninstall this ffmpeg version with some additional recommended options, do I have to add something to this command line?
brew uninstall ffmpeg
-
how to compile FFMPEG and merge it to one android ".so" file
5 avril 2016, par user965347i am intereseted to compile the ffmpeg source to android to be invoked with jni as one ".so" last time i tried 0.8 versions but failed it always shows that something is undeclared, i tried all of google examples but it seems doesnt work for me, i tried this one
but it seems that the ffmpeg.c is not included with compile , but when i compile it always error, it says that something undeclared, and i cant build this project as one android ".so" file
i also tried this one, Link Two
but it seems i cant understand.
i have tried everything , but none of them work ,none of them merge all ".o" , ".so" , ".a" into one ".so" files
is there any good example in google or somewhere to compile ffmpeg as one ".so" file and have a good downloadable source i can compile?
-
FFMPEG MP3 decode and encode audio distortion
5 avril 2016, par user3450380I'm trying to make a program that successfully decodes MP3 to PCM. To test this I've been re-encoding to MP3 to see if the audio matches up. The problem is when I play the re-encoded audio the songs are ~30 seconds shorter than the original and at a noticeably higher pitch. However, if I decode and encode this new audio (the distorted one I just encoded), I get the exact same audio. The only thing I can think of is maybe I'm missing something in the header? Thanks for any help! Sorry for the weird code blocks, the trying to tab to make code blocks skipped across the web page.
#define AUDIO_INBUF_SIZE 20480 #define AUDIO_REFILL_THRESH 4096 #define STD_SAMPLE_RATE 44100 //check if given sample format is accepted by given codec static int check_sample_format(AVCodec* avco, enum AVSampleFormat sample_fmt) { const enum AVSampleFormat* p = avco->sample_fmts; while(*p != AV_SAMPLE_FMT_NONE) { if(*p == sample_fmt) { return 1; } p++; } return 0; } //if no sample rates in codec, selects the standard rate of 44100. //otherwise, highest suported sample rate is chosen static int select_sample_rate(AVCodec* avco) { const int* p; int best_sample_rate = 0; if(!(avco->supported_samplerates)) { return STD_SAMPLE_RATE; } p = avco->supported_samplerates; while(*p) { best_sample_rate = FFMAX(*p, best_sample_rate); p++; } return best_sample_rate; }
//select layout with the highest channel count
static int select_channel_layout(AVCodec* codec)
{
const uint64_t* p; uint64_t best_ch_layout = 0; int best_nb_channels = 0; if(!codec->channel_layouts) { return AV_CH_LAYOUT_STEREO; } p = codec->channel_layouts; while(*p) { int nb_channels = av_get_channel_layout_nb_channels(*p); if(nb_channels > best_nb_channels) { best_ch_layout = *p; best_nb_channels = nb_channels; } p++; } return best_ch_layout;
}
static int file_format_check(AVFormatContext* pFormatCtx, const char* song_path, FILE* infile)
{
AVCodecContext* codecCtx = NULL; AVCodec* inputCodec = NULL; int audioStreamIndex, i = 0; //open audio file if(avformat_open_input(&pFormatCtx, song_path, NULL, NULL) != 0) { return -1; } //open binary file for reading infile = fopen(song_path, "rb"); if(!infile) { fprintf(stderr, "Input file not opened!"); return -1; } if(avformat_find_stream_info(pFormatCtx, NULL)) { fprintf(stderr, "Stream info not found!"); return -1; } //dumps info about format context to standard error av_dump_format(pFormatCtx, 0, /*argv[1]*/0, 0); //find audio stream for(i = 0; i < pFormatCtx->nb_streams; i++){ if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { audioStreamIndex = i; printf("Audio Stream Found!\n"); break; } } if(audioStreamIndex == -1) { return -1; } //set codec context pointer to codec context of audio stream codecCtx = pFormatCtx->streams[audioStreamIndex]->codec; //find decodeder for audio stream inputCodec = avcodec_find_decoder(codecCtx->codec_id); if (inputCodec == NULL) { fprintf(stderr, "Unsupported codec!\n"); return -1; } //open codec if(avcodec_open2(codecCtx, inputCodec, NULL) < 0) { fprintf(stderr, "Codec could not be opened!"); return -1; } return audioStreamIndex;
}
int main(int argc, const char * argv[])
{
//refister all available file formats and codecs av_register_all(); FILE *infile, *outfile; int i, len, ret, audioStreamIndex = -1; const char* song_path = "/Users/timothyrice/Dropbox/audio-experimentation/audio_playground/audio_playground/Monsters.mp3"; const char* new_format_path = "/Users/timothyrice/Dropbox/audio-experimentation/audio_playground/audio_playground/new_audio.mp3"; AVFormatContext* inputFormat = avformat_alloc_context(); AVFormatContext* outputFormat = avformat_alloc_context(); AVCodecContext* decodeCodecCtx; AVPacket decodingPacket; AVFrame* decodedFrame = NULL; AVCodec* encodeCodec = NULL; AVCodecContext* encodeCodecCtx = NULL; AVPacket encodingPacket; audioStreamIndex = file_format_check(inputFormat, song_path, infile); if(audioStreamIndex < 0) { return -1; } av_init_packet(&decodingPacket); //allocate frame if(!decodedFrame) { if(!(decodedFrame = av_frame_alloc())) { fprintf(stderr, "Could not allocate audio frame\n"); return -1; } } //set decoding codec context to audio stream index's codec decodeCodecCtx = inputFormat->streams[audioStreamIndex]->codec; //set up encoding audio codec encodeCodec = avcodec_find_encoder(AV_CODEC_ID_MP3); if(!encodeCodec) { fprintf(stderr, "Could not find encoder codec!\n"); return -1; } encodeCodecCtx = avcodec_alloc_context3(encodeCodec); encodeCodecCtx->bit_rate = decodeCodecCtx->bit_rate; encodeCodecCtx->sample_fmt = decodeCodecCtx->sample_fmt; encodeCodecCtx->frame_size = decodeCodecCtx->frame_size; if(!check_sample_format(encodeCodec, encodeCodecCtx->sample_fmt)) { fprintf(stderr, "Sample format %s not supported by encoding codec!\n", av_get_sample_fmt_name(encodeCodecCtx->sample_fmt)); return -1; } //encoder codec context setup encodeCodecCtx->sample_rate = select_sample_rate(encodeCodec); encodeCodecCtx->channel_layout = select_channel_layout(encodeCodec); encodeCodecCtx->channels = av_get_channel_layout_nb_channels(encodeCodecCtx->channel_layout); if(avcodec_open2(encodeCodecCtx, encodeCodec, 0) < 0) { fprintf(stderr, "Could not open encoder codec\n"); return -1; } outfile = fopen(new_format_path, "wb"); if(!outfile) { fprintf(stderr, "Output file not opened!\n"); return -1; } //printf("Outside function format-duration = %lld\n", inputFormat->duration); int c = 0, sum = 0;// max = 0; while (av_read_frame(inputFormat, &decodingPacket) == 0) { //CHECK LATER:# of samples decoded = # encoded? //PLANAR???? int ch, got_frame, got_packet = 0; int j = 0; //printf("Frame #%d\n", ++c); //make sure stream indexes match, rarely necessary but can prevent a crash if(decodingPacket.stream_index == audioStreamIndex) { int bl = 0; //temporary to see performance of while loop while (decodingPacket.size > 0) { got_frame = 0; if(bl++ > 1) { printf("while loop repeat!!!!\n\n\n"); } //decodes next frame from stream inside decodingPacket and stores it in decodedFrame //len < 0 if the decoding didn't work len = avcodec_decode_audio4(decodeCodecCtx, decodedFrame, &got_frame, &decodingPacket); if(got_frame && len >= 0) { ret = avcodec_encode_audio2(encodeCodecCtx, &encodingPacket, decodedFrame, &got_packet); if(ret < 0) { fprintf(stderr, "Error encoding raw audio frame!\n"); return -1; } if(got_packet) { fwrite(encodingPacket.data, 1, encodingPacket.size, outfile); av_free_packet(&encodingPacket); //if encoder needs to be flushed if(encodeCodecCtx->codec->capabilities == CODEC_CAP_DELAY) { av_init_packet(&encodingPacket); got_frame = 0; while(avcodec_encode_audio2(encodeCodecCtx, &encodingPacket, NULL, &got_packet) >= 0 && got_frame) { fwrite(encodingPacket.data, 1, encodingPacket.size, outfile); av_free_packet(&encodingPacket); } } } //if decoder needs to be flushed if(decodeCodecCtx->codec->capabilities == CODEC_CAP_DELAY) { av_init_packet(&decodingPacket); got_frame = 0; while(avcodec_decode_audio4(decodeCodecCtx, decodedFrame, &got_frame, &decodingPacket) >= 0 && got_frame) { av_free_packet(&decodingPacket); } } } else { fprintf(stderr, "Error while decoding\n"); return -1; } decodingPacket.size -= len; decodingPacket.data += len; decodingPacket.dts = AV_NOPTS_VALUE; decodingPacket.pts = AV_NOPTS_VALUE; } av_free_packet(&decodingPacket); } } //open audio file if(avformat_open_input(&outputFormat, new_format_path, NULL, NULL) != 0) { return -1; } //open binary file for reading outfile = fopen(new_format_path, "rb"); if(!outfile) { fprintf(stderr, "Input file not opened!"); return -1; } if(avformat_find_stream_info(outputFormat, NULL)) { fprintf(stderr, "Stream info not found!"); return -1; } //dumps info about format context to standard error av_dump_format(outputFormat, 0, /*argv[1]*/0, 0); fclose(infile); fclose(outfile); avcodec_close(decodeCodecCtx); av_free(decodeCodecCtx); av_frame_free(&decodedFrame); return 0;
}