#3107: Problem using muxing example -------------------------------------+------------------------------------- Reporter: ahsan | Owner: Type: defect | Status: new Priority: normal | Component: Version: unspecified | undetermined Keywords: | Resolution: Blocking: | Blocked By: Analyzed by developer: 0 | Reproduced by developer: 0 -------------------------------------+-------------------------------------
Comment (by easonic): Replying to [comment:10 ahsan]: > I merged, demux and mux example codes so that i can take in any .mp4/.avi/mpg files and then re-encode them in the same format > > I am having following issues > > 1. MUX example code uses avformat_alloc_output_context2() to create the output context for example for .mpg it will choose MPEG1 encoder, the .mpg file i used is encoded using MPEG2 encoder. > > I was wondering how can i select different encoders, is there any API call which i can use to re-set the encoder name in the context encoder fails > > 2. I uses the fmt_ctx from decoder to set the encoder parameters, i try to memcpy the context (decoder to encoder for the codec) but it fails by setting the different parameters from fmt_ctx to the c > > c->width = fmt_ctx->streams[video_stream_idx]->codec->width; > c->height = fmt_ctx->streams[video_stream_idx]->codec->height; > c->coded_width = fmt_ctx->streams[video_stream_idx]->codec>coded_width; > ........................ > c->gop_size = fmt_ctx->streams[video_stream_idx]->codec->gop_size; > /* emit one intra frame every twelve frames at most */ > > c->bit_rate = (fmt_ctx->streams[video_stream_idx]->codec->bit_rate == 0) ? 400000 : > fmt_ctx->streams[video_stream_idx]->codec->bit_rate; > /* i am seting it to 400kbps in case it is set to 0 as i am seeing it for some stream */ > > ........................ > > I am seeing different issue > > 1. GOP Size fmt_ctx most of the time has gop_size = 12 which does not seems like the case for the original/input stream > > 2. bit-rate i am getting in the output .mp4 is way higher then the one i see from the fmt_ctx, it seems like encoded bit-stream is in 50Mbits/sec where as input .mp4 was 300kbps or 400kbps bit-rate > > I am wondering what is the best way to set the encoder context using the input bitstream > [.mp4, .avi, .mpg etc] files > > Please let me know if you are able to figure it out Hi, ahsan Sorry for the delay, really busy for the project. Um, do you resolve that issue? I met maybe the same problem here, what I did was just: '''avcodec_copy_context(vStream->codec, inFormatCtx->streams[video_idx]->codec);''' but found that the '''output avformatcontext''' complains about the codec_tag. Thus, I traced the problem, found that after '''avformat_write_header(outFmtCtx, NULL);''', some parameter in the '''output avformatcontext->streams[video]->codec''' will change; thus I set the parameter to zero before '''avformat_write_header(outFmtCtx, NULL);''' and that works. For my experiment, I found that to get the correct duration and time_base (you can treat it as after parsing the codeccontext parameter), I need to set videostream's codec to: ''/* * IMPORTANT!!! Set the stream->codec information: * Copy all the CodecFormat info except the time_base and codec_tag * video_stream->codec->time_base: set to inputFmtCtx->vStream->time_base * video only! * video_stream->codec->codec_tag: calculate by av_write_header * video_stream->codec->flags : set global if the output format need * global **/'' Um, and for audio, just skip the time_base part, and it works for me, too. If you need my code (what I was doing was to remux files without reencoding.), I will email to you later~ -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/3107#comment:11> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker _______________________________________________ FFmpeg-trac mailing list FFmpeg-trac@avcodec.org http://avcodec.org/mailman/listinfo/ffmpeg-trac