How can I get the approximate frame rate of an AVI video using AVFoundation ?
Getting nominalFrameRate from an AVAssetTrack gives a result of 0.0 but the same code works fine on any mov file I try.
In my experience, AVI files don't really work with AV Foundation. QuickTime may be the answer, however.
Related
I have to record videos for a project I'm doing. Two of these are USB cameras and another is a n IP overhead camera.All three are connected to a laptop computer. After recording the videos I need to be able to open them in an editor (not for editing particularly but for modeling stuff in them for which I need a timeline). I have chosen Sony Vegas Pro for my editor. I have been able to record the uncompressed avi using gstreamer with this command:
gst-launch v4l2src device=/dev/video0 ! 'video/x-rawyuv,width=640,height=480,framerate=10/1' ! mux. avimux name=mux ! filesink location=temp.avi
I had to set the framerate to 10 because I was using two USB cameras and a framerate of 30 on both could not be accomodated in the bandwidth of the USB controller. I do not care about audio in my file so I don't grab audio. Similary, while encoding I wouldn't care about audio as well. This is raw uncompressed avi. I was not able to open this in Sony Vegas Pro. I believe I need to encode this uncompressed avi using a codec that will be opened by Sony Vegas Pro (I don't know which codecs Sony likes, so I'll probably try different ones until one of them opens).
For encoding this video, I have several options: mencoder, ffmpeg, gstreamer. But I am not able to figure out how to use these tools to get what I want. Ideally, I would like just to sort of "insert" a codec with other settings remaining the same. I don't really care about the how much space the resulting video takes since the length of the videos are not going to be more than 3 minutes and I have space available, so lossless codecs also work. I believe Sony reads mpeg avi's so if I can get that, it'll be great.
Thanks for reading and I appreciate all the help.
I was able to figure this out after some searching. It is based on the information here. I found that Sony Vegas pro seems to open avi videos encoded with the xvid codec.
I'm trying to convert GIF files into WebM (ffmpeg, libvpx) and getting some strange ffmpeg behaviour.
ffmpeg is installed on my mac from MacPorts.
Converting with:
ffmpeg -i srcFilename.gif -b:v 600K -qmin 0 -qmax 50 -crf 5 destFilename.webm
if my GIF file has some frame(s) with 1-2s duration somewhere in the middle of animation like this, conversion result is fine - it's playing with the "pause" in the middle.
But if I have GIF like this with "pause" in the last frame, ffmpeg decodes it without a delay.
Have no idea why, spent some time reading ffmpeg manual, trying different conversion options with no success.
Any ideas? Thanks in advance!
I wrote an email to GIF decoder author and he answered me that he knows about this issue. It's located somewhere deep inside of ffmpeg and he has no idea how to fix it right now.
So, I'm using "dirty hack" in my project - just adding copy of last frame with zero delay to GIF file before encoding.
I am rendering a video file from input pictures that come from a 3D engine at runtime (I don't pass an actual picture file, just RGB memory).
This works perfectly when outputting MP4 using CODEC_ID_H264 as video codec.
But when I want to create an MPG file using CODEC_ID_MPEG2VIDEO, the resulting file is simply broken. No player can play the video correctly and when I then want to concatenate that MPG with another MPG file, and transform the result MP4 in another step, the resulting .mp4 file has both videos, but many frames from the original MPG video (and only video! Sound works fine) are simply skipped.
At first I thought the MPG -> MP4 conversion was the problem, but then I noticed that the initial MPG, which comes from the video render engine, is already broken, which would speak for broken headers. Not sure if it is the system or sequence headers that are broken, though.
Or if it could be something totally different.
If you want to have a look, here is the file:
http://www.file-upload.net/download-7093306/broken.mpg.html
Again, the exact same muxing code works perfectly fine when directly creating an MP4 from the video render engine, so I'm pretty sure the input data, swscale(), etc. is correct. The only difference is that CODEC_ID_H264 is used and some additional variables (like qmin, qmax, etc.) are set, which are all specific to H264 so should not have an impact.
Also, neither avformat_write_header nor av_write_trailer report an error.
As an additional info, when viewing the codec data of the MPG in VLC player, it is not able to show the FPS, resolution and format (should show 640x360, 30 fps and 4:2:0 YUV).
I am using a rather new (2-3 months old, maybe) FFmpeg version, which I compiled from sources with MinGW.
Any ideas on how to resolve this would be welcome. Currently, I am out of those :)
Alright, the problem was not the avformat_write_header, but that I did not set the PTS value of each written video packet to AV_NOPTS_VALUE.
Once I do set it for each video packet, everything works fine.
I assumed that AV_NOPTS_VALUE was the default, as I never needed to set any special PTS value.
Mencoder has a lovely option for converting a mjpeg file into an avi file with an 'MJPG' codec that plays in VLC.
The command line to do this is:
mencoder filename.mjpeg -oac copy -ovc copy -o outputfile.avi -speed 0.3
where 0.3 is the ratio of the desired play framerate to the default 25 fps. All this does is make a copy of the mjpeg file, put an avi header on top and at the end, what seems to be an index of the frame positions in the file.
I want to replicate this in my own code, but I can't find documentation anywhere. What is the exact format of the index section? The header has extra filler bytes in it for some reason - whats this about?
Anyone know where I can find documentation? Both mencoder and vlc seem to have this codec built in.
After much work, study and fiddling around with HxD and RiffPad, I finally figured it out. It would take a long blog entry to explain it all, but basically there isn't really an 'MJPG' codec out there - mjpg just uses a few tricks and unusual parts of the avi standard to produce an indexed file.
The key is to place '00dc' and an Int32 length tag 8 bytes in front of each Jpeg open tag. If you want the avi to be random access, then you need an index at the end which points to each of the '00dc' tag positions.
VLC will play this natively. If you have ffmpeg installed, then Windows Media Player uses that to decode these types of mjpg files.
I am looking for some sites where I can download some short clips (5-20seconds) for testing purposes of video import routines.
Does anyone has some data sources for wmv, mpeg, mov, etc. ?
Thanks!
http://www.open-video.org/
http://www.archive.org/
http://reefvid.org/
Or just take some short vids with a digital video camera (or digital camera), import them onto your computer.
You can convert video files at http://www.zamzar.com/ to any format from any format.
Youtube, and convert it with ffmpeg
Or film trailers are often in mov (imdb: http://www.imdb.com/Sections/Trailers/ )
Or game trailers, gamershell / gamespot / ...
I was searching for this few days ago and here is best one I found:
http://www.jhepple.com/support/sample_movies1.htm
16 different files (two original samples), rather small sizes, covering most of popular formats.
MetaCafe allows you to download videos. I have some clips that I use for testing which are downloaded from there.
Some HD clips:
http://www.microsoft.com/windows/windowsmedia/musicandvideo/hdvideo/contentshowcase.aspx - Windows Media Audio and Video 9 Series, 1080p WMV files
http://www.apple.com/quicktime/guide/hd/ - H.264 in Quicktime containers
http://www.w6rz.net/ MPEG-2 Transport Stream Test Patterns