ffmpeg - slideshow from set of images ignoring first image - linux

I can create slideshow with below command
ffmpeg -y -f image2 -r 1/15 -i image%d.jpeg -y -r 45 video.mp4
Video is created successfully ,, but its ignoring the 1st image..
for example in current folder i have
image1.jpeg
image2.jpeg
image3.jpeg
but slide show is created with image2.jpeg and image3.jpeg only..(i.e 30 second video with 2 image is created..but i expected 45 second video with 3 images displaying 15 sec per image)

What's wrong with your command is the -r 45 as an output option. You're telling ffmpeg to produce a video with 45 fps output rate. You probably don't want that.
Use the fps filter to set the framerate:
ffmpeg -r 1/15 -i img%d.jpeg -vf fps=25 output.mp4
If you use
ffmpeg -r 1/15 -i img%d.jpeg output.mp4
you will get a video with ~0.07 fps, and three frames, meaning a roughly 45 second long video (3 / 0.07). This gives the expected result, but it might not be playable in all players.
Note:
-y is not needed twice. Only supply it once before -i.
-f image2 is not needed.
Using -r as an output option to force another frame rate skips the first frame immediately in some players. I consider this a bug, which is now reported in this ticket .

Related

Per second frame count using ffmpeg

I need to count the number of frames in a video captured by a camera on a per-second basis. I haven't found a solution using ffmpeg or ffprobe (or something else) to output the number of frames per second (maintaining a constant frame rate is not guaranteed because of the capture mechanism and needs to be verified).
So far, I've needed to run ffmpeg and ffprobe separately. First, I run ffmpeg to trim the video:
ffmpeg -ss 00:00:00 -to <desired time in seconds> -i <in_video> -c copy <out_video>
Then, I run ffprobe to count the number of frames in the snippet:
ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv <out_video>
Is there one command to output the number of frames for each second in the video?
Run
ffmpeg -report -i <in_video> -an -vf select='if(eq(n,0),1,floor(t)-floor(prev_selected_t))' -f null -
In the generated report, search for select:1.000000
that will get you lines of the form
[Parsed_select_0 # 000001f413152540] n:270.000000 pts:138240.000000 t:9.000000 key:0 interlace_type:P pict_type:P scene:nan -> select:1.000000 select_out:0
The t is the timestamp and the n is the frame index. Check the frame index for each successive t. The difference is the frame count for that 1 second interval.

Ffmpeg mixing audio only for n number of videos using offset with an altered duration

I want to mix audio stream of n amount of video files with ffmpeg, with certain parameters such as:
Duration: I want to specify how long each audio is going to play for each output. For example if I specify ffmpeg -i -d:5 first.mp4 -i second.mp4 it should play the audio from first.mp4 for 5 seconds (I don't know if -d:5 is a real tag it's just an example I've made ).
Starting point: I want to specify when a given file is going start on the output, I probably need to use -itsoffset 5 but I don't know if it's the right one in terms of interacting with other commands, in on itself it works fine. For example: ffmpeg -i -isoffset 5 first.mp -i second.mp4 causes the second.mp4 to start immediately, and first.mp4 to start after 5 seconds.
Segmentation: This is the tricky one, I want to specify at which point the input's audio should start. It's like the -ss flag but the problem is it's not working together with -itsoffset. For example when I say ffmpeg -i -ss 5 first.mp4 -i second.mp4 both files should start immediately on the output, but first.mp4 should start on it's 5 seconds. So the 5th second of first.mp4 is heard at the 1st second of the output.
This is what I'm trying to achieve, my problem is that I don't know how to implement 'duration' and -ss is not working together with -itsoffset.
At the end I should have something similar to this:
ffmpeg -y -d 5 -itsoffset 3.5 -i first.mp4 -d 10 -ss 10 -itsoffset 5.3 -i 3 -vn -copyts -async 1 -filter_complex amix=inputs=2 out.mp
Which should result in an audio that sounds like this: The first 3.5 seconds are empty, no audio is heard. Then first.mp4 is heard from it's beginning for 5 seconds. When the outputs timestamp reaches 5.3, the 10th seconds of second.mp4 is heard (while first.mp4 is still playing, it's supposed to play until 8.5, so I should hear both files at the same time.) for 10 seconds.
I can't find an example of this and some sources are out-of date.
Try something like this:
ffmpeg -t 5 -ss 0 -i first.mp4 \
-t 10 -ss 10 -i second.mp4 \
-filter_complex \
[0:a]adelay=3500:all=1[c1];\
[1:a]adelay=5300:all=1[c2];\
[c1][c2]amix=inputs=2[aout] \
-map [aout] out.mp3

FFMPEG merging audio and video to get resulting video

I need to merge audio and video using ffmpeg so that, it should result in a video with the same duration as of audio.
I have tried 2 commands for that requirement in my linux terminal. Both the commands work for a few of the input videos; but for some other input_videos, they produce output same as the input video, the audio doesn't get merged.
The commands, I have tried are -
ffmpeg -i wonders.mp4 -i Carefull.mp3 -c copy testvid.mp4
and
ffmpeg -i wonders.mp4 -i Carefull.mp3 -strict -2 testvid.mp4
and
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict
experimental output.mp4
and these are my input videos -
samplevid.mp4
https://vid.me/z44E
duration - 28 seconds
size - 1.1 MB
status - working
And
wonders.mp4
https://vid.me/gyyB
duration - 97 seconds
size - 96 MB
status - not working
I have observed that the large size (more than 2MB) of the input video is probably the issue.
But, still I want the fix.

openRTSP default 25fps encoding (not 24)

I want to capture the RTSP stream from some IP cameras, and after looking around I found 2 great tools to do this: avconv and openRTSP
openRTSP -u user password rtsp://10.48.34.125/axis-media/media.amp
avconv -i "rtsp://user:password#10.48.34.125/axis-media/media.amp" -vcodec copy -f mp4 10.48.34.125.mp4
but for some voodoo reason when I need to use URLs without an specific extension, such as:
rtsp://user:password#10.48.34.46/
avconv returns 401 Unauthorized
so I'm stuck with openRTSP at the moment...
The thing is, unlike avconv, openRTSP outputs a raw file which is encoded to 25fps, which made some of my videos look like they where in fast-forward. I found a (cpu expensive) way to re-encode the file to a closer frame rate to what I need:
avconv -r 7 -i video-H264-1 -r 24 -f mp4 10.48.34.28.mp4
(in this example I'm forcing the frame rate of the raw file to be 7, and the frame rate of the output file to be 24. I tried using openRTSP build-in flags, but the output file still had a frame rate of 25: openRTSP -f 7 -u user password rtsp://10.48.34.145/mpeg4/media.3gp)
Sadly the video looks odd at certain points, and that's because the original stream sometimes has a variable frame rate (for example at night).
My question is, is there some way to deactive this default encondig to 25fps?
And why 25? I mean, isn't the norm 24?
try:
avconv -rtsp_transport tcp -i rtsp://server -an -vcodec copy -f mp4 10.48.34.28.mp4
if you want to change original video rate to 24 you must transcode it:
avconv -rtsp_transport tcp -i rtsp://server -an -vcodec libx264 -r 24 -f mp4 10.48.34.28.mp4

Add audio (with an offset) to video with FFMPEG

I have a 10 minute video and a 50 minute audio mp3.
The video starts at 500 seconds into the audio.
Using FFMPEG, how can I add the the audio to the video but specify a 500 seconds audio offset (So that they sync up)?
EDIT:
Down the bottom of this page it suggests how to specify an offset.
$ ffmpeg -i video_source -itsoffet delay -i audio_source -map 0:x -map 1:y .......
However, when I apply this, it still starts the audio from the start.
We are 8 years later, and the -itsoffset does work.
Exactly as in your linked page:
ffmpeg -i input_1 -itsoffset 00:00:03 -i input_2
Note that you place the -itsoffset switch before the input you want to delay, in this case input_2 will be delayed.
So in your case that the video starts later, you would add -itsoffset 00:08:20 before the video input.
I couldn't get audio to offset properly either, and some searching suggests that -itsoffset is currently broken.
You could try and get/compile an old version of ffmpeg before it broke (which doesn't sound like much fun).
Alternately, you could pad your audio with the necessary silence using something like sox and then combine:
sox -null silence.mp3 trim 0 500 # use -r to adjust sample-rate if necessary
sox silence.mp3 input.mp3 padded_input.mp3
ffmpeg -i in.avi -i padded_input.mp3 out.avi

Resources