How can I get the resolution (width and height) for a video file from a linux command line?

Use ffprobe (part of FFmpeg toolkit) example: ffprobe -v quiet -print_format json -show_format -show_streams ~/Movies/big_buck_bunny_720p_5mb.mp4 output: { “streams”: [ { “index”: 0, “codec_name”: “h264”, “codec_long_name”: “H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10”, “profile”: “Main”, “codec_type”: “video”, “codec_time_base”: “1/50”, “codec_tag_string”: “avc1”, “codec_tag”: “0x31637661”, “width”: 1280, “height”: 720, “coded_width”: 1280, “coded_height”: 720, “has_b_frames”: 0, … Read more

FFmpeg: How to split video efficiently?

The ffmpeg wiki links back to this page in reference to “How to split video efficiently”. I’m not convinced this page answers that question, so I did as @AlcubierreDrive suggested… echo “Two commands” time ffmpeg -v quiet -y -i input.ts -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 -sn test1.mkv time ffmpeg -v quiet -y … Read more

My ffmpeg output always add extra 30s of silence at the end

Use ffmpeg -y -loop 1 -framerate 2 -i “some.png” -i “with.mp3” -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest -fflags +shortest -max_interleave_delta 100M “result.mkv” Containers (AVI, MP4, MKV) usually store multiple streams in an interleaved fashion i.e. a few seconds of video, then a few seconds of audio, and so on. So … Read more

Cannot open “.mp4” video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine

I have had the same issue before, solved by this step: Check your OpenCV python version >>> from cv2 import __version__ >>> __version__ ‘2.4.0’ Then Copy your opencv_ffmpeg.dll to C:\Python27\ and rename it to relevant your OpenCV Python Version. In my case I had to rename it to opencv_ffmpeg240.dll. Update: On Windows, you can find … Read more

How to control key-frame generation of ffmpeg?

It is possible for ffmpeg to generate Key frame at irregular interval, based on scene change detection. key frame interval can be controlled by GOP size. the following options can be used -g (FFmpeg) Keyframe interval, also known as GOP length. This determines the maximum distance between I-frames. Very high GOP lengths will result in … Read more

process video stream from memory buffer

I had a similar need recently. I was looking for a way in OpenCV to play a video that was already in memory, but without ever having to write the video file to disk. I found out that the FFMPEG interface already supports this through av_open_input_stream. There is just a little more prep work required … Read more

Getting length of video

Here is an example: using DirectShowLib; using DirectShowLib.DES; using System.Runtime.InteropServices; … var mediaDet = (IMediaDet)new MediaDet(); DsError.ThrowExceptionForHR(mediaDet.put_Filename(FileName)); // find the video stream in the file int index; var type = Guid.Empty; for (index = 0; index < 1000 && type != MediaType.Video; index++) { mediaDet.put_CurrentStream(index); mediaDet.get_StreamType(out type); } // retrieve some measurements from the video … Read more