Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFmpeg C Api - Reduce fps but maintain video duration
25 mars 2015, par Justin BradleyUsing the FFmpeg C API I'm trying to convert an input video into a video that looks like an animated gif - meaning no audio stream and a video stream of 4/fps.
I have the decode/encode part working. I can drop the audio stream from the output file, but I'm having trouble reducing the fps. I can change the output video stream's time_base to 4/fps, but it increases the video's duration - basically playing it in slow mo.
I think I need to drop the extra frames before I write them to the output container.
Below is the loop where I read the input frames, and then write them to output container.
Is this where I'd drop the extra frames? How do I determine which frames to drop (I,P,B frames)?
while(av_read_frame(input_container, &decoded_packet)>=0) { if (decoded_packet.stream_index == video_stream_index) { len = avcodec_decode_video2(input_stream->codec, decoded_frame, &got_frame, &decoded_packet); if(len < 0) { exit(1); } if(got_frame) { av_init_packet(&encoded_packet); encoded_packet.data = NULL; encoded_packet.size = 0; if(avcodec_encode_video2(output_stream->codec, &encoded_packet, decoded_frame, &got_frame) < 0) { exit(1); } if(got_frame) { if (output_stream->codec->coded_frame->key_frame) { encoded_packet.flags |= AV_PKT_FLAG_KEY; } encoded_packet.stream_index = output_stream->index; encoded_packet.pts = av_rescale_q(current_frame_num, output_stream->codec->time_base, output_stream->time_base); encoded_packet.dts = av_rescale_q(current_frame_num, output_stream->codec->time_base, output_stream->time_base); if(av_interleaved_write_frame(output_container, &encoded_packet) < 0) { exit(1); } else { current_frame_num +=1; } } frame_count+=1; av_free_packet(&encoded_packet); } } }
-
Extract audio from video with FFMPEG but not the same duration
25 mars 2015, par user3774451My problem is that i need to extract with FFMPEG the audio contained in a video with the same duration. But for some files that i tested, the audio's duration is sometimes shorter than the video's duration. I need to have the exact same duration between the audio and the video file.
The command that i have already tried is this following:
ffmpeg -i input_video.mp4 output_audio.wav
How can i fix this with options in my command ?
-
How to convert flv to avi using ffmpeg high quality
25 mars 2015, par NaotaNeed to convert flv files to avi or mov, trying out ffmpeg but the output quality is terrible. How can I get the video output to be on par quality with the source?
I thought ffmpeg -i name.flv -s 320x... name.avi would do it, but no good.
-
Dealing with 302 Redirection in FFMPEG
25 mars 2015, par Bilal Ahmed YaseenI am using FFMPEG Library to Stream Audio from RTSP URL. My Sample Streaming URL is:
rtsp://username:password@machine-ip/708314c4eba2a041
And I am using the following command for streaming this RTSP URL:
ffmpeg -i RTSP_URL -f mov C:\FFMPEG_Recordings\bay.mov
So, the above FFMPEG command will capture the media stream from RTSP_URL and will store in bay.mov media file.
Sometimes, I get 302 Redirection Error from the Server which is actually propagating streams. Such as:
[rtsp @ 0000000002cc8100] Status 302: Redirecting to rtsp://server-ip:server-port/708314c4eba2a041?token=708114c4e99dbcd1^LA^0^0^0^1427248150^e77149b2a2c209982a74367d0f72c2e11ba6636c
And after this process gets stuck (on Command Prompt) until I press CTRL+C twicely to terminate it in cmd where I run this command.
While It should start streaming from the redirected URL automatically.
I read that It's a FFMPEG's bug on FFMPEG Track and also read about it on FFMPEG Discussion Community but didn't get any solution or workaround for this.
Please guide to overcome this scenario If anyone ever encountered it that what are workarounds for this. Thnaks
-
javacv FFMPEG decode memory leak ?
25 mars 2015, par Liquan NieI'm new to JAVACV and I am using FFMPEG to play some video file as follows My enviroument is windows 8 with jdk7 and javacv0.10.
String file_path ="D:\\1.mp4"; // regist all format and codec avformat.av_register_all(); avcodec.avcodec_register_all(); // open file avformat.AVFormatContext avFormatCtx = avformat.avformat_alloc_context(); if (avformat.avformat_open_input(avFormatCtx, file_path, null, null) != 0) { System.out.println("cann't open file\r\n"); return; } // find stream info if (avformat.avformat_find_stream_info(avFormatCtx, (AVDictionary)null) < 0) { System.out.println("can't find stream info\r\n"); return; } int videoIndex = -1; for(int i=0; i< avFormatCtx.nb_streams();i++) { if(avFormatCtx.streams(i).codec().codec_type() == avutil.AVMEDIA_TYPE_VIDEO) { videoIndex = i; } } // determ codec avcodec.AVCodecContext avCodecCtx = avFormatCtx.streams(videoIndex).codec(); avcodec.AVCodec codec = avcodec.avcodec_find_decoder(avCodecCtx.codec_id()); if (codec == null) { System.out.println("codec not found"); return; } if(avcodec.avcodec_open2(avCodecCtx, codec, (AVDictionary)null) < 0) { System.out.println("cann't open avcodec\r\n"); } avutil.AVFrame frame = avcodec.avcodec_alloc_frame(); avutil.AVFrame frameRGB = avcodec.avcodec_alloc_frame(); int numByte = avcodec.avpicture_get_size(avutil.AV_PIX_FMT_RGB24, avCodecCtx.width(), avCodecCtx.height()); Pointer outBuffer = avutil.av_malloc(numByte); avcodec.avpicture_fill(new AVPicture(frameRGB), outBuffer.asByteBuffer(), avutil.AV_PIX_FMT_RGB24, avCodecCtx.width(), avCodecCtx.height()); avformat.av_dump_format(avFormatCtx, 0, file_path, 0); System.out.println(avFormatCtx.duration()); SwsContext img_convert_ctx = swscale.sws_getContext(avCodecCtx.width(), avCodecCtx.height(), avCodecCtx.pix_fmt(), avCodecCtx.width(), avCodecCtx.height(), avutil.AV_PIX_FMT_RGB24, swscale.SWS_BICUBIC, null, null, (double[])null); AVPacket pkt = new AVPacket(); int y_size = avCodecCtx.width()*avCodecCtx.height(); avcodec.av_new_packet(pkt, y_size); opencv_highgui.cvNamedWindow(WINDOW_NAME); IplImage showImage = opencv_core.cvCreateImage(opencv_core.cvSize(avCodecCtx.width(), avCodecCtx.height()), opencv_core.IPL_DEPTH_8U, 3); // read frames loop int frameNumbers = avformat.av_read_frame(avFormatCtx, pkt); System.out.println("frame number is "+frameNumbers); while (avformat.av_read_frame(avFormatCtx, pkt) >= 0) { //System.out.println(pkt.asByteBuffer()); if (pkt.stream_index() == videoIndex) { IntPointer ip = new IntPointer(); int ret = avcodec.avcodec_decode_video2(avCodecCtx, frame, ip, pkt); if (ret < 0) { System.out.println("codec error\r\n"); return; } if (ip.get()!= 0) { swscale.sws_scale(img_convert_ctx, frame.data(), frame.linesize(), 0, avCodecCtx.height(), frameRGB.data(), frameRGB.linesize()); showImage.imageData(frameRGB.data(0)); showImage.widthStep(frameRGB.linesize().get(0)); opencv_highgui.cvShowImage(WINDOW_NAME, showImage); opencv_highgui.cvWaitKey(25); } } } showImage.release(); opencv_highgui.cvDestroyWindow(WINDOW_NAME); avutil.av_free(frameRGB); avcodec.avcodec_close(avCodecCtx); avformat.avformat_close_input(avFormatCtx);
but i run into get this error
# A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000767c35ed, pid=11884, tid=3960 # # JRE version: 7.0_13-b20 # Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode windows-amd64 compressed oops) # Problematic frame: # C [avcodec-56.dll+0x4835ed] avcodec_decode_video2+0xbd # # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows # # An error report file with more information is saved as: # E:\code\android\TestJAVACV\hs_err_pid11884.log # # If you would like to submit a bug report, please visit: # http://bugreport.sun.com/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 1970-01-01 00:00:00 encoder : Lavf53.29.100 Duration: 00:08:30.27, start: 0.000000, bitrate: 160 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 28 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc (default) Metadata: creation_time : 1970-01-01 00:00:00 handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) Metadata: creation_time : 1970-01-01 00:00:00 handler_name : SoundHandler
Heap PSYoungGen total 23872K, used 20250K [0x00000000e5600000, 0x00000000e70a0000, 0x0000000100000000) eden space 20480K, 98% used [0x00000000e5600000,0x00000000e69c69f8,0x00000000e6a00000)