Splitting video with ffmpeg gives weird output - bash

I want to split a video into (mostly) equal parts of 120sec length. The code below works but only the first video output is of normal mp4 format. The others seem like they start at where the previous video ends but only like the video file was never cut
First video timeline image:
next video timeline, as you can see it starts at 2min mark rather than at 0 as a separate video. Even though the file stats still show the video as being 2 minutes in length:
ffmpeg -i 1146redmp4.mp4 -c:v libx264 -crf 22 -map 0 -segment_time 120 -g 120 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*120)" -f segment 1146output%03d.mp4
If this is the correct output and not a bug. How do I have the video splits be output as their own video?

Looks like your player doesn't like starting timestamps to be non-zero.
ffmpeg -i 1146redmp4.mp4 -c:v libx264 -crf 22 -map 0 -segment_time 120 -g 120 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*120)" -reset_timestamps 1 -f segment 1146output%03d.mp4

Related

ffmpeg how to show each frame for 1 second?

I have a video, recorded at 7 fps. It's 17 seconds long and has 122 frames.
I want to keep all frames but show them 1 per second, I want the same video to last 122 seconds. I don't want to lose information, but I also don't want the file size to increase.
How can I do that? All the ffmpeg options I see change the frame rate but keep the duration or create/drop frames.
You want to slow down your video without reincoding your video to (possibly) keep the file size. You must strip the timestamps by exporting the video to a raw bitstream format:
ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb raw.h264
and than remux it with:
ffmpeg -fflags +genpts -r 1 -i raw.h264 -c:v copy output.mp4
-r 1 sets the framerate to 1.

How to create a full length video from images with FFmpeg?

I have more than a thousand images that I want to transform into a 3 minutes video. I tried using this line ffmpeg -r 30 -i "E:/White-box-Cartoonization/test_code/cartoonized_images/$flower%03d.bmp" -c:v libx264 -pix_fmt yuv420p out.mp4 it worked but creates only a 5 seconds video. What do I need to do to turn it into a full length 3 minutes video?
If you have 1250 images and want an output duration of 180 seconds:
ffmpeg -framerate 1250/180 -i input%03d.bmp -c:v libx264 -vf format=yuv420p output.mp4
This example results in a frame rate of 6.94. Some players can't handle such low frame rates. If your player does not like it then add the -r output option to make a normal output frame rate. ffmpeg will duplicate the frames but the output will look the same.
ffmpeg -framerate 1250/180 -i input%03d.bmp -c:v libx264 -vf format=yuv420p -r 25 output.mp4
For 3 minutes of video at 30 frames per second (-r parameter) you'd need 30*60*3 images: 5400 images.
Your source parameter specifies there would be only 3 digits, so you have a maximum of 1000 source images:
$flower%03d.bmp => $flower000.bmp .. $flower999.bmp
1000 images at 30 frames per second should give about 30 seconds of video ... if you actually have $flowerxxx.bmp files.
You might need a 4th digit in there somewhere.
$flower%04d.bmp

FFMPEG spends 6 seconds to create first video frame after i feed first image to it?

I use ffmpeg to convert a sequence of images to a video, i find that after i feed first image to it and almost 6 seconds later ffmpeg output first video frame to me.
I use command as follow:
ffmpeg -f image2pipe -r 100 -i pipe:0 -f flv -r 100 -tune zerolatency -preset ultrafast -bufsize 2M -codec:v libx264 -codec:a libmp3lame -bf 0 -muxdelay 0.001 -s 478x850 -b:v 2M pipe:1
Is my options is right?
Or others led to this result?
How can i get first video frame quickly once i feed the first frame?
Change probesize & analyzeduration options

Live streaming HLS via ffmpeg, How to force client to start playing from the beginning? From 1st segment

Is there a way, maybe via an ffmpeg option or flag, to force the client player to always start the playlist from the beginning when live streaming rather than the real time mid-stream?
Say the user comes in 1mn after the stream has started, rather than starting to watch at 1mn the player would start at the beginning of the video so minute zero.
Here is my ffmpeg command:
ffmpeg -f "screen capture" -s 1280x720 -r 30 -i :0.0+nomouse -f alsa -ac 2 -i pulse -async 30 -vcodec libx264 -pix_fmt yuv420p -acodec libfdk_aac -ar 44100 -b:a 64k -threads 0 -s 640x360 -f hls -g 1 -hls_time 1 -hls_list_size 1 -hls_allow_cache 0 /hls/#{#stream_name}/index.m3u8
Thanks!
Use -hls_list_size 0 to keep all segments in the playlist. Using a value greater than 0 will cause the playlist to use a sliding window of hls_list_size length.
Also of note, using -hls_time 1 will greatly increase your playlist file size. The Apple recommended value is 6 seconds so you should try to increase it to a multiple of your desired keyframe interval.

Image sequence of 1500 frames to loop 30 times in a 30 min video FFMPEG

Really struggling to get this to work, I just need to loop an image sequence. It is 25fps and exactly one second in duration (1500) I need this to basically loop for 30 mins, so it will loop 30 times. Using FFMPEG, here is the working 1500 frames being converted to MP4, like i said it has to be 30 mins in length:
ffmpeg -i "input_%04d.jpg" -c:v libx264 -b:v 1M -s 1080x810 -crf 28 -r 25 -pix_fmt yuv420p out.mp4
Use -loop 1 as an input option for an infinite loop, and then use -t 00:30:00 as an output option to cut off the video at thirty minutes. I would also suggest that you have a look at the H.264 Encoding Guide, and the FFmpeg wiki in general.
ffmpeg -loop 1 -i "input_%04d.jpg" -c:v libx264 -s 1080x810 -preset veryfast -crf 28 -r 25 -pix_fmt yuv420p -t 00:30:00 out.mp4

Resources