I am programatically extracting multiple audio clips from single video files using ffmpeg.
My input data (start and end points) are specified in frames rather than seconds, and the audio clip will be used by a frame-centric user (an animator). So, I'd prefer to work in frames throughout.
In addition, the framerate is 30fps, which means I'd be working in steps of 0.033333 seconds, and I'm not sure it's reasonable to expect ffmpeg to trim correctly given such values.
Is it possible to specify a frame number instead of an ffmpeg time duration for start point (-ss) and duration (-t)? Or are there frame-centric ffmpeg commands that I've missed?
Audio frame or sample numbers don't correspond to video frame numbers, and I don't see a way to specify audio trim points by referencing video frame indices. Nevertheless, see this answer for more details.
Related
I frequently deal with .mp4 footage files which are game recordings from my computer. Because I'm dealing with a laggy game I end up with footage that has both duplicate frames and a variable frame rate. I want to cut out lagspikes from my video, lagspikes that can have the form of variable frame rates and/or duplicate frames. The end goal is to have video with a constant frame rate and no more lagspikes.
I'm well aware that this will destroy or at least damage the audio, but keeping the audio intact is not necessary for my application.
I have come across the mpdecimate filter for FFmpeg. As far as I have seen this is able to remove duplicate frames, however it does this in a way that does not make the output file a shorter video, but it introduces more variable frame rate.
Is it possible to reach my goal with FFmpeg? And if so, how?
Thanks in advance for help!
ffmpeg -i input.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB out.mp4
as Gyan showed in a comment on my original question, this is the solution. Works like a charm, thanks a lot!
(FRAME_RATE can be replaced with a number if you wish to have a set framerate)
I am currently using Kdenlive, but have also used ffmpeg when I have the simple task of adding audio to a video that does not yet have audio. Since it is just a matter of putting the video file together with the audio, it seems like it ought to be simple. Is there something about encoding mp4's that means it must take a lot of processing to complete?
I have good hardware (i7 6700k and gtx 1080), but kdenlive currently estimates 2.5 hours to complete adding audio to a 10 minute video.
Without more info (encoder, settings, video width x height, instructions to duplicate the behavior, etc) we can only guess. It's probably re-encoding the video instead of only muxing it. Encoding is CPU intensive and takes a long time. Although 2.5 hours for 10 minutes seems excessive, but there is not enough info in the question to say why it takes this long.
If you want to add audio with ffmpeg see How to add a new audio into a video using ffmpeg? This will allow you to mux the video (and optionally the audio) without encoding it: like a copy and paste.
This question and answer cover how to get the framecount and keyframe count from an AVI file, which is very useful. I've got a raw AVI file and want to count the number of keyframes (equivalent to non-dropped frames for raw AVI), but it takes a long time to process through a raw AVI file.
There is some way to get this information without fully processing the file, as VirtualDub provides both framecount and key framecount in the file information, as well as total keyframe size, almost instantly for a 25-second raw 1920x1080 AVI. But ffprobe requires count_frames to populate nb_read_frames, which takes some good processing time.
I can do some math with the file's size and the frame's width/height/format to get a fairly good estimate of the number of frames, but I'm worried the overhead of the container could be enough to throw the math off for very short clips. (For my 25 second clip, I get 1286.12 frames, when there are really 1286.)
Any thoughts on if there is a way to get this information programatically with ffprobe or ffmpeg without processing the whole file? Or with another API on windows?
I'm converting my video to mp4 H.264 with ffmpeg than changing the moov atom to front with qt-faststart, so I can stream the video.
Everything works fine with small videos 5-10 minute, but when it comes to large ones 1-2 hrs it can take a significant time to start playing. it loads 6-10mb and only than start playing the video.
In flv that's not the case, it plays immediately no matter how large the video is. How can i fix that?
It is just the nature of the formats. The moov atom contains all the metadata for every frame of audio or video in the file. So, the more frames, the larger the moov. By putting all this metatadata in one place, it makes seeking within a file much easier. Once you have downloaded the moov, the player knows exactly what byte in the file to request to seek to a specific frame or time. An FLV file is sent one frame at a time, there is no index of frame locations, this makes seeking extremely difficult for the player.
You can try making the moov smaller by ensuring your video is not in variable frame rate, and that you do not have unnecessary data (such as movie posters) embedded in the metadata. Having the server send gzip streams may help as well as the moov should compress well.
I have a bunch of .png frames and a .mp3 audio file which I would like to convert into a video. Unfortunately, the frames do not correspond to a constant frame rate. For instance, one frame may need to be displayed for 1 second, whereas another may need to be displayed for 3 seconds.
Is there any open-source software (something like ffmpeg) which would help me accomplish this? Any feedback would be greatly appreciated.
Many thanks!
This is not an elegant solution, but it will do the trick: duplicate frames as necessary so that you end up with some resulting (fairly high) constant framerate, 30 or 60 fps (or higher if you need higher time resolution). You simply change which frame is duplicated at the closest new frame to the exact timestamp you want. Frames which are exact duplicates will be encoded to a tiny size (a few bytes) with any decent codec, so this is fairly compact. Then just encode with ffmpeg as usual.
If you have a whole lot of these and need to do it the "right" way: you can indicate the timing either in the container (such as mp4, mkv, etc) or in the codec. For example in an H.264 stream you will have to insert SEI messages of type pic_timing to specify the timing of each frame. Alternately you will have to write your own muxer relying on a container library such as Matroska (mkv) or GPAC (mp4) to indicate the timing in the container. Note that not all codecs/containers support arbitrarily variable frame rate. Only a few codecs support timing in the codec. Also, if timing is specified in both container and codec, the container timing is used (but if you are muxing a stream into a container, the muxer should pick up the individual frame timestamps from the codec).