ffmpeg combined video increaes duration - ffmpeg

I am splitting video file in scenes and then process them. After processing and combining them I gain a lot of extra seconds. Original duration 24:29 after combining 24:59.
First I split video with this command
ffmpeg -i test.mkv -f segment -c copy -map 0 -y $HOME/Encoding/SPLIT/OUTPUT-%07d.mkv
And then I process each file encoding x264 to AV1:
ffmpeg -i $HOME/Encoding/SPLIT/OUTPUT-0000125.mkv -map 0:0 -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe /tmp/fifo_stream
SvtAv1EncApp -i /tmp/fifo_stream --profile 0 --preset 6 --qp 35 --max-qp 63 --min-qp 1 --rc 0 --keyint 240 --input-depth 10 --crf 30 --rc 0 --passes 2 --film-grain 0 -b $HOME/Encoding/CONVERTED/OUTPUT-0000125.ivf
and store information about every converted file in $HOME/Encoding/list.txt file
Then I combine files:
ffmpeg -f concat -safe 0 -i $HOME/Encoding/list.txt -y $HOME/Encoding/encoded.mp4
result video gained extra 30 seconds. Someone knows what to do so that combined file duration will be same as original?

Related

Trying to get frame timestamp with ffmpeg from a RTSP camera

I'm trying to retrieve the timestamp of each frame of a camera using an rstp stream and them.
For recording I use the following command line and it's work :
ffmpeg
-correct_ts_overflow 0
-probesize 1G
-analyzeduration 1G
-i rtsp://user:password#ip:port
-vcodec copy
-bsf:v h264_mp4toannexb
-bufsize 10M
-acodec copy
-f ssegment
-segment_list_flags live
-segment_atclocktime 1
-reset_timestamps 1
-write_empty_segments 1
-segment_time 15
-segment_list C:\Video\Delivery\ffmpeg\list.video
-segment_list_type csv
-strftime 1 "C:\Video\Delivery\ffmpeg\%%Y%%m%%d_%%H-%%M-%%S.ts"
And for some utility I would like to be able to retrieve the timestamp of the machine when I receive a frame, so by searching a bit I found different post on '-mkvtimestamp_v2'. By trying it alone with the camera as if below:
ffmpeg
-copyts ^
-correct_ts_overflow 0 ^
-probesize 1G ^
-analyzeduration 1G ^
-i rtsp://user:password#ip:port
-c copy
-pix_fmt yuv420p
-flush_packets 1
-vframes 10
-reset_timestamps 1
-timestamp now
-copyts
-f mkvtimestamp_v2 timestamp.txt
-vsync 0
It works perfectly.
But from the moment I try to record AND try to retrieve the timestamp simultaneously with the following command :
ffmpeg
-use_wallclock_as_timestamps 1
-correct_ts_overflow 0
-probesize 1G
-analyzeduration 1G
-i rtsp://user:password#ip:port
-vcodec copy
-bsf:v h264_mp4toannexb
-bufsize 10M
-acodec copy
-f ssegment
-segment_list_flags live
-segment_atclocktime 1
-reset_timestamps 1
-write_empty_segments 1
-segment_time 15
-segment_list C:\Video\Delivery\ffmpeg\list.video
-segment_list_type csv
-strftime 1 "C:\Video\Delivery\ffmpeg\%%Y%%m%%d_%%H-%%M-%%S.ts"
-copyts
-vcodec copy
-flush_packets 1
-f mkvtimestamp_v2 log.txt
-vsync 0
I get a lot of: Non-monotonous DTS in output stream 0:0 warning.
I also have on average one minute delay between the recorded timestamps, and the real timestamp.
And the first video recorded have a bugged timer on a video player like this : Here
I've tried arranging the command in different orders but I get nothing conclusive...
So if you have any idea that would be a big help!
I work on Windows 10 and I use ffmpeg-3.4.1.
Cordially,
Jay
I solved it by piping the second output to another ffmpeg instance. The reason why I think this works is because the second ffmpeg will discard the timestamp offset that was added by -use_wallclock_as_timestamps 1 and reset the offset to 0.
ffmpeg -use_wallclock_as_timestamps 1 -i rtsp://#ip:port -c copy -copyts -y -f mkvtimestamp_v2 timestamps.txt -vsync 0 -c copy -f mpegts - | ffmpeg -f mpegts -i - -c copy -f segment output-segment-%d.mp4
Another problem however with this solution is that if RTSP drops some frames, then the mkvtimestamp_v2 file will be skipping some time values, making it hard to correlate the segments with the timestamps.txt file.
So instead I solved it by embedding the wall clock timestamps into the segments themselves.
ffmpeg -use_wallclock_as_timestamps 1 -i rtsp://#ip:port -c copy -copyts -vsync passthrough -f segment -segment_time 10 out%d.mp4
Then I can run ffprobe later on each segment to know their actual start time. (relative to system clock).

FFMPEG cannot encode video with high speed change

Hi I am trying to speed up and trim clips with FFMPEG version 4.2.2. Is there a limit to how fast you can speed up a clip? If I try to speed up a clip over a certain then the output file cannot be opened.
I have tried two methods without any luck: 1. using the setPTS filter and 2. inputing the file at a faster frame rate.
1.
ffmpeg -i GH012088.MP4 -y -ss 18 -t 0.48 -an -filter:v "setpts=0.096*PTS" -r 25 output.MP4
2.
ffmpeg -r 312.1875 -i GH012088.MP4 -y -ss 18 -t 0.48 -r 25 -an output.MP4
I am trying to create a clip from the input that starts at 1 second in the original clip, plays at 10.4166 x speed and lasts for 0.48 seconds
What am I doing wrong?
Thanks
Use
ffmpeg -ss 1 -i GH012088.MP4 -y -t 0.48 -an -filter:v "setpts=0.096*PTS" -r 25 output.MP4
The seek has to be on the input side, before frames are retimed. The -t has to be on output side, after frames are retimed.
Does the movie have sound?
If yes, than we have to sync speed up audio and video by combine filter:
ffmpeg -i video.avi -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" -f avi video1.avi

Splitting video with ffmpeg gives weird output

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

Ffmpeg show an image for multiple seconds before a video without re-encoding

I've been looking all around for this. Problem is that most google searches end up with being about creating a video from solely PNG files.
I've found this command which does the job :
ffmpeg -y -loop 1 -framerate 60 -t 5 -i firstimage.jpg -t 5 -f lavfi -i aevalsrc=0 -loop 1 -framerate 60 -t 5 -i secondimage.png -t 5 -f lavfi -i aevalsrc=0 -loop 1 -framerate 60 -t 5 -i thirdimage.png -t 5 -f lavfi -i aevalsrc=0 -i "shadowPlayVid.mp4" -filter_complex "[0:0][1:0][2:0][3:0][4:0][5:0][6:0][6:1] concat=n=4:v=1:a=1 [v] [a]" -map [v] -map [a] output.mp4 >> log_file1.txt 2>&1
But it seems to reencode the whole video, the input video is H.264 without CFR, but it seems to me that putting just some images before the video shouldn't take too long.
Because it ends up encoding the whole thing, this takes about 2 hours with a video of 30 minutes on a strong computer, while I feel like without encoding this should be able to be done much quicker. How do I make sure it doesn't re-encode while maintaining every image showing for 5 seconds first?
Generate your playervid.mp4 via
ffmpeg -y -loop 1 -framerate 60 -t 5 -i sample-out3.jpg -f lavfi -t 5 -i aevalsrc=0 -vf settb=1/60000 -video_track_timescale 60000 -c:v libx264 -pix_fmt yuv420p playervid.mp4

ffmpeg output video size limits to 4GB

I have a video file of .mp4 format. I want to convert it into .mpeg.
But when the output file size reaches 4GB, the conversion stops with a message something like "av_interleaved_write_frame() file too large"
My file system is ext4.
The commands I used are as below :
ffmpeg -i "input_file.mp4" -q:v 0 -q:a 0 -c:v mpeg2video "output_file.mpeg"
ffmpeg -i "input_file.mp4" -q:v 0 -q:a 0 -c:v mpeg2video -fs 8G "output_file.mpeg"
I understand that the conversion target defaults to DVD, so, the 4GB is the upper limit. can I tweak the target ?
Or, is it possible to dump the output to a subsequent file2Out.mpeg once file1Out.mpeg reaches 4GB
Yes, the reason is the filesystem format. FAT32 doesnt allow an mpeg file to exceed 4GB.
thank you
For instance, if your input lasts for 2 hours, you can convert the first hour to one file, and the second hour to another file by using -to option to stop at a certain position and -ss (placed before -i) option to start from a certain position:
ffmpeg -i "input_file.mp4" -to 1:00:00 -q:v 0 -q:a 0 -c:v mpeg2video "output_file_h1.mpeg" && \
ffmpeg -ss 1:00:00 -i "input_file.mp4" -q:v 0 -q:a 0 -c:v mpeg2video "output_file_h2.mpeg"

Resources