Opencv failed to parse AVI - python

I've installed opencv3.1.0 through anaconda along with the ffmpeg package. opencv still gives
Failed to parse avi: index was not found
when I try to read an .avi file.
Is it possible to have .avi files work straight out of anaconda or do I have to compile everything manually (a process I have not have had much luck with so far).

Related

I have pip installed pydub but still didn't work

After I had pip installed pydub and SpeechRecognition, I still can't make the program run successfully although I extracted the files from ffmpeg and specified the folder name bin in the corresponding directory. I tried to find solutions to solve the problem but it sill didn't work after I followed the steps clearly from the web. May I ask what is the good way to read .wav files using pydub AudioSegment?
Warning (from warnings module):
File "C:\Python38\lib\site-packages\pydub\utils.py", line 171
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
Make sure that you have ffmpeg http://www.ffmpeg.org/ installed. You can get help from this official page.
Other thing that I can think of is that ffmpeg is installed and is in your path but not in the path of the process using pydub.
If this is the reason for the error, then you can set the absolute path to ffmpeg directly like shown below:
import pydub
pydub.AudioSegment.ffmpeg = "/absolute/path/to/ffmpeg"
sound = AudioSegment.from_mp3("test.mp3")
Give this a try.

What is the best way to batch download videos from teachable.com in Python?

I have got access to a course on teachable.com but this access is time-bound. If I wanted to keep the videos what is the best way to download them using Python, much like coursera-dl or youtube-dl?
I have tried the urlretriever method but it doesn't seem to download the video file but some video-like file that can't be played.
I have tried using this with no success
Download video from URL in Python
The expected output is a list of mp4 files. I can then extend it to organise the files by modules.
Check out this package: https://github.com/barakagb/gb-dl
You can install it using: pip install gb-dl

Could not open codec 'libopenh264': Unspecified error

I am using OpenCV to process videos for my research. I have Python 2.7 and OpenCV 3.2 versions installed on Windows 10. When I do background subtraction on a video in Python using OpenCV, it works fine and produces the output. However, when I try to save the background subtracted video, it throws this error:
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:779)
warning: MAH00119.avi (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:780)
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 28 and format 'h264 / raw H.264 video'
Failed to load OpenH264 library: openh264-1.6.0-win64msvc.dll
Please check environment and/or download library: https://github.com/cisco/openh264/releases
[libopenh264 # 0000000001f5bf60] Incorrect library version loaded
Could not open codec 'libopenh264': Unspecified error
I am processing MP4 videos. And I followed the instructions carefully while installing ffmpeg, like adding the bin's path to environment variables. I don't know what else to do. Stuck on this for three days now.
Any help would be much appreciated!
Thanks in advance!!
The error message you are getting says that openCV can't load the H264 codec. H264 doesn't come by default with the default installation of openCV.
To add the H264 codec download 'openh264-1.6.0-win64msvc.dll.bz2' from https://github.com/cisco/openh264/releases/tag/v1.6.0.
Extract the file and move the extracted DLL to the same directory as your python file. OpenCV should now be able to find the DLL and load the H264 codec.
Note that in your error message, openCV is looking for the openh264-1.6.0-win64msvc.dll (failed to load: openh264-1.6.0-win64msvc.dll.bz2) which is what we have now provided.

how to get a video file's orientation in Python

I would like to load a video file's frames into a numpy array. I want the frames to be properly upright, which means I need to read the orientation metadata in the video file, and rotate the loaded frames accordingly.
I have a means of loading the frames (opencv's python bindings), so all I need is a way to read the video file's orientation metadata.
I'm trying to read a .MOV file recorded off my iPhone, in python running on an Ubuntu 14.04 machine.
Stuff I've looked at:
opencv: no way of inspecting video orientation
hachoir-metadata: doesn't display orientation metadata
enzyme: only works on .mkv files, AFAICT.
ffmpeg: no longer available as a stand-alone executable on Ubuntu's repositories. This is a dealbreaker since I'd rather just hand-specify the rotation rather than go through the trouble of compiling ffmpeg from source just to get video orientation.
PIL, pyexiv: AFAICT, only loads image files.
I'm running the code on an Ubuntu 14.04 machine, so I'm looking for libraries or command-line programs available on that platform.
Any pointers would be greatly appreciated.
We use MediaInfo (libmediainfo)
it is running both on Windows and Ubuntu, and you can get all you need (codec, aspect, fps, bitrate, orientation...).
use qtrotate. It's just one file, and it works on .Mov files
https://github.com/danielgtaylor/qtrotate

extract single frame from video

I am trying to write a script that will extract a single frame from a user uploaded video clip in order to create a thumbnail. It sounds like either OpenCV or ffmpeg will do what I need, but I am having trouble installing them.
I tried installing OpenCV using apt-get install libopencv-dev, and it looks like everything worked, but when running import cv2 in Python, it says there is no such module. Also tried installing using these instructions, but when I run the import, it hangs for a second or two and then says Failed to initialize libdc1394.
I then tried to install ffmpeg with pyffmpeg, but the most recent version of pyffmpeg I could find was released 3 years ago and built for Python2.6 on Ubuntu 10.10, while I am using 2.7 on Ubuntu 12.04.
Does anyone have experience installing either of these, or would recommend something else for this purpose?
If you are trying to install ffmpeg, you can do this more easily if you have homebrew and then use brew to install it. It's a lot more complicated otherwise.
If you just want to be able to complete this task, and it doesn't have to be the tool you're listing, you could try ffmpeg-python. After you have it installed, you can use the get_video_thumbnail example to get a single image. You could also probably tweak the read_frame_as_jpeg example to get a single image from a frame if you want.

Categories

Resources