kewlbear / FFmpeg-iOS-build-script

Shell scripts to build FFmpeg for iOS and tvOS
3.03k stars 897 forks source link

Max bitrate property issue #117

Closed ViswanathB84 closed 6 years ago

ViswanathB84 commented 6 years ago

Thank you very much for developing and supporting this great FFMPEG libaray .

I am an iOS developer. I used FFMPEG library for video conversion i.e mpg format to mp4 format. I am getting below error in debug console.

Input #0, mpeg, from '/Users/Library/Developer/CoreSimulator/Devices/A71B16D3-86A9-4403-A6B1-9A8D23B842C0/data/Containers/Bundle/Application/FFA13844-61BD-4A81-9A2F-CACDB6BC6ADA/DLGDemo.app/iOSQuickstartMVVM.mpg': Duration: 00:05:15.69, start: 0.508278, bitrate: 982 kb/s Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc Stream #0:1[0x1c0]: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s [h264_videotoolbox @ 0x7ff34a018200] Error setting max bitrate property: -12902 Cannot open video encoder for stream #0 Error occurred: Generic error in an external library.

Would you please help on this how to resolve this issue. Thank you very much for your support.

kewlbear commented 6 years ago

You should show relevant source code of your app to get help from anyone.

ViswanathB84 commented 6 years ago

Thank you very much for your support. I am getting below error in open_output_file method at encoder = avcodec_find_encoder(dec_ctx->codec_id); line and it returns null value.

XPC connection interrupted Input #0, mpeg, from '/Users/viswanath/Library/Developer/CoreSimulator/Devices/A71B16D3-86A9-4403-A6B1-9A8D23B842C0/data/Containers/Bundle/Application/73503E38-AF99-4539-8453-FBB5C8B28F46/DLGDemo.app/iOSQuickstartMVVM.mpg': Duration: 00:05:15.69, start: 0.508278, bitrate: 982 kb/s Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 30 tbc Stream #0:1[0x1c0]: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s Necessary encoder not found Error occurred: Invalid data found when processing input

`

import "FFMpegVideoConversion.h"

include <libavcodec/avcodec.h>

include <libavformat/avformat.h>

include <libavfilter/buffersink.h>

include <libavfilter/buffersrc.h>

include <libavutil/opt.h>

include <libavutil/pixdesc.h>

include "libavfilter/avfiltergraph.h"

include "libavutil/common.h"

include "libavutil/imgutils.h"

include "libavutil/mathematics.h"

include "libavutil/samplefmt.h"

include "libavutil/channel_layout.h"

static AVFormatContext ifmt_ctx; static AVFormatContext ofmt_ctx; typedef struct FilteringContext { AVFilterContext buffersink_ctx; AVFilterContext buffersrc_ctx; AVFilterGraph filter_graph; } FilteringContext; static FilteringContext filter_ctx; typedef struct StreamContext { AVCodecContext dec_ctx; AVCodecContext enc_ctx; } StreamContext; static StreamContext *stream_ctx;

@implementation FFMpegVideoConversion

static int open_input_file(const char filename) { int ret; unsigned int i; ifmt_ctx = NULL; if ((ret = avformat_open_input(&ifmt_ctx, filename, NULL, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n"); return ret; } if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n"); return ret; } stream_ctx = av_mallocz_array(ifmt_ctx->nb_streams, sizeof(stream_ctx)); if (!stream_ctx) return AVERROR(ENOMEM); for (i = 0; i < ifmt_ctx->nb_streams; i++) { AVStream stream = ifmt_ctx->streams[i]; AVCodec dec = avcodec_find_decoder(stream->codecpar->codec_id); AVCodecContext codec_ctx; if (!dec) { av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i); return AVERROR_DECODER_NOT_FOUND; } codec_ctx = avcodec_alloc_context3(dec); if (!codec_ctx) { av_log(NULL, AV_LOG_ERROR, "Failed to allocate the decoder context for stream #%u\n", i); return AVERROR(ENOMEM); } ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to input decoder context " "for stream #%u\n", i); return ret; } / Reencode video & audio and remux subtitles etc. / if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, NULL); / Open decoder / ret = avcodec_open2(codec_ctx, dec, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to open decoder for stream #%u\n", i); return ret; } } stream_ctx[i].dec_ctx = codec_ctx; } av_dump_format(ifmt_ctx, 0, filename, 0); return 0; } static int open_output_file(const char filename) { AVStream out_stream; AVStream in_stream; AVCodecContext dec_ctx, enc_ctx; AVCodec encoder; int ret; unsigned int i; ofmt_ctx = NULL; avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, filename); if (!ofmt_ctx) { av_log(NULL, AV_LOG_ERROR, "Could not create output context\n"); return AVERROR_UNKNOWN; } for (i = 0; i < ifmt_ctx->nb_streams; i++) { out_stream = avformat_new_stream(ofmt_ctx, NULL); if (!out_stream) { av_log(NULL, AV_LOG_ERROR, "Failed allocating output stream\n"); return AVERROR_UNKNOWN; } in_stream = ifmt_ctx->streams[i]; dec_ctx = stream_ctx[i].dec_ctx; if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { / in this example, we choose transcoding to same codec / encoder = avcodec_find_encoder(dec_ctx->codec_id); if (!encoder) { av_log(NULL, AV_LOG_FATAL, "Necessary encoder not found\n"); return AVERROR_INVALIDDATA; } enc_ctx = avcodec_alloc_context3(encoder); if (!enc_ctx) { av_log(NULL, AV_LOG_FATAL, "Failed to allocate the encoder context\n"); return AVERROR(ENOMEM); } / In this example, we transcode to same properties (picture size,

}

@end `

kewlbear commented 6 years ago

You should log failing codec info and verify it is available. You may need to rebuild FFmpeg with more external libraries and/or configure options.

ViswanathB84 commented 6 years ago

I rebuilded FFmpeg libraries and below libraries using for conversion but Still it is failing. libavcodec.a libavdevice.a libavfilter.a libavformat.a libavresample.a libavutil.a libfdk-aac.a libpostproc.a libswresample.a libswscale.a libx264.a Would you please suggest which external libraries or configure I need to use it for conversion.