Cannot repeat ffmpeg commnad in one bash script - bash

I have this simple bash script for ffmpeg conversion. If there is only one call for ffmpeg, script works well. If there are 2 or more calls, only the last call for ffmpeg is successfull. For previous calls there is the error: unable to find suitable output format for /var/.../.../.jpg : Invalid argumentlic_html. It seems to me it is needed to call ffmpeg by different way. Any idea?
#!/bin/bas
ffmpeg -y -i "http://xx/22.m3u8" -qscale:v 2 -vframes 1 -vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: text='%{localtime}': fontsize=20: fontcolor=white#0.9: x=20: y=20: box=1: boxcolor=red#0.2" /var/xxx/22.jpg
ffmpeg -y -i "http://xx/23.m3u8" -qscale:v 2 -vframes 1 -vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: text='%{localtime}': fontsize=20: fontcolor=white#0.9: x=20: y=20: box=1: boxcolor=red#0.2" /var/xxx/23.jpg

Related

Combine two ffmpeg commands (segment and still photo)

is it possible to combine this command
ffmpeg -i video.mp4 -map 0:s:0? -c copy -movflags empty_moov+default_base_moof+frag_keyframe -f segment output%03d.mp4
with a command that can take a still from the first segment
ffmpeg -ss 00:00:00.00 -i output001.mp4 -vframes 1 -q:v 2 still.jpg"
Append the second command to the first:
ffmpeg -i video.mp4 -map 0:s:0? -c copy -movflags empty_moov+default_base_moof+frag_keyframe -f segment output%03d.mp4 -frames:v 1 -q:v 2 still.jpg

How to get image from video and combine other image using ffmpeg

I want to get a frame from video to combine with other image
using two ffmpeg commands as:
command 1:
ffmpeg -ss 3 -i video.mp4 -vf \"select=gt(scene\,0.4)\"
-frames:v 5 -vsync vfr -vf fps=fps=1/100
-vf scale=150:150 output.jpeg
command 2:
ffmpeg -i output.jpeg -i other.png -filter_complex "[0:v][1:v]
overlay=(W-w)/2:(H-h)/2:enable='between(t,0,20)'"
-pix_fmt yuv420p -c:a copy output2.jpg
how to combine two commands in one, or
how to get frame from video and combine other image in one?
You can combine the two commands using the and && after the first command which allows you to execute the second command based on whether the first command completed successfully:
ffmpeg -ss 3 -i video.mp4 -vf "select=eq(n\,4)"
-frames:v 5 -vsync vfr -vf fps=fps=1/100
-vf scale=150:150 output.jpeg
&&
ffmpeg -i output.jpeg -i other.png -filter_complex "[0:v][1:v]
overlay=(W-w)/2:(H-h)/2:enable='between(t,0,20)'"
-pix_fmt yuv420p -c:a copy output2.jpg
Now if you want to combine multiple images onto one, Take a look at this solution

FFMPEG Combining Two Commands Into One

Im currently trying to combine trim and delogo together, looked over a few tutorials but i just have no clue.
trim:
ffmpeg -i input.mp4 -ss 00:00:05 -t 00:00:10 -async 1 ouput.mp4
delogo:
ffmpeg -i input.mp4 -vf "delogo=x=1075:y=9:w=170:h=52" -c:a copy ouput.mp4
I want to combine these two commands so i can run one execution which will do both within, instead of 2 separate commands
As simple as
ffmpeg -i input.mp4 -ss 5 -t 10 -vf "delogo=x=1075:y=9:w=170:h=52" -c:a copy ouput.mp4

FFmpeg | Option loop not found

The loop option is not working with gif image.
When I'm working with png image the code good.
But when I'm working with animated gif image the error is thrown Option loop not found.
In my example I'm trying to create the video from input image with specific duration.
ffmpeg -loop 1 -t 5 -i 15324210315b56e3a78abe5.png -i watermark.png -filter_complex "[0]scale=trunc(iw/2)*2:trunc(ih/2)*2[v];[v][1]overlay=x=(W-w-10):y=(H-h-10)" output.mp4
Below command is not working
ffmpeg -loop 1 -t 5 -i 15323488345b55c9a2b2908.gif -i watermark.png -filter_complex "[0]scale=trunc(iw/2)*2:trunc(ih/2)*2[v];[v][1]overlay=x=(W-w-10):y=(H-h-10)" output.mp4
GIFs are handled by a seperate demuxer module, not the generic image sequence demuxer. The gif demuxer has a separate option. See command below.
ffmpeg -ignore_loop 0 -t 5 -i 15323488345b55c9a2b2908.gif ...
The python script for gif to video conversion using ffmpeg library
f"/opt/ffmpeglib/ffmpeg -ignore_loop 0 -i {lambda_file_path} -c:v libx264 -t 10 -pix_fmt yuv420p {lambda_output_file_path}

How to Loop Input video x number of time using FFMPEG?

I want to loop same video 4 times and output as video using ffmpeg.
SO I create code like this in ffmpeg.
ffmpeg -loop 4 -i input.mp4 -c copy output.mp4
but when i run it it give the error like this.
Option Loop Not Found.
how to do this withour error. Please Help Me
In recent versions, it's
ffmpeg -stream_loop 4 -i input.mp4 -c copy output.mp4
Due to a bug, the above does not work with MP4s. But if you wrap to a MKV, it works for me.
ffmpeg -i input.mp4 -c copy output.mkv
then,
ffmpeg -stream_loop 4 -i output.mkv -c copy output.mp4
I've found an equivalent work-around with input concatenation for outdated/bugged versions -stream_loop:
ffmpeg -f concat -safe 0 -i "video-source.txt" -f concat -safe 0 -i "audio-source.txt" -c copy -map 0:0 -map 1:0 -fflags +genpts -t 10:00:00.0 /path/to/output.ext
This will loop video and audio independently of each other and force-stop the output at 10 hour mark.
Both text files consist of
file '/path/to/file.ext'
but you must make sure to repeat this line enough times to keep the output satisfied.
For example, if your total video time is less than total audio time then video output will stop earlier than intended and the audio will keep playing until either -t 10H is reached or audio ends prematurely.

Resources