Home > Backend Development > PHP Tutorial > Detailed explanation of how PHP uses ffmpeg to extract audio and video images from videos

Detailed explanation of how PHP uses ffmpeg to extract audio and video images from videos

怪我咯
Release: 2023-03-10 13:56:02
Original
2064 people have browsed it

If you want to extract audio information from a video, the preferred technology is ffmpeg. ffmpeg is a very useful command line program that can be used to transcode media files. This article mainly introduces you to the relevant information on PHP using ffmpeg to extract audio and video images from videos. Friends in need can refer to it.

Preface

The name of FFmpeg comes from the MPEG video coding standard. The "FF" in front stands for "Fast Forward". FFmpeg is a set of An open source computer program used to record, convert digital audio and video, and convert it into streams. You can easily convert between multiple video formats.

FFmpeg users include Google, Facebook, Youtube, Youku, iQiyi, Tudou, etc.

Composition

## 1. libavformat: used to generate and parse various audio and video encapsulation formats, including obtaining the information required for decoding to generate Functions such as decoding context structures and reading audio and video frames, including demuxers and muxer libraries;

2. libavcodec: used for various types of sound/image encoding and decoding;

3. libavutil: including Some public tool functions;

4. libswscale: used for video scene scaling and color mapping conversion;

5. libpostproc: used for post-effects processing;

6 , ffmpeg: It is a command line tool used to convert video files to formats, and also supports real-time encoding of TV cards;

7. ffsever: It is an HTTP multimedia real-time broadcast streaming server that supports time shifting;

8. ffplay: It is a simple player that uses the ffmpeg library to parse and decode, and displays it through SDL;

Extracts audio and video images from the video

If you want to extract audio information from a video, the preferred technology is ffmpeg. Most of the ffmpeg tutorials on the Internet are:


For example, your file is test.mp4

Separate the video:

ffmpeg -i test.mp4 -vcodec copy -an Video stream.avi

Separate the audio:

ffmpeg -i test.mp4 -acodec copy -vn audio stream.mp3

Using this method, there is no problem in extracting the video. But when extracting audio, I encountered the following error:

Invalid audio stream. Exactly one MP3 audio stream is required. could not write header for output file #0 (incorrect codec parameters ) invalid argument
Copy after login

In fact, simply extracting audio and video does not need to be so complicated, just execute the following two lines. Now:

Separate the video:

ffmpeg -i test.mp4 Video stream.avi

Separate the audio:

ffmpeg -i test.mp4 Audio stream.mp3

The above is the detailed content of Detailed explanation of how PHP uses ffmpeg to extract audio and video images from videos. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template