Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
bugs in avcodec_decode_audio4() in ios pad [on hold]
29 novembre 2016, par LL2012I read the mp3 frame and try to decode it to PCM on ios, but the data is totally disordered(from memory comparing with the original pcm)
it is quite ok with the same code on windows.
anyone who have met the same thing?
seems ffmpeg is not so attractive subject to get any reply, since my last question has been left there for several days. I have to re-create a new one
while (av_read_frame(format_ctx_org_, &avpkt) >= 0) { if (avpkt.stream_index == audio_stream_) { pkt_size = avpkt.size; pkt_data = avpkt.data; while (pkt_size > 0) { len = avcodec_decode_audio4(codec_ctx_, decoded_frame, &got_frame, &avpkt); if (len < 0) { //decode has completed if ((audio_duration_ - avpkt.dts <= avpkt.duration) || (file_size_ - avpkt.pos == avpkt.size)) { sink_->OnAudioDataDecodeCompleted(true, "decoding loops end!"); return kThreadProcessBreak; } //meet bad frame, just skip it break; } if (got_frame) { if (ConverFrame(decoded_frame) < 0) return kThreadProcessBreak; } pkt_size -= len; pkt_data += len; } } } int FfmpegAudioFileDecoder::ConverFrame(AVFrame * frame) { int64_t src_ch_layout, dst_ch_layout ; int src_rate = codec_ctx_org_->sample_rate, dst_rate = param_->sample_rate; uint8_t **src_data = 0, **dst_data = 0; int src_nb_channels = codec_ctx_org_->channels, dst_nb_channels = param_->sample_fmt; int src_linesize, dst_linesize; int src_nb_samples = frame->nb_samples, dst_nb_samples, max_dst_nb_samples; enum AVSampleFormat src_sample_fmt = codec_ctx_org_->sample_fmt, dst_sample_fmt = (enum AVSampleFormat)param_->sample_fmt; int ret; //we already have the frame data, no need to alloc /*ret = av_samples_alloc_array_and_samples(&src_data, &src_linesize, src_nb_channels, src_nb_samples, src_sample_fmt, 0);*/ //for (int i = 0 ; i < src_nb_channels; i++) //{ // src_data[i] = frame->data[i]; //} //if (ret < 0) { // av_log(0, "Could not allocate source samples\n"); // return -1; //} max_dst_nb_samples = dst_nb_samples = av_rescale_rnd(src_nb_samples, dst_rate, src_rate, AV_ROUND_UP); ret = av_samples_alloc_array_and_samples(&dst_data, &dst_linesize, dst_nb_channels, dst_nb_samples, dst_sample_fmt, 0); if (ret < 0) { sink_->OnAudioDataDecodeCompleted(false, "ConverFrame():Could not allocate destination samples" ); av_log(0,log_level_, "Could not allocate destination samples\n"); return -1; } dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx_, src_rate) + src_nb_samples, dst_rate, src_rate, AV_ROUND_UP); if (dst_nb_samples > max_dst_nb_samples) { av_freep(&dst_data[0]); ret = av_samples_alloc(dst_data, &dst_linesize, dst_nb_channels, dst_nb_samples, dst_sample_fmt, 1); if (ret < 0) { sink_->OnAudioDataDecodeCompleted(false, "ConverFrame():av_samples_alloc failed"); return -1; } max_dst_nb_samples = dst_nb_samples; } ret = swr_convert(swr_ctx_, dst_data, dst_nb_samples, (const uint8_t **)frame->data, src_nb_samples); if (ret < 0) { sink_->OnAudioDataDecodeCompleted(false, "ConverFrame():Error while converting"); av_log(0, log_level_,"Error while converting\n"); return -1; } int dst_bufsize = av_samples_get_buffer_size(&dst_linesize, dst_nb_channels, ret, dst_sample_fmt, 1); if (dst_bufsize < 0) { sink_->OnAudioDataDecodeCompleted(false, "ConverFrame():Could not get sample buffer size"); av_log(0,log_level_, "Could not get sample buffer size\n"); return -1; } decoded_duration_ += frame->pkt_duration; float decode_percentage = (float)decoded_duration_ /audio_duration_; av_log(0, log_level_, "decode_percentage %.3f\n" , decode_percentage); int nRet = sink_->OnAudioDataDecoded(dst_data[0], dst_bufsize, decode_percentage); if(nRet < 0) sink_->OnAudioDataDecodeCompleted(false, "ConverFrame(): user cancelled"); if (dst_data) av_freep(&dst_data[0]); av_freep(&dst_data); return nRet; }
-
Adding an audio track to a video using it's own audio as a source ?
29 novembre 2016, par user41997I have a video file with the following layout:
- Video
- DTS audio
What I would like to do is:
- Video
- AAC audio (converted from the DTS source)
- DTS audio
I can't wrap my head around the FFMPEG command I would need to do this, though, since I would need to convert the DTS audio to AAC and then place it ahead of the DTS track. The reason for this is the PS4 media player currently doesn't let you select audio tracks and it only plays the first one it sees. It doesn't support DTS audio but I'd like to keep it around.
-
Can't write YUV Frame from ffmpeg into .yuv file
29 novembre 2016, par tankyxMy goal is to write the frame I decode into a file. I know I capture it well because it shows in my SDL playback and I encode it afterwards without any problems. Yet it seems I can't write the frame into a file properly. Here is the code :
#define PIXFMT AV_PIX_FMT_YUV420P #define WIDTH 1280 #define HEIGHT 720 // initialize SWS context for software scaling sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, WIDTH, HEIGHT, PIXFMT, SWS_LANCZOS, NULL, NULL, NULL ); FfmpegEncoder enc("rtsp://127.0.0.1:1935/live/myStream", pParser); //SetPixelArray(); i = 0; enc.FillYuvImage(pFrameRGB, 0, this->pCodecCtx->width, this->pCodecCtx->height); FILE *pFile; while (av_read_frame(pFormatCtx, &packet) >= 0 && !exit) { if (packet.stream_index == videoindex) { // Decode video frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); if (frameFinished) { i++; sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); if (i < 500) { pFile = fopen(std::string("./screenshots/screen.yuv").c_str(), "a+"); for (int y = 0; y < pCodecCtx->height; y++) { fwrite(pFrame->data[0] + y * pFrame->linesize[0], 1, pCodecCtx->width * pCodecCtx->height, pFile); fwrite(pFrame->data[1] + y * pFrame->linesize[1], 1, pCodecCtx->width * pCodecCtx->height / 4, pFile); fwrite(pFrame->data[2] + y * pFrame->linesize[2], 1, pCodecCtx->width * pCodecCtx->height / 4, pFile); } fclose(pFile); } enc.encodeFrame(pFrameRGB); } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); }
The program crashes when it tries to write the frame.
-
How we use FFMPEG Library in android for play more then one audio file ?
29 novembre 2016, par Mob AppsI want to use FFMPEG library to play audio files and also want to record the output please help me.
-
mp3 decode error with ffmpeg in ios
29 novembre 2016, par LL2012I met a very strange phenomenon in decoding mp3 to pcm data in ios pad. I have tested the code on windows 10, it works correctly.However, with the same mp3 file and the same code runing on ios pad , the pcm data become total white noise.
I have compare the input compressed data(mp3) and the decoded data in memory on both system. input data is all the same(none silence frame),but the decoded data has totally different.
so, can I say that there is a bug in ffmpeg on ios platforms for decoding audio.the version I used is ffmpeg2.6
anyone meet the same things?