使用ffmpeg缩放和剪切部分视频

I am trying to upload a video that is 640 x 480. Using FFmpeg I am trying to resize to a square but I am having much difficulty.

if i use s=320x320 in my command or scale 320x320

    ->setVideoScale(320, 320)

the image is distored.

If i change the aspect ratio 1:1 i get black bars.

is there a way to actually just cut a RECT in the video. IE i want to be able to re save the video and it only capture

   x 0 to 320
   y 0 to 320  

or whatever bounds I pick.

Basically I do not want to re-size I just want to be able to re record a certain portion of the video. is this possible?

dongzen5577
dongzen5577 听起来你想添加它作为答案,所以我可以接受!
接近 6 年之前 回复
duanjing7298
duanjing7298 听起来像你想要裁剪:ffmpeg.org/ffmpeg-filters.html#Examples-19
接近 6 年之前 回复

1个回答

Check out FFMPEG's video filters. There is a crop option that will do what you're asking for, specifically the first example.

Depending on the library you're using to interface with FFMPEG, something like the following might work per your example:

->addCommand('-vf', 'crop=320:320:0:0');
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

android使用ffmpeg,通过图片和视频合成mp4

最近接到个任务 就是用使用android app 把图片和视频合成mp4文件,文件的时长要根据mp3文件来定, 研究了好几天 实在没有头绪,求大神解惑 ,我现在的情况就是找个找几个库 (因导入ffmpeg总是出错)但还是无法解决 合成后的视频大小还是1-2秒 肯定不是mp3的时间 求大神帮个忙 或者给个思路 问题1.android studio 想制作这种功能是否使用第三方库是否能完成 问题2.怎么合成后 视频的时长是mp3的 而且能播放出mp3的声音。 能帮我解决可付费

Android 如何使用ffmpeg合并MP4视频

用ffmpeg合并裁减后的视频,视频都是MP4格式的,请问该怎么合并呢?我在网上看到的都是命令,但是不会在android中用,刚刚接触ffpeg,什么都不懂,求资料和帮助!!!谢谢

使用ffmpeg把一系列的图片生成视频?

如题,使用ffmpeg把一系列的图片生成视频,图片显示的间隔我想自己控制,比如显示完第一张图片后,我想隔10秒显示第二张图片,然后隔 20秒显示第三张图片,不知道这样的需求可以使用ffmpeg命令来实现吗?具体命令是什么?

求一个使用FFmpeg实现录制视频的Demo

需要使用FFmpeg录制视频,但感觉FFmpeg有点难。。。

ffmpeg 水印在不同的视频显示不一样大?

使用ffmpeg先将两个分辨率不同的视频合并,然后再添加文字水印,文字水印再两个视频显示大小不一样,是因为什么?

python怎么使用ffmpeg播放视频文件

想用python做一个视频播放器,不知道python怎么调用ffmpeg。视频非线性编辑方面打算用moviepy实现

iOS开发视频解码库FFmpeg

本人做刚开始做iOS,对于使用过的第三方类、库,基本知道了解那种模式,包含头文件,然后有现成能的方法去调用。但是最近开始接触视频方面的,研究了两天,始终不理解FFmpeg是什么,像是第三方库吧,但是没有看到具体实在可调用的方法,并且在网上搜到的Demo,似乎配合着第三方视频播放类去使用,但是在Demo中没发现他们之间关联的部分,不理解FFmpeg到底是怎么发挥作用的。请教一下这FFmpeg是怎么使用的,原理。

Java 使用ffmpeg进行视频转换问题

使用Java代码进行视频格式转换,使用了ffmpeg+mencoder,但是转换出来的视频大小为50KB左右,也就是为空。对此,我在命令行下进行了测试,发现转出来的视频大小也是50KB左右,这个是什么原因? 命令如下: ffmpeg -i 被转资源 目标资源 给出其他视频格式转mp4的转换代码最好,谢谢啦。

FFMPEG 视频截取 其中的几秒 出现问题。

我用 ffmpeg.exe -ss 00:00:02 -i input.mp4 -vcodec copy -acodec copy -t 00:00:05 e:\output_file.mp4 截取的视频总是从第一秒开始 截取 总视频大小为7秒 我想要的是从第三秒到第七秒的视频 我是视频源input.mp4是 用ffmpeg -f dshow -i video="screen-capture-recorder" -f dshow -i audio="virtual-audio-capturer" -r 5 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec libmp3lame input.mp4 录制的。 到底哪里出了问题。好纠结

我想使用ffmpeg将图像用作drawtext视频的背景

<div class="post-text" itemprop="text"> <p>Currently i am able to create video with ffmpeg using the drawtext filters to draw text on a black background Now Remain one thing that seems difficult to me, I thought it would be easy until i come to discover i don't got it right. I want to use an image as background for the drawtext filters. I.e I want to use image as background of the video instead of using the background color or video background. Please someone should take me through on this this is my code `</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>echo shell_exec('ffmpeg -f lavfi -i color=color=black -vf drawtext="textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50" -t '.$words_count.' textover09.mp4 -report'); `</code></pre> </div> </div> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>ffmpeg started on 2018-01-07 at 22:53:03 Report written to "ffmpeg-20180107-225303.log" Command line: ffmpeg -loop 1 -i elena.jpg -vf "drawtext=textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50" -t 46.2 textover09.mp4 -report ffmpeg version git-2017-12-28-be4dfbf Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-18) configuration: --prefix=/usr/local/ffmpeg --extra-cflags=-I/usr/local/ffmpeg/include --extra-ldflags=-L/usr/local/ffmpeg/lib --bindir=/usr/local/bin --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libtheora --enable-filter=drawtext --enable-libfreetype libavutil 56. 7.100 / 56. 7.100 libavcodec 58. 9.100 / 58. 9.100 libavformat 58. 3.100 / 58. 3.100 libavdevice 58. 0.100 / 58. 0.100 libavfilter 7. 8.100 / 7. 8.100 libswscale 5. 0.101 / 5. 0.101 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Splitting the commandline. Reading option '-loop' ... matched as AVOption 'loop' with argument '1'. Reading option '-i' ... matched as input url with argument 'elena.jpg'. Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'drawtext=textfile=text.txt:expansion=normal:fontfile=FreeSerif.otf: y=h-line_h-20:x=-100*t: fontcolor=white: fontsize=50'. Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '46.2'. Reading option 'textover09.mp4' ... matched as output url. Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'. Finished splitting the commandline. Parsing a group of options: global . Applying option report (generate a report) with argument 1. Successfully parsed a group of options. Parsing a group of options: input url elena.jpg. Successfully parsed a group of options. Opening an input file: elena.jpg. [NULL @ 0x2c1fe80] Opening 'elena.jpg' for reading [file @ 0x2c207c0] Setting default whitelist 'file,crypto' [image2 @ 0x2c1fe80] Format image2 probed with size=2048 and score=50 [image2 @ 0x2c1fe80] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0 nb_streams:1 [image2 @ 0x2c1fe80] Opening 'elena.jpg' for reading [AVIOContext @ 0x2c21f80] Statistics: 3871771 bytes read, 0 seeks [mjpeg @ 0x2c21940] marker=d8 avail_size_in_buf=3871769 [mjpeg @ 0x2c21940] marker parser used 0 bytes (0 bits) [mjpeg @ 0x2c21940] marker=e0 avail_size_in_buf=3871767 [mjpeg @ 0x2c21940] marker parser used 16 bytes (128 bits) [mjpeg @ 0x2c21940] marker=e2 avail_size_in_buf=3871749 [mjpeg @ 0x2c21940] marker parser used 3160 bytes (25280 bits) [mjpeg @ 0x2c21940] marker=db avail_size_in_buf=3868587 [mjpeg @ 0x2c21940] index=0 [mjpeg @ 0x2c21940] qscale[0]: 2 [mjpeg @ 0x2c21940] index=1 [mjpeg @ 0x2c21940] qscale[1]: 2 [mjpeg @ 0x2c21940] marker parser used 132 bytes (1056 bits) [mjpeg @ 0x2c21940] marker=c0 avail_size_in_buf=3868453 [mjpeg @ 0x2c21940] Changing bps from 0 to 8 [mjpeg @ 0x2c21940] sof0: picture: 5616x3744 [mjpeg @ 0x2c21940] component 0 2:2 id: 0 quant:0 [mjpeg @ 0x2c21940] component 1 1:1 id: 1 quant:1 [mjpeg @ 0x2c21940] component 2 1:1 id: 2 quant:1 [mjpeg @ 0x2c21940] pix fmt id 22111100 [mjpeg @ 0x2c21940] marker parser used 17 bytes (136 bits) [mjpeg @ 0x2c21940] marker=c4 avail_size_in_buf=3868434 [mjpeg @ 0x2c21940] marker parser used 0 bytes (0 bits) [mjpeg @ 0x2c21940] escaping removed 6222 bytes [mjpeg @ 0x2c21940] marker=da avail_size_in_buf=3868014 [mjpeg @ 0x2c21940] marker parser used 3861792 bytes (30894336 bits) [mjpeg @ 0x2c21940] marker=d9 avail_size_in_buf=0 [mjpeg @ 0x2c22540] marker parser used 132 bytes (1056 bits) [mjpeg @ 0x2c22540] marker=c0 avail_size_in_buf=3868453 [mjpeg @ 0x2c22540] sof0: picture: 5616x3744 [mjpeg @ 0x2c22540] component 0 2:2 id: 0 quant:0 [mjpeg @ 0x2c22540] component 1 1:1 id: 1 quant:1 [libx264 @ 0x2c24c40] i16 v,h,dc,p: 40% 53% 4% 3% [libx264 @ 0x2c24c40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 10% 27% 7% 9% 8% 8% 9% 11% [libx264 @ 0x2c24c40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 12% 11% 6% 9% 11% 7% 9% 6% [libx264 @ 0x2c24c40] i8c dc,h,v,p: 53% 17% 21% 8% [libx264 @ 0x2c24c40] Weighted P-Frames: Y:0.0% UV:0.0% [libx264 @ 0x2c24c40] ref P L0: 56.3% 9.9% 21.1% 12.8% [libx264 @ 0x2c24c40] ref B L0: 74.5% 22.4% 3.1% [libx264 @ 0x2c24c40] ref B L1: 98.3% 1.7% [libx264 @ 0x2c24c40] kb/s:4673.55 [AVIOContext @ 0x2c28ac0] Statistics: 32768 bytes read, 0 seeks</code></pre> </div> </div> </div>

在YII中使用ffmpeg从mp4视频中获取图像

<div class="post-text" itemprop="text"> <p>I have written a code to get an image from an uploaded mp4 video using ffmpeg in YII.</p> <p>In localhost, when i have written absolute path like <code>d:/wamp/www/projectname/ffmpeg</code> like this, it is working perfectly and i am getting image but when I tried like below using <code>baseurl</code></p> <pre><code>$var="http://".$_SERVER['HTTP_HOST'].Yii::app()-&gt;request-&gt;baseUrl; $ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe"; </code></pre> <p>I am unable to get the image from video.</p> <p>Here is my code</p> <pre><code>$var="http://".$_SERVER['HTTP_HOST'].Yii::app()-&gt;request-&gt;baseUrl; $ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe"; // $uploaddir is my file upload path $video = $uploaddir.$image_name; //where to save the image $iname = basename($image_name, ".mp4"); $image = $uploaddir.'/'.$iname.'_img.jpg'; //time to take screenshot at $interval = 5; //screenshot size pn $size = '640x480'; //ffmpeg command $cmd="$ffmpeg -i ".$video." -ss 00:00:01.100 -f image2 -vframes 1 ".$image; exec($cmd); </code></pre> </div>

ffmpeg如何快速裁剪视频?

如题,如何使用FFmpeg快速的裁剪视频到指定的宽高,频率?-y -i /Video/output11.mp4 -acodec copy -vf scale=853:480,crop=480:480:280:0 -s 480x480 /Video/output1.mp4 这个命令怎么优化才能更快?

java-ffmpeg分割合并视频

java-ffmpeg分割合并视频是如何做的?谁有这个demo也行帮助理解一些

基于ffmpeg的视频段截取

想基于ffmpeg开发视频段截取的程序,可不可以直接将原视频解封装,然后将要截取视频部分的packet重新封装进输出文件? ![图片说明](https://img-ask.csdn.net/upload/201505/06/1430881355_987532.jpg)

关于c#内部调用ffmpeg.exe处理视频文件时的命令

直接通过cmd,手打ffmpeg -i in.avi -vf drawtext="fontfile=arial.ttf: timecode='09\:57\:00\:00': r=10: \x=(w+tw)/2:fontcolor=Red:fontsize=30" -an -y out.avi进行视频处理时该命令是能够正确完成功能的。 但是,在c#内部调用时该如何把那串字符正确的输入进去啊,怎么输都不对。 System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.WorkingDirectory = Application.StartupPath; proc.StartInfo.UseShellExecute = false; //use false if you want to hide the window string command_line = "-i " + filename + " -vf drawtext=\"" + "fontfile=arial.ttf: timecode='09\\:57\\:00\\:00': r=10: \\x=(w+tw)/2:fontcolor=Red:fontsize=30\"" + "-an " + name1; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.FileName = "ffmpeg"; proc.StartInfo.Arguments = command_line; proc.Start();

使用PHP-FFMpeg(Laravel 5)的视频有意义的缩略图

<div class="post-text" itemprop="text"> <p>I'm working on a project using Laravel 5 and the <a href="https://github.com/PHP-FFMpeg/PHP-FFMpeg" rel="nofollow noreferrer">PHP-FFmpeg</a> Library.</p> <p>Previously someone else asked this question "<a href="https://superuser.com/questions/538112/meaningful-thumbnails-for-a-video-using-ffmpeg">Meaningful thumbnails for a Video using FFmpeg</a>" that works from the command line.</p> <p>However, I want to implement the functional equivalent using the PHP-FFmpeg Library.</p> <p>I have scanned both Stack Overflow and the Unit Tests for PHP-FFmpeg to try and figure out the correct syntax, but it is just not jumping out at me. </p> <p>So I'm hoping someone with more experience with PHP-FFmpeg can give me some pointers or an example of how to achieve the same results as the command line calls referenced in this post: "Meaningful thumbnails for a Video using FFmpeg".</p> <p>Thanks in advance for everyone's help.</p> <p>BTW, This is my first post on Stack Overflow so the site won't let me post all the relevant links (limit 2) or create a tag for "PHP-FFmpeg". </p> </div>

使用Go和FFmpeg合并两个视频

<div class="post-text" itemprop="text"> <p>I have two videos, Video A &amp;&amp; Video B. I want to combine both videos to a new video C using golang. I tried FFmpeg, but I am unable to cross compile it for ARM devices and getting error message.</p> <blockquote> <p>/usr/local/ffmpeg/lib/libavdevice.so: file not recognized: File format not recognized collect2: error: ld returned 1 exit status</p> </blockquote> <p>Please advise.<br> Opening two media player at once is not an option. With amd64 I compile without having any issue. </p> </div>

ffmpeg转换视频格式问题

使用java调用ffmpeg转换多个视频,会同时把多个视频进行转,这样会导致CPU使用率达到100%,如果同时转换的视频到达某一数目,电脑就会卡死。 本人尝试过实时获取输出流来查看转换状态,代码如下: Process process = Runtime.getRuntime().exec(cmd); final BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String s = null; while((s=br.readLine()) != null){ System.out.println(s); } 但,当执行到s=br.readLine()方法时会卡着不动了。 请问有大神知道如何控制ffmpeg转换完一个视频后,再进行第二个视频的转换。

使用VidStab进行PHP-FFMpeg视频稳定

<div class="post-text" itemprop="text"> <p>I'm using <a href="https://github.com/PHP-FFMpeg/PHP-FFMpeg" rel="nofollow">PHP-FFMpeg</a> in a Laravel 5.2 application to stabilize videos with the help of <a href="https://gist.github.com/maxogden/43219d6dcb9006042849" rel="nofollow">VidStab</a>. I have all the dependencies and everything installed correctly and I can follow the directions on the VidStab repo to stabilize my videos via the command line.</p> <p>My question is how could I do this nicely (the Laravel way) from within PHP? I know I can add a custom filter to the Video object like this:</p> <pre><code>$video = $ffmpeg-&gt;open('shaky_video.mp4'); $video-&gt;addFilter(new CustomFilter('vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=transform.trf')); </code></pre> <p>But how can I execute this command without the need for <code>$video-save()</code>, which I think is designed to output a video/audio file and not the <code>trf</code> analysis file?</p> <p>I suppose I could just run a PHP exec() command, but I would like to keep this as much object oriented PHP as I can. Any suggestions?</p> <p>Thanks in advance!</p> <hr> <p>I've tried this (added <code>-f null -</code> to filter and then tried running <code>save()</code> to execute the command), but it still creates the mp4 file instead of the trf file:</p> <pre><code>$video = $ffmpeg-&gt;open('shaky_video.mp4'); $video-&gt;addFilter(new CustomFilter('vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=transform.trf -f null -')); $video-&gt;save(new X264(), 'stabilized.mp4'); </code></pre> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c# cad插入影像 c#设计思想 c#正则表达式 转换 c#form复制 c#写web c# 柱形图 c# wcf 服务库 c#应用程序管理器 c#数组如何赋值给数组 c#序列化应用目的博客园
立即提问