Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
How to hack ffmpeg to consider I-Frames as key frames ?
2 février 2012, par justanothercoderI'm trying to get ffmpeg to seek h264 interlaced videos, and i found that i can seek to any frame if i just force it.
I already hacked the decoder to consider I - Frames as keyframes, and it works nicely with the videos i need it to work with. And there will NEVER be any videos encoded with different encoders.
However, i'd like the seek to find me an I - Frame and not just any frame.
What i'd need to do is to hack The AVIndexEntry creation so that it marks any frame that is an I-Frame to be a key frame. Or alternatively, hack the search thing to return I - Frames.
The code does get a tad dfficult to follow at this point.
Can someone please point me at the correct place in ffmpeg code which handles this?
-
Facebook video upload [closed]
2 février 2012, par Ahmet KapıkıranI can't add subtitle to an avi file with mencoder. The length of avi videos are about 100 minutes. I split the videos to 19 minutes parts with ffmpeg and x264 codec and then I upload the video to user's facebook account with my facebook application. So, facebook starts to encode the video but after a period of time the video suddenly is removed by facebook. What is the problem. Is there a time period limit to send video to facebook profile or is my problem about codecs?
-
Audio stream shorter than video stream
2 février 2012, par JackWilsonI generate a bunch of videos by looping .PNG inputs along with .AMR audio.
ffmpeg -loop 1 -i slide001.png -i slide001.amr -vcodec rawvideo -acodec pcm_s16le -t 5 slide001.avi
Eventually I join the .AVIs using Mencoder. I haven't had much success trying to join them with FFmpeg.
It seems that because the .AMR's actual duration is shorter than the 5 seconds I specified for example, when the time comes to join the .AVIs, the audio stream will be out of sync (ahead of the video).
I suspect I need to find a way of padding the audio with silence or specifying its duration somehow so that the audio and video streams in my .AVIs are of equal length before joining them.
Any ideas?
Thanks.
-
How to convert videos with FFMPEG to play on iPad with iOS 5 ?
2 février 2012, par sushil bharwaniMy ffmpeg converted .mp4 video is not playing on iOS 5. while it was playing on 4.3. Could somebody help? I am new to ios devices.
-
FFmpeg : avcodec_encode_video() and JPEG images
2 février 2012, par user105909I'm trying to encode a series of .jpg files into a video using the ffmpeg library, and I can't seem to get the frames to encode. (I have to use the ffmpeg library, and using ffmpeg from a command line is not an option in my case.)
Except for the part where I'm trying to open JPG files as AVFrames, my code is more or less the same thing as found in api-example.c from the ffmpeg library. When I populate the frames as the example does, everything works as expected. In the code below, I fail to encode any frames. Obviously the trouble is related to how I'm opening the JPG files, but I can't figure out what.
I'm opening the image like this:
AVFrame* open_image(const char* imageFileName, int width, int height, long * bufSize) { AVFormatContext *pFormatCtx; if(av_open_input_file(&pFormatCtx, imageFileName, NULL, 0, NULL)!=0) { printf("Can't open image file '%s'\n", imageFileName); return NULL; } AVCodecContext *pCodecCtx; pCodecCtx = pFormatCtx->streams[0]->codec; pCodecCtx->width = width; pCodecCtx->height = height; pCodecCtx->pix_fmt = PIX_FMT_YUV420P; // Find the decoder for the video stream AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (!pCodec) { printf("Codec not found\n"); return NULL; } // Open codec if(avcodec_open(pCodecCtx, pCodec)<0) { printf("Could not open codec\n"); return NULL; } AVFrame *pFrame = avcodec_alloc_frame(); if (!pFrame) { LOGV(TAG, "Can't allocate memory for AVFrame\n"); return NULL; } int frameFinished; int numBytes; // Determine required buffer size and allocate buffer numBytes = avpicture_get_size(PIX_FMT_YUVJ420P, pCodecCtx->width, pCodecCtx->height); // *** *bufSize = numBytes; // *** uint8_t *buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t)); avpicture_fill((AVPicture *) pFrame, buffer, PIX_FMT_YUVJ420P, pCodecCtx->width, pCodecCtx->height); // Read frame AVPacket packet; int framesNumber = 0; while (av_read_frame(pFormatCtx, &packet) >= 0) { if(packet.stream_index != 0) continue; int ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); if (ret > 0) { sprintf(buf, "Frame is decoded, size %d", ret); LOGV(TAG, buf); pFrame->quality = 4; return pFrame; } else { // printf("Error [%d] while decoding frame: %s\n", ret, strerror(AVERROR(ret))); sprintf(buf, "Error %d decoding frame: %s", ret, strerror(AVERROR(ret))); LOGV(TAG, buf); } } }
...and attempting to encode them like this:
DIR * dir = opendir(path); int i = 0; if (dir != NULL) { for(struct dirent *ent = readdir(dir); ent != NULL; ent = readdir(dir)) { fflush(stdout); printf("%s/%s", path, ent->d_name); LOGV(TAG, filename); // If not a jpg file, pass it over const char * ext = strrchr(filename, '.'); if((!ext) || (strcmp(ext, ".jpg"))) { continue; } /*** NOTE: Is this where I've gone wrong? Bufsize is set in open_image based on av_picture_size() */ long bufSize = 0L; AVFrame * frame = open_image(filename, width, height, &bufSize); if(frame) { // This is what it needs to do, and it does not work. // Causes: // Wrong format? // Wrong buffer size? uint8_t * picBuf = (uint8_t *)malloc(bufSize); out_size = avcodec_encode_video(c, picBuf, bufSize, frame); printf("encoding frame %3d (size=%5d)\n", i++, out_size); /** On the first image, out_size is 0. On the next, it's -1, and fails. */ if(out_size < 0) { printf("Error encoding frame"); return -6; } fwrite(picBuf, 1, bufSize, f); free(picBuf); av_free(frame); } else { printf("Couldn't open image"); return -5; } } closedir(dir); } else { printf("Couldn't open directory %s\n", path); return -4; }
Could someone point me in the right direction?