Home Backend Development PHP Tutorial PHP uses ffmpeg to add text subtitles to videos ffmpeg linux ffmpeg command ffmpeg c

PHP uses ffmpeg to add text subtitles to videos ffmpeg linux ffmpeg command ffmpeg c

Jul 29, 2016 am 08:49 AM
ffmpeg

This article mainly introduces the method of using PHP to add subtitles to the video using ffmpeg. It analyzes the techniques of using PHP to add letters to the video using ffmpeg. It has certain reference value. Friends who need it can refer to it.

The example in this article describes how to use ffmpeg to add subtitles to videos in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

<?php
$dir = './'; // set to current folder
if ($handle = opendir($dir)) {
 while(false!== ($file = readdir($handle))) {
 if ( is_file($dir.$file) ){
 if (preg_match("'\.(avi)$'", $file) ){
 $sub_file = str_ireplace(".avi", ".srt", $dir.$file);
 $idx_file = str_ireplace(".avi", ".idx", $dir.$file);
 $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
 $out_file = str_ireplace(".avi", ".mp4", $dir.$file);
 flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
 }
 else{
 continue;
 }
 }
 }
 closedir($handle);
}
//flv_convert_get_thumb('input.avi', 'input.srt', 'output.jpg', 'output.ogm');
// code provided and updated by steve of phpsnaps ! thanks
// accepts:
// 1: the input video file
// 2: path to thumb jpg
// 3: path to transcoded mpeg?
function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){
 // get thumbnail
 $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb;
 $res = shell_exec($cmd);
 // $res is the output of the command
 // transcode video
$cmd = 'mencoder '.$in.' -o '.$out_vid.' -sub '.$in_sub.' -subfont-text-scale 3.0 -subpos 99 -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encop$
 $res = shell_exec($cmd);
}
?>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

Original address: http://www.manongjc.com/article/839.html

Related reading:

php source code using FFMPEG to obtain video thumbnails and total video duration

php to capture a picture in the video

php ffmpeg intercepts the specified frame of the video into a picture

The above introduces how to use ffmpeg to add text subtitles to videos in PHP, including the content of ffmpeg. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Practice of video splicing using Golang and FFmpeg Practice of video splicing using Golang and FFmpeg Sep 28, 2023 am 08:37 AM

Practical introduction to video splicing using Golang and FFmpeg: In daily life, we often encounter situations where we need to merge multiple video files into one, such as splicing multiple recorded videos into a complete video file. To achieve this goal, this article will introduce how to use Golang and FFmpeg libraries to implement the video splicing process, and provide specific code examples. 1. What are Golang and FFmpeg? Golang (Go language) is an open source programming language developed by

Golang and FFmpeg: How to achieve audio mixing and separation Golang and FFmpeg: How to achieve audio mixing and separation Sep 27, 2023 pm 02:24 PM

Golang vs. FFmpeg: How to implement audio mixing and separation, specific code examples required Summary: Audio processing is an essential part of many multimedia applications. In Golang, we can use the FFmpeg library to achieve audio mixing and separation. This article will introduce how to use Golang to call the FFmpeg library to achieve audio mixing and separation, and provide specific code examples. By studying this article, readers will learn how to use Golang and FFmpeg to implement audio processing

Golang and FFmpeg: How to implement audio synthesis and segmentation Golang and FFmpeg: How to implement audio synthesis and segmentation Sep 27, 2023 pm 10:52 PM

Golang and FFmpeg: How to implement audio synthesis and segmentation, specific code examples are required Summary: This article will introduce how to use Golang and FFmpeg libraries to implement audio synthesis and segmentation. We will use some specific code examples to help readers understand better. Introduction: With the continuous development of audio processing technology, audio synthesis and segmentation have become common functional requirements in daily life and work. As a fast, efficient and easy to write and maintain programming language, Golang, coupled with FFmpeg

Golang and FFmpeg: How to implement audio format conversion and compression Golang and FFmpeg: How to implement audio format conversion and compression Sep 28, 2023 pm 07:13 PM

Golang and FFmpeg: How to implement audio format conversion and compression, specific code examples are needed. Introduction: In audio file processing, sometimes you encounter the need to convert audio formats or compress audio file sizes. As a powerful programming language, Golang, combined with FFmpeg, a popular audio and video processing tool, can achieve fast and efficient audio format conversion and compression. This article will introduce how to use Golang and FFmpeg to achieve audio format conversion and compression, and give specific code examples.

Golang and FFmpeg: Technology for real-time video stream analysis and recognition Golang and FFmpeg: Technology for real-time video stream analysis and recognition Sep 27, 2023 pm 02:31 PM

Golang and FFmpeg: Technology to implement real-time video stream analysis and recognition, requiring specific code examples Introduction: In today's digital and intelligent era, video technology is increasingly used. Among them, the analysis and recognition of real-time video streams play an important role in security monitoring, intelligent transportation, face recognition and other fields. This article will introduce how to use the technology combining Golang and FFmpeg to realize the analysis and identification of real-time video streams, and provide specific code examples. 1. Introduction to Golang Golang is a

The practice of using Golang and FFmpeg to achieve video de-flickering The practice of using Golang and FFmpeg to achieve video de-flickering Sep 27, 2023 pm 04:46 PM

A practical overview of using Golang and FFmpeg to achieve video de-flickering: Video flickering is a challenge often encountered in video processing. When the frame rate of the recorded video does not match the lighting frequency, it may cause flickering in the video. This article will introduce how to use Golang and FFmpeg libraries to achieve video de-flickering, and provide specific code examples. Steps: Install the FFmpeg library: First, we need to install the FFmpeg library in the Golang development environment. able to pass

How to install PHP FFmpeg extension on server? How to install PHP FFmpeg extension on server? Mar 28, 2024 pm 02:39 PM

How to install PHPFFmpeg extension on server? Installing the PHPFFmpeg extension on the server can help us process audio and video files in PHP projects and implement functions such as encoding, decoding, editing, and processing of audio and video files. This article will introduce how to install the PHPFFmpeg extension on the server, as well as specific code examples. First, we need to ensure that PHP and FFmpeg are installed on the server. If FFmpeg is not installed, you can follow the steps below to install FFmpe

Installation guide for FFmpeg in Ubuntu environment Installation guide for FFmpeg in Ubuntu environment Jan 02, 2024 pm 02:30 PM

I recently started doing my graduation project, which is about the design of a video surveillance system under Linux. Now I am starting to configure the Linux environment. In order to facilitate future reference, I will write down my thoughts during the installation. I hope everyone can learn and make progress together! Before installing ffmpeg, you must first install yasm. 1. Install yasm. The yasm I use is yasm-1.2.0.tar.gz. This version is tarxzvfyasm-1.2.0.tar.gz#cdyasm-1.2.0#./configure. Note: Do not use prefix to specify the installation path. , otherwise the consequences will be endless! Sister, I understand it deeply, really! #make #makeinsta

See all articles