FFMPEG use -strict -2 - ffmpeg

Hi I've been recently using the command below
Ffmpeg -i song.mp3 -loop 1 -i image.jpg -filter_complex \
"[0:a]showfreqs=mode=line:ascale=log:fscale=log:s=1280x518[sf]; \
[0:a]showwaves=s=1280x202:mode=p2p[sw]; \
[sf][sw]vstack[fg]; \
[1:v]scale=1280:-1,crop=iw:720[bg]; \
[bg][fg]overlay=shortest=1:format=auto,format=yuv420p,drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf:fontcolor=white:x=10:y=10:text='\"Rated80s Prophets Prey\" by Comics On Film'[out]" \
-map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a libopus output.mp4
from this post Showfreqs and showwaves over background image?.
However I changed the output file to from output.mkv to output.mp4 as I would prefer to use mp4
I get the below error
[mp4 # 0x7f962b816800] opus in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature
Error initializing output stream 0:0 --
[libopus # 0x7f962b819800] 1 frames left in the queue on closing
The main information from that error is
opus in MP4 support is experimental, add '-strict -2' if you want to use it.
but where do I use -strict -2 within the command to make the command possible

You can add it anywhere after the last input and before the output URL.
e.g.
ffmpeg -i song.mp3 -loop 1 -i image.jpg -strict -2 -filter_complex ...
or
-map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a libopus -strict -2 output.mp4
You can also write it as -strict experimental.

Related

Multiple sounds + watermark overlay not working with ffmpeg

I have a problem with an ffmpeg command.
I want to add the same sound several times in the final video and then add a watermark above.
When I do the full command, it doesn't work correctly because the sound is only played once (the first reference):
ffmpeg -i "assets/frame%05d.png" -i "assets/sound.mp3" -loop 1 -i
"assets/watermark.png" -filter_complex
"[1:a]adelay=1000|1000[s1];[1:a]adelay=3000|3000[s2];[s1][s2]amix=2[a];[0:v][2:v]overlay=shortest=1[outv]"
-map "[outv]" -map "[a]" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"
When I don't add the watermark, it works correctly:
ffmpeg -i "assets/frame%05d.png" -i "assets/sound.mp3" -filter_complex
"[1:a]adelay=1000|1000[s1];[1:a]adelay=3000|3000[s2];[s1][s2]amix=2[a]"
-map 0:v -map "[a]" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"
Try this:
ffmpeg -i "assets/frame%05d.png" \
-stream_loop -1 -i "assets/sound.mp3" \
-loop 1 -i "assets/watermark.png" \
-filter_complex "[1:a]adelay=1000|1000[s1];\
[1:a]adelay=3000|3000[s2];\
[s1][s2]amix=2[a];\
[0:v][2:v]overlay=shortest=1[outv]" \
-map "[outv]" -map "[a]" -shortest \
-c:v libx264 -pix_fmt yuv420p -preset ultrafast -y "result.mp4"
-stream_loop -1 input option loops the input infinitely and -shortest output option stops the audio when video is done.
p.s., I think an aecho filter can combine the 2nd adelay and amix filters.
I found the problem was that the different frames that make up the video were not all correctly encoded which caused the problem with the sounds.
ffmpeg can't read indexed PNG correctly.
You must therefore use this option (for those like me who use imagick):
$imagick->setOption('png:color-type', 6);
$imagick->writeImage('frame00000.png');

ffmpeg - cannot find matching stream for unlabeled input pad 1 on filter Parsed_amix_0

I have an mp4 and I am trying to merge multiple audio files into it. The command is generated dynamically given the number of audio and their offset. Everything works when I have multiple audios to merge but doesn't when I have one audio file to merge.
Here is the command to merge single audio into the mp4
ffmpeg -y -i ./video.mp4 -itsoffset 00:00:1.753 -i ./audio0.mp3 -filter_complex amix -map 0:v -map 1:a -c:v copy -async 1 -c:a aac -strict experimental -t 10 ./finalVideo.mp4
Here is the command to merge multiple audio files which works
ffmpeg -y -i ./video.mp4 -itsoffset 00:00:1.753 -i ./audio0.mp3 -itsoffset 00:00:0.113 -i ./audio/audio1.mp3 -filter_complex amix -map 0:v -map 1:a -map 2:a -c:v copy -async 1 -c:a aac -strict experimental -t 10 ./finalVideo.mp4

Unrecognized option 'map 0:a?'

Trying to make derivatives of silent video files is failing. My understanding is adding a trailing ? to the -map option makes ffmpeg ignore that stream if it does not exist, but its not working. The full script is below.
ffmpeg -n -vsync 0 -nostdin -v info -hide_banner -stats -i "${FILE}" -movflags faststart -pix_fmt yuv420p -map 0:v -map 0:a? -c:v libx264 -vf "yadif=1,format=yuv420p" -crf "${CRFVALUE}" -preset "${PRESETSPEED}" -maxrate "${MAXRATE}"k -bufsize 1835k -c:a aac -strict -2 -b:a 384k -f mp4 "${OUTPUT}"
withouth the ? after -map 0:a it works with files containing audio streams but not with silent ones. with the ? it fails all files. from the ffmpeg documentation: "A trailing ? will allow the map_channel to be optional: if the map_channel matches no channel the map_channel will be ignored instead of failing."
why isn't it working here?

Combine Two Commands (Get Video from Images)

I have 300 images and i wants to generate video from these images.
i am new to FFMPEG so now i am using two commands to generate video from images.
Command to generate video from images which also add Logo on video
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -pix_fmt yuv420p test_video.mp4
After using above command i am getting the video to add audio to this video i am using below command
ffmpeg -i test_video.mp4 -i inputfile.mp3 -c:v libx264 -c:a libvorbis -shortest final_video.mp4
which generates video and i am getting below message
MPEG-4 AAC decoder is required to play the file
Help to combine this both command. if possible can we add sound without any decoder required
Log for command 1 https://drive.google.com/file/d/1zS7gvrPy69VK_MkyE4127FpX2kEziJHq/view?usp=sharing
and Log command 2 https://drive.google.com/file/d/1rHqVGzj7f003aWP6eISiyUjsES8_EWuw/view?usp=sharing
Try next command:
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -i inputfile.mp3 -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -map 2:a -c:a copy -pix_fmt yuv420p -shortest test_video.mp4
-map 2:a is needed to skip image in case if there is cover image in track.
With -c:a copy track will not be re-encoded, so you will have mp3 inside of your video file.

ffmpeg adding ass subtitles: error initializing filter 'subtitles' with args ''

So I want to convert my mkv files to mp4 with hardcoded subs
While this works fine:
ffmpeg.exe -i "[X] File - 1 [Y].mkv" -c:v libx264 -preset veryfast -b:v 2750k -pass 1 -c:a aac "file_out.mp4"
When I want to add the ASS subtitles (from the same MKV file) like so:
ffmpeg.exe -i "[X] File - 1 [Y].mkv" -vf subtitles="[X] File - 1 [Y].mkv" -c:v libx264 -preset veryfast -b:v 2750k -pass 1 -c:a aac "file_out.mp4"
the following error is produced:
[Parsed_subtitles_0 # 00000000259c840] No filename provided!
[AVFilterGraph # 000000000094dc20] Error initializing filter 'subtitles' with args ''
It seems like somehow it didn't pick up the filename for the subtitles. So what's the deal with that?
Okay I fixed it already by doing the following instead of -vf ... :
-filter_complex "subtitles='[X] File - 1 [Y].mkv'"
If you want to use a path, then use the following (forward slashes):
-filter_complex "subtitles='X\:/Users/~/[X] File - 1 [Y].mkv'"
For me this syntax works
ffmpeg -i C:\Users\USER\Downloads\output.mp4 -filter_complex "subtitles='C\:/Users/USER/Downloads/subtitle.srt'" -c:v libx264 -crf 20 -c:a aac -strict experimental -b:a 192k C:\Users\USER\Downloads\foutput.mp4

Resources