Trying to get frame timestamp with ffmpeg from a RTSP camera - ffmpeg

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).

Related

ffmpeg combined video increaes duration

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?

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

How do I get strftime working? Nothing has been working so far

Trying to add a timestamp for ffmpeg for capture card recoridngs but its not working at all.
ffmpeg -f dshow -rtbufsize 100M -i video="Game Capture HD60 S (Video) (#01)":audio="Game Capture HD60 S (Audio) (#01)" -c:v mpeg2video -q:v 0 -r 29.97 -c:a aac -b:a 192k -threads 12 -flags +ilme+ildct -top 1 -strftime 1 "file-%Y%m%d-%%04d.ts"
The output file is basically just "file-%Y%m%d-%%04d.ts", no dates or times. Any help?
strftime is not a generic option for all muxers; it is specific to a few.
However, you can work around this by using the segment muxer. The segment muxer is meant for when the output needs to be split across, umm.. segments. However, by setting a very large segment time, it effectively will write a single file.
So,
ffmpeg -f dshow -rtbufsize 100M -i video="Game Capture HD60 S (Video) (#01)":audio="Game Capture HD60 S (Audio) (#01)" -c:v mpeg2video -q:v 0 -r 30000/1001 -c:a aac -b:a 192k -threads 12 -flags +ilme+ildct -top 1 -f segment -segment_time 99999 -strftime 1 "file-%Y%m%d-%%04d.ts"
(Set r value to exact representation)

ffmpeg buffer queue drop overflow, dropping

I got
buffer queue drop overflow, dropping
error when I try to run this code
ffmpeg.exe -i input.mkv -i logo.png -loop 1 -report -filter_complex "overlay=20:15,subtitles ='sub.srt'" -c:a copy -q:v 1 -f segment -segment_time 600 "out_%d.ts"
but if I removed the overlay in complex filter it works find but Produce the video without logo
The following command is working but without the logo
ffmpeg.exe -i input.mkv -i logo.png -loop 1 -report -filter_complex "subtitles ='sub.srt'" -c:a copy -q:v 1 -f segment -segment_time 600 "out_%d.ts"

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