FFmpeg how generate a sequence of videos with bash - bash

i try to write an .sh that read a folder create a playlist of mp4 files and then generate an only big video with a sequence of all videos find in the folder, and encode it for dash:
printf "file '%s'\n" ./*.mp4 > playlist.sh
ffmpeg -f concat -safe 0 -i playlist.sh -c copy concat.mp4
Till now i follow the demux concat official guido to ffmpeg website.
Without result, also the following give me "more than 1000 frames duplicated between videos of the sequence"
ffmpeg -f concat -i playlist.sh -c:a aac -b:a 384k -ar 48000 -ac 2 -c:v libx264 -x264opts 'keyint=50:min-keyint=50:no-scenecut' -r 25 -b:v 2400k -maxrate 2400k -bufsize 1200k -vf "scale=-1:432 " out.mp4
Thanks a lot

Sry, cannot comment (yet)...
Your commands are correct, I could just concat some sample videos.
Do you always get the mentioned error, or also something else? And is the video working, or no video is created?
In most cases, the input video is incorrect. Wrong input format (not fitting to file extension) or worse like ending at wrong frame.
Perhaps you can make the video available?
PS: Needed to add -safe 0 to the second command to avoid error [concat # 0x7fbfd1000000] Unsafe file name './small.mp4'
Hint: Do not use file extension .sh for your list of video files. This extension is used for shell scripts, so it can be confusing. Just use .txt.
UPDATE #Massimo Vantaggio
We should not create new answers, but I cannot comment yours and I also don't know how to continue our discussion, so I edit my answer.
Your videos don't look very different. Can't see, what's wrong with the first one.
Perhaps you could use ffprobe -report input.mp4 to get more informations. Look for errors or warnings.
My assumption is still that the video was cut in a hard way (by conversion software), so keyframes are messed up or something else.
You can also try to first reencode your video with ffmpeg. After that, it should be complete compatible with ffmpeg ;)
Something like this:
ffmpeg -i small.mp4 -acodec aac -ab 192k -vcodec libx264 -vb 1024k -f mp4 output.mp4
Use -ab and -vb from your input video, or at least the bitrate from input. Quality will decrease a little bit and file size increase, but it should be okay.

Related

FFMPEG converting MP3 to MP4 is adding blank space, how to fix Terminal command?

I'm creating MP4 files from MP3 files + an image. Searching here at StackOverflow I found a Terminal command that gets me really close:
ffmpeg -loop 1 -r 1 -i pic.jpg -i input.mp3 -c:a copy -shortest -c:v libx264 output.mp4
Works almost perfectly so long as input.mp3 and pic.jpg are in the same folder. The problem is:
It frequently ends up with about 20-40seconds of blank space at the end of the resulting MP4. I can manually chop it off, but I'd love to find out if there's a way to alter this command so that the resulting MP4 file is exactly the length of the input MP3 file.
I don't know the ffmpeg commands well and know just enough Terminal to be dangerous. So I'm hoping it's something obvious haha.
This command should work for you:
ffmpeg -i input.mp3 -loop 1 -i pic.jpg -shortest -c:a copy -c:v mjpeg output.mp4
You do not need to set -r 1 with just one image and -loop 1.
I think -c:v mjpeg is more suitable to encode jpg than -c:v libx264.

Ffmpeg makes audio longer when changing bitrate

I've been using ffmpeg convert audio from one format to another and to change audio's bitrate. When I try to convert aac audio to mp3 audio using the command:
ffmpeg -i SomeAudio.aac -c:a mp3 -b:a 128k SomeOutputPath.mp3
everything works correctly and output audio is of the same length as the input audio (6 minutes, 15 seconds).
However, when I try converting it to aac audio using a similar command:
ffmpeg -i SomeAudio.aac -c:a aac -b:a 128k SomeOutputPath.aac
it makes the output audio longer (around 10 minutes). I have tried specifying output length but that still makes the video longer, it just cuts of part of the audio:
ffmpeg -i SomeAudio.aac -c:a aac -b:a 128k -t 00:06:15 SomeOutputPath.aac
Here is a link to the screenshot:
My suspicion is that message "Estimating duration from bitrate, this may be innacurate" (the one in the screenshot) is the root of my problem but I just haven't been able to find any useful information about it on the web.
Thanks a lot for any help in advance :)
The duration shown for raw AAC is a guess because it does not contain duration info. You can find the actual duration with:
ffmpeg -i input.aac -f null -
Or a faster, "close enough" method:
ffmpeg -i input.aac -c copy -f null -
Workaround is to remux to M4A:
ffmpeg -i input.aac -c copy output.m4a

Win/ffmpeg - How to generate a video from images under ffmpeg?

I know this is with great possibility a duplicate of same questions, but I dont get it working. So how can I under windows generate a mp4 video with h265 codec and 30fps of a bunch of images.
What I have done so far is to try this answers from this post:
Duplicate Question
If I try this:
C:\\ffmpeg-3.4.2-win64-static\\bin\\ffmpeg -r 1/5 -i img%%03d.jpg -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
I get the following output:
img%%03d.jpg: No such file or directory
I got filename like this:
img0001.jpg / img0002.jpg until img0030.jpg
So maybe I got the filename syntax wrong - I just dont know...
I have also tried this command:
C:\\ffmpeg-3.4.2-win64-static\\bin\\ffmpeg -framerate 29 -pattern_type glob -i img%%03d.jpg -c:v libx265 -crf 28 -c:a aac -b:a 128k output.mp4
but I get the same error..
Please help me I am not really into this ffmpeg stuff and need advice!
Maybe you can also show me how to set a directory of images in the ffmpeg params.
Thank you and greets!
Use
ffmpeg -framerate 30 -i "img%04d.jpg" -c:v libx265 -crf 28 output.mp4
Since your numbering has four digits (0001..), you need %04d.
Depending on how you're executing this command, you may need to escape the %
-pattern_type glob applies for wildcard matching, but your filename template is a smoothly numbered sequence so it's incorrect in this context.
You need to use img%%04d.jpg instead of img%%03d.jpg, because your filenames contain 4 digits.

How add scale in my ffmpeg command

i want convert video from any format to mp4. so i am using command:
ffmpeg -i ttt.mp4 -vcodec copy -acodec copy test.mp4
this is working perftectly but now i also add scale in this -s 320:240.
There also many other command for convert LIKE :
ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
but after convert by this command video not play in html5 player
BUT this is not working so tell me in my command how i add scale;
So please provide me solution for this .
Thanks in advance.
You have several problems:
In your command, you have -vcodec copy you cannot scale video without reencoding.
In the command you randomly found on the Internet, they are using AVI, which is not HTML5-compatible.
What you should do is:
ffmpeg -i INPUT -s 320x240 -acodec copy OUT.mp4
Adding to Timothy_G:
Video copy will ignore the video filter chain of ffmpeg, so no scaling is available (man ffmpeg is a great source of information that you will not find on Google). Notice that once you start decoding-filtering-encoding (i.e., no copy) the process will be much slower (x100 time slower or even more). The libx264 is recommended if you want compatibility with all browsers.
$ ffmpeg -i INPUT -s 320x240 -threads 4 -c:a copy -c:v libx264 OUT.mp4
vp9 will provide nearly 50% extra bandwidth saving, but only for supported browsers (Firefox/Chrome), and the encoding will much slower compared to libx264 (that itself is much slower that v:c copy):
$ ffmpeg -i INPUT -s 320x240 -c:a copy -c:v vp9 OUT.webm
Notice that there is a set of formats (containers) accepted by browsers (most admit mp4, some also webm, ...) and for each format there is a set of audio/video codecs accepted. For example you can use mp3 or aac with an mp4 file (container), but not with webm files.
http://en.wikipedia.org/wiki/HTML5_video#Supported_video_formats

JPG join MP3 to FLV

How to convert image and music to video? I would like YouTube video. I like FFMPEG command or other Ubuntu free software. I would like: *.mp3 + *.jpg = *.flv
Here is an example using a recent ffmpeg syntax:
ffmpeg -loop 1 -i image.jpg -i music.mp3 -shortest -c:v libx264 -crf 20 -tune stillimage -c:a copy output.mkv
This example will copy the audio instead of re-encoding to preserve quality. Adjust quality if desired with the CRF option. See the FFmpeg and x264 Encoding Guide for more information.
Super User (another StackExchange site) is a better place for ffmpeg usage questions since Stack Overflow is programming specific.
Today I was in need of merging an image and an audio file into a video file. Since none of the answers that I found on SO worked for me, I'm leaving here what worked for me after trial and error:
ffmpeg -loop 1 -t 205 -i audio.mp3 -i image.jpg -crf 20 test.flv
Where 205 is the duration of the input mp3 file in seconds -> 3:25 minutes.
(Tested with FFmpeg SVN-r13582)

Resources