I'm using ffmpeg to cut and covert a part of a long video but when using the "-to" option ffmpeg keeps encoding till the end of the video and wont stop.
Here's my command:
ffmpeg -ss 00:22:59 -i input.mkv -to 00:23:15.5 -c:v libx264 -c:a aac output.mp4
if i change to "-t" and enter my desired duration, problem goes away. but since i have a very long video and many tasks i need to use "-to" which is easier for me.
Thanks in advance.
Basically, -ss when used as an input option, seeks to the given time and resets timestamps, so that the first selected frame has timestamp 0. So, in your command, t and to will have the same effect.
You have to either use
ffmpeg -ss 00:22:59 -copyts -i input.mkv -to 00:23:15.5 -c:v libx264 -c:a aac output.mp4
(not recommended)
or
ffmpeg -ss 00:22:59 -to 00:23:15.5 -i input.mkv -c:v libx264 -c:a aac output.mp4
(needs ffmpeg build > Nov 19 2017)
or
ffmpeg -i input.mkv -ss 00:22:59 -to 00:23:15.5 -c:v libx264 -c:a aac output.mp4
(slowest of the three)
Related
I am using this command to mute audio :
ffmpeg -i input.mp4 -af "volume=enable ='between(t,10,15)':volume=0, volume=enable ='between(t,20,25)':volume=0, volume=enable ='between(t,30,35)':volume=0, volume=enable ='between(t,40,45)':volume=0, volume=enable ='between(t,50,55)':volume=0" -c:v copy -c:a aac -b:a 192K output.mp4
How can I repeat or loop this filter without writing it again and again?
For example, this commands zooms video after specific seconds :
ffmpeg -i input.mp4 -vf "zoompan=z='if(lte(mod(time,6),3),zoom+1.5,zoom-3)':x='iw/2-(iw/zoom)/2':y='ih/2-(ih/zoom)/2':d=1:fps=24" -c:v libx264 -crf 20 -preset:v ultrafast -profile:v high -g 60 -threads 2 -c:a aac -b:a 192K output.mp4
How can I use volume filter like this to mute audio after specific seconds?
Tip: you can target multiple time ranges or conditions in one enable expression by adding them, e.g.
ffmpeg -i input.mp4 -af "volume=volume=0:enable ='between(t,10,15)+between(t,20,25)+between(t,30,35)+between(t,40,45)+between(t,50,55)'" -c:v copy -c:a aac -b:a 192K output.mp4
If the pattern is regular, like 'every 10 seconds, for 2 seconds', you generally use the mod function, which returns the remainder of the left operand by the right operand. Then you enclose this is a comparative function like lte (less than or equal to)
In this case,
ffmpeg -i input.mp4 -af "volume=volume=0:enable ='lte(mod(t\,10)\,2)'" -c:v copy -c:a aac -b:a 192K output.mp4
I want to use FFMPEG (the latest version) to cut a 24 fps matroska file. So I am using -ss and -t, but I noticed with VLC that the very first frame is ALWAYS duplicated one time, no matter the file or the duration I choose. While it is not a really serious issue, but I wanted to know if there was a way to prevent that.
Here is the command I am using:
ffmpeg -ss 00:01:26.086 -i file.mkv -t 00:00:02.000 -c:v libx264 -crf 18 output.mp4
add -vsync vfr in your cmd may be helpful
ffmpeg -ss 00:01:26.086 -i file.mkv -vsync vfr -t 00:00:02.000 -c:v libx264 -crf 18 output.mp4
I am trying to encode a video to webm for playing through a HTML5 video tag. I have these settings...
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:a 128k -b:v 1M -c:a libopus output.webm
The results aren't great, video has lost lot's of it's sharpness. Looking at the original file I can see the bitrate is 1694kb/s.
Are there any settings I can add or change to improve the output? Would maybe a 2 pass encode improve things?
Try with
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus output.webm
Adjust the CRF value till the quality/size tradeoff is ok. Lower values produce bigger but better files.
Try to run two passes:
ffmpeg -i file.mp4 -b:v 0 -crf 30 -pass 1 -an -f webm -y /dev/null
ffmpeg -i file.mp4 -b:v 0 -crf 30 -pass 2 output.webm
From - https://trac.ffmpeg.org/wiki/Encode/VP9
I am creating a small script to stream a images on rtmp server but FFMPEG command taking 100% CPU. Please have a look on my code.
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -loop 1 -i "Digital-Wallet-.jpg" -t 00:30:00 -r 1 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -f flv "rtmp://rtmpserver"
Encoding is CPU intensive. Remove -r 1 and add -framerate 1, -re, and -shortest.
ffmpeg -f lavfi -i anullsrc -loop 1 -framerate 1 -re -i "Digital-Wallet-.jpg" -t 00:30:00 -c:v libx264 -c:a aac -preset:v ultrafast -pix_fmt yuv420p -shortest -f flv "rtmp://rtmpserver"
The default image demuxer frame rate is 25, so your command was unnecessarily converting 25 frames per second to 1 frame per second which is inefficient. The above changes fixes that.
-re will slow down the reading of the input to the native frame rate of the input. It is useful for real-time output and live streaming. Otherwise ffmpeg will attempt to encode as fast as possible.
I added -shortest to end the output when the shortest stream ends (the image) because anullsrc was set to encode indefinitely.
This code works fine for some audio files (makes a slideshow of JPG pictures with a PNG watermark and MP3 audio, while maintaining aspect ratio) but for this audio file, the pictures are not showing for the first two seconds or so of the video:
ffmpeg -y -framerate 1/12 -i "media/%03d.jpg" -i "media/audio.mp3" -loop 1 -i "media/watermark.png" -filter_complex "[0:v]scale=iw*min(3840/iw\,2160/ih):ih*min(3840/iw\,2160/ih), pad=3840:2160:(3840-iw)/2:(2160-ih)/2[ss]; [ss][2:v] overlay=main_w-overlay_w-10:main_h-overlay_h-10:shortest=1[out]" -map "[out]" -map 1:a -c:v libx264 -r 24 -preset veryfast -tune stillimage -pix_fmt yuv420p -c:a copy -map_metadata -1 "media/video.mkv" -report
I tried converting the audio into different formats of MP3, tried changing bitrates, changed audio to stereo, and even tried converting it to a WAV. None of these things worked.
Here are the report results for when I run this command.
If it makes a difference, I'm using Ubuntu 14.04 and FFmpeg version N-77455-g4707497 (latest version).
This command should work, but I consider this bizarre behaviour as FFmpeg should be automatically padding frames as per output spec
ffmpeg -y -framerate 1/12 -i "media/%03d.jpg" -i "media/audio.mp3" -loop 1 -i "media/watermark.png" -filter_complex "[0:v]scale=iw*min(3840/iw\,2160/ih):ih*min(3840/iw\,2160/ih), pad=3840:2160:(3840-iw)/2:(2160-ih)/2,fps=24[ss]; [ss][2:v] overlay=main_w-overlay_w-10:main_h-overlay_h-10:shortest=1[out]" -map "[out]" -map 1:a -c:v libx264 -r 24 -preset veryfast -tune stillimage -pix_fmt yuv420p -c:a copy -map_metadata -1 "media/video.mkv"