Home  >  Article  >  Backend Development  >  PHP uses ffmpeg to extract audio and video images from videos

PHP uses ffmpeg to extract audio and video images from videos

陈政宽~
陈政宽~Original
2017-06-28 13:42:553024browse

If you want to extract the audio information from the 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 tools

function

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 file formats, and also supports real-time encoding of TV cards;

7. ffsever: It is an HTTP

MultimediaReal-time broadcast streaming server, supports time shifting;

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

Extract audio and video images from videos

If you want to extract audio information from videos, the preferred technology is ffmpeg. Most of the ffmpeg usage 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


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

Separate the video:

ffmpeg -i test.mp4 Video stream.avi

Separate the audio:

ffmpeg -i test.mp4 audio stream.mp3

Summary

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

Statement:
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