Monday, 31 December 2018

17 FFmpeg Commands For Beginners

17 FFmpeg Commands For Beginners

#1 Getting audio/video file information
ffmpeg -i video.mp4

(use -hide_banner flag to hide information such as version, configuration details, copyright notice, build and library options etc.)

#2 Converting video files into AVI
ffmpeg -i video.mp4 video.avi

(use -qscale 0 to preserve the quality of your source video file)

#3 understand comman Abbr
-vn – Indicates that we have disabled video recording in the output file.
-ar – Set the audio frequency of the output file. The common values used are 22050, 44100, 48000 Hz.
-ac – Set the number of audio channels.
-ab – Indicates the audio bitrate.
-f – Output file format. In our case, it’s mp3 format.

#4 Change resolution of video files
ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4

#5 Compressing video files
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4

#6 Compressing Audio files
ffmpeg -i input.mp3 -ab 128 output.mp3


#7 Removing audio stream from a media file
ffmpeg -i input.mp4 -an output.mp4

#8 Removing video stream from a media file
ffmpeg -i input.mp4 -vn output.mp3

#9 Cropping videos
ffmpeg -i input.mp4 -croptop 100 -cropbottom 100 -cropleft 300 -cropright 300 output.mp4

#12 Set the aspect ratio to video
ffmpeg -i input.mp4 -aspect 16:9 output.mp4

#13 Trim a media file using start and stop times
ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4

#14 Changing resolution and Reencoding
ffmpeg -i 1.mp4 -vf scale=1280:720 -acodec aac -vcodec libx264   NewFile.mp4 -hide_banner

#15 Joining multiple video parts into one
ffmpeg -f concat -i join.txt -c copy output.mp4

(join.txt will have path of all videos)

#16 Add subtitles to a video file
fmpeg -i input.mp4 -i -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4

#17 Increase video playback speed
ffmpeg -i inputvideo.mp4 -vf "setpts=0.5*PTS" outputvideo.mp4

Monday, 5 November 2018

How to change the video resolution from 1280X720 to 600X400

Question: Download the php-ffmpeg library (If not downloaded)?
composer require php-ffmpeg/php-ffmpeg

Question: How to change the video resolution from 1280 X 720 to 600 X 400?
    //load the library
    require_once 'ffmpeglib/vendor/autoload.php'; 
    $ffmpeg = FFMpeg\FFMpeg::create();

    //format of new video
    $format = new FFMpeg\Format\Video\X264();

    //path of folder where video exist

    //change the resolution

    //load the video in ffmpeg
    $videoObj = $ffmpeg->open($videoFolderPath.'/input_video.mp4');
    //filter the video with height/width
    $videoObj->filters()->resize(new FFMpeg\Coordinate\Dimension($width, $height), FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_INSET, true);
    //save the video
    $videoObj->save($format, $videoFolderPath.'/output_video.mp4');