[FFmpeg-user] Trying to Motion JPEG to segmented video, but "Non-increasing DTS in stream 0" forever
Renato Santos
renato.cron at gmail.com
Sun Mar 2 00:54:29 CET 2014
Hello,
I have to connect to several mjpeg ip-camera (mostly cheap copy of FI8908W),
and segment it in files. Sometimes I'll have MJPEG and sometimes only
snapshots JPEG.
I have the code for downloading MJPEG and then I print each JPEG to STDOUT.
Here's the perl code to download it:
use strict;
use LWP::UserAgent;
LWP::UserAgent->new->get("http://141.89.114.58/cgi-bin/video320x240.mjpg",
':content_cb' => \&got_data);
my $buffer = '';
my $boundary;
my $x = 0;
sub got_data {
my ($str, $ref) = @_;
$boundary = do {
my $z = $ref->headers->{'content-type'} =~ /boundary=(.+)\;?/;
$1} if !defined $boundary;
$buffer .= $str;
next unless $boundary;
#print $buffer;
while( 1+(my $end = index($buffer, $boundary))) {
my $ret = substr $buffer, 0, $end, '';
handle_part($ret) if $ret ne '--';
substr $buffer, 0, length($boundary), '';
}
}
my $idx = 0;
sub handle_part {
my $data = shift;
return unless length $data;
# clear some headers
$data =~ s/^.+Content-Length\: \d+//s;
$data =~ s/^.+Content-type\: image\/jpeg//s;
$data =~ s/^(\r|\n)+//;
$idx++;
print $data;
}
Then, I run:
perl download_mjpg.pl | /home/renato/ffmpeg/ffmpeg-HEAD-e2742d6/ffmpeg -
*use_wallclock_as_timestamps* 1 -loglevel debug -f *image2pipe* -i - -map
0 -an -codec:v libx264 -profile:v main -preset fast -r 4
-force_key_frames 'expr:gte(t,n_forced*10)' -f segment -segment_time
20 -segment_list /tmp/segment.csv -reset_timestamps 1 -segment_time_delta
0.05 /tmp/hmm%09d.mp4
ffmpeg *version 2.1.git-e2742d6* Copyright (c) 2000-2013 the FFmpeg
developers
built on Dec 16 2013 13:41:29 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libx264 --prefix='~/ffmpeg/'
libavutil 52. 58.100 / 52. 58.100
libavcodec 55. 45.101 / 55. 45.101
libavformat 55. 22.100 / 55. 22.100
libavdevice 55. 5.102 / 55. 5.102
libavfilter 3. 92.100 / 3. 92.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Splitting the commandline.
Reading option '-use_wallclock_as_timestamps' ... matched as AVOption
'use_wallclock_as_timestamps' with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging
level) with argument 'debug'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'image2pipe'.
Reading option '-i' ... matched as input file with argument '-'.
Reading option '-map' ... matched as option 'map' (set input stream
mapping) with argument '0'.
Reading option '-an' ... matched as option 'an' (disable audio) with
argument '1'.
Reading option '-codec:v' ... matched as option 'codec' (codec name) with
argument 'libx264'.
Reading option '-profile:v' ... matched as option 'profile' (set profile)
with argument 'main'.
Reading option '-preset' ... matched as AVOption 'preset' with argument
'fast'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value,
fraction or abbreviation)) with argument '4'.
Reading option '-force_key_frames' ... matched as option 'force_key_frames'
(force key frames at specified timestamps) with argument
'expr:gte(t,n_forced*10)'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'segment'.
Reading option '-segment_time' ... matched as AVOption 'segment_time' with
argument '20'.
Reading option '-segment_list' ... matched as AVOption 'segment_list' with
argument '/tmp/segment.csv'.
Reading option '-reset_timestamps' ... matched as AVOption
'reset_timestamps' with argument '1'.
Reading option '-segment_time_delta' ... matched as AVOption
'segment_time_delta' with argument '0.05'.
Reading option '/tmp/hmm%09d.mp4' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file -.
Applying option f (force format) with argument image2pipe.
Successfully parsed a group of options.
Opening an input file: -.
[image2pipe @ 0xa628fe0] Before avformat_find_stream_info() pos: 0 bytes
read:8192 seeks:0
[image2pipe @ 0xa628fe0] parser not found for codec none, packets or times
may be invalid.
Last message repeated 1 times
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 2 with DTS
34842940956, packet 3 with DTS 34842940956
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 4 with DTS
34842941004, packet 5 with DTS 34842941004
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 6 with DTS
34842941066, packet 7 with DTS 34842941066
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 8 with DTS
34842941133, packet 9 with DTS 34842941133
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 10 with DTS
34842941199, packet 11 with DTS 34842941199
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 12 with DTS
34842941244, packet 13 with DTS 34842941244
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 14 with DTS
34842941292, packet 15 with DTS 34842941292
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 16 with DTS
34842941335, packet 17 with DTS 34842941335
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 17 with DTS
34842941335, packet 18 with DTS 34842941335
... lot of it, then I give up with CTRL+C:
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 108 with
DTS 34842943589, packet 109 with DTS 34842943589
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 110 with
DTS 34842943634, packet 111 with DTS 34842943634
[image2pipe @ 0xa628fe0] Non-increasing DTS in stream 0: packet 112 with
DTS 34842943700, packet 113 with DTS 34842943700
^C[image2pipe @ 0xa628fe0] Could not find codec parameters for stream 0
(Video: none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize'
options
[image2pipe @ 0xa628fe0] After avformat_find_stream_info() pos: 466944
bytes read:466944 seeks:0 frames:114
pipe:: could not find codec parameters
[AVIOContext @ 0xa629500] Statistics: 466944 bytes read, 0 seeks
Received signal 2: terminating.
Surely i'm doing something wrong! I googled and tried also:
perl download_mjpg.pl | /home/renato/ffmpeg/ffmpeg-HEAD-e2742d6/ffmpeg
-loglevel debug -r 5 -f mjpeg -an -i - -vcodec libx264 -threads 0 -f
rtsp rtsp://127.0.0.1:1935/rtplive/myStream.sdp
but it give up after *max_analyze_duration 5000000 reached at 5000000
microseconds*, and I cant connect to this stream.
perl download_mjpg.pl | /home/renato/ffmpeg/ffmpeg-HEAD-e2742d6/ffmpeg
-loglevel debug -r 5 -f mjpeg -an -i - -vcodec libx264 -threads 0 -f
rtsp rtsp://127.0.0.1:1935/rtplive/myStream.sdp
ffmpeg version 2.1.git-e2742d6 Copyright (c) 2000-2013 the FFmpeg developers
built on Dec 16 2013 13:41:29 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --enable-gpl --enable-libx264 --prefix='~/ffmpeg/'
libavutil 52. 58.100 / 52. 58.100
libavcodec 55. 45.101 / 55. 45.101
libavformat 55. 22.100 / 55. 22.100
libavdevice 55. 5.102 / 55. 5.102
libavfilter 3. 92.100 / 3. 92.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging
level) with argument 'debug'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value,
fraction or abbreviation)) with argument '5'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'mjpeg'.
Reading option '-an' ... matched as option 'an' (disable audio) with
argument '1'.
Reading option '-i' ... matched as input file with argument '-'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec
('copy' to copy stream)) with argument 'libx264'.
Reading option '-threads' ... matched as AVOption 'threads' with argument
'0'.
Reading option '-f' ... matched as option 'f' (force format) with argument
'rtsp'.
Reading option 'rtsp://127.0.0.1:1935/rtplive/myStream.sdp' ... matched as
output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file -.
Applying option r (set frame rate (Hz value, fraction or abbreviation))
with argument 5.
Applying option f (force format) with argument mjpeg.
Applying option an (disable audio) with argument 1.
Successfully parsed a group of options.
Opening an input file: -.
[mjpeg @ 0xabc1e40] Before avformat_find_stream_info() pos: 0 bytes
read:8192 seeks:0
[mjpeg @ 0xabca7e0] marker=d8 avail_size_in_buf=9097
[mjpeg @ 0xabca7e0] marker parser used 0 bytes (0 bits)
[mjpeg @ 0xabca7e0] marker=fe avail_size_in_buf=9095
[mjpeg @ 0xabca7e0] marker parser used 40 bytes (320 bits)
[mjpeg @ 0xabca7e0] marker=db avail_size_in_buf=9053
[mjpeg @ 0xabca7e0] index=0
[mjpeg @ 0xabca7e0] qscale[0]: 7
[mjpeg @ 0xabca7e0] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xabca7e0] marker=db avail_size_in_buf=8984
[mjpeg @ 0xabca7e0] index=1
[mjpeg @ 0xabca7e0] qscale[1]: 14
[mjpeg @ 0xabca7e0] marker parser used 67 bytes (536 bits)
[mjpeg @ 0xabca7e0] marker=c0 avail_size_in_buf=8915
[mjpeg @ 0xabca7e0] sof0: picture: 320x240
[mjpeg @ 0xabca7e0] component 0 2:1 id: 0 quant:0
[mjpeg @ 0xabca7e0] component 1 1:1 id: 1 quant:1
[mjpeg @ 0xabca7e0] component 2 1:1 id: 2 quant:1
[mjpeg @ 0xabca7e0] pix fmt id 21111100
[mjpeg @ 0xabca7e0] marker parser used 17 bytes (136 bits)
[mjpeg @ 0xabca7e0] marker=c4 avail_size_in_buf=8896
[mjpeg @ 0xabca7e0] class=0 index=0 nb_codes=12
[mjpeg @ 0xabca7e0] marker parser used 31 bytes (248 bits)
[mjpeg @ 0xabca7e0] marker=c4 avail_size_in_buf=8863
[mjpeg @ 0xabca7e0] class=1 index=0 nb_codes=251
[mjpeg @ 0xabca7e0] marker parser used 181 bytes (1448 bits)
[mjpeg @ 0xabca7e0] marker=c4 avail_size_in_buf=8680
[mjpeg @ 0xabca7e0] class=0 index=1 nb_codes=12
[mjpeg @ 0xabca7e0] marker parser used 31 bytes (248 bits)
[mjpeg @ 0xabca7e0] marker=c4 avail_size_in_buf=8647
[mjpeg @ 0xabca7e0] class=1 index=1 nb_codes=251
[mjpeg @ 0xabca7e0] marker parser used 181 bytes (1448 bits)
[mjpeg @ 0xabca7e0] escaping removed 14 bytes
[mjpeg @ 0xabca7e0] marker=da avail_size_in_buf=8464
[mjpeg @ 0xabca7e0] component: 0
[mjpeg @ 0xabca7e0] component: 1
[mjpeg @ 0xabca7e0] component: 2
[mjpeg @ 0xabca7e0] marker parser used 8449 bytes (67591 bits)
[mjpeg @ 0xabca7e0] marker=d9 avail_size_in_buf=2
[mjpeg @ 0xabca7e0] decode frame unused 2 bytes
*[mjpeg @ 0xabc1e40] max_analyze_duration 5000000 reached at 5000000
microseconds *
*[mjpeg @ 0xabc1e40] After avformat_find_stream_info() pos: 256000 bytes
read:262144 seeks:0 frames:27*
Input #0, mjpeg, from 'pipe:':
Duration: N/A, bitrate: N/A
Stream #0:0, 27, 1/1200000: Video: mjpeg, yuvj422p(pc), 320x240, 1/5, 5
fps, 5 tbr, 1200k tbn, 5 tbc
Successfully opened the file.
Parsing a group of options: output file rtsp://
127.0.0.1:1935/rtplive/myStream.sdp.
Applying option vcodec (force video codec ('copy' to copy stream)) with
argument libx264.
Applying option f (force format) with argument rtsp.
Successfully parsed a group of options.
Opening an output file: rtsp://127.0.0.1:1935/rtplive/myStream.sdp.
Successfully opened the file.
detected 8 logical cores
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'video_size' to value
'320x240'
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'pix_fmt' to value '13'
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'time_base' to value
'1/5'
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'pixel_aspect' to value
'0/1'
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'sws_param' to value
'flags=2'
[graph 0 input from stream 0:0 @ 0xabc23c0] Setting 'frame_rate' to value
'5/1'
[graph 0 input from stream 0:0 @ 0xabc23c0] w:320 h:240 pixfmt:yuvj422p
tb:1/5 fr:5/1 sar:0/1 sws_param:flags=2
[force CFR for input from stream 0:0 @ 0xabd2ee0] Setting 'expr' to value
'N'
[format @ 0xabcef40] compat: called with
args=[yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16]
[format @ 0xabcef40] Setting 'pix_fmts' to value
'yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16'
[AVFilterGraph @ 0xabcfbc0] query_formats: 5 queried, 4 merged, 0 already
done, 0 delayed
[graph 0 input from stream 0:0 @ 0xabc23c0] TB:0.200000 FRAME_RATE:5.000000
SAMPLE_RATE:nan
No pixel format specified, yuvj422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0xabd2700] using mv_range_thread = 24
[libx264 @ 0xabd2700] using cpu capabilities: MMX2 SSE2Fast SSSE3
FastShuffle SSE4.2 AVX
[libx264 @ 0xabd2700] profile High 4:2:2, level 1.2, 4:2:2 8-bit
[libx264 @ 0xabd2700] 264 - core 123 r2189 35cf912 - H.264/MPEG-4 AVC codec
- Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1
ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00
mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11
fast_pskip=1 chroma_qp_offset=-2 threads=12 sliced_threads=0 nr=0
decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3
b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2
keyint=250 keyint_min=5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf
mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
aq=1:1.00
[tcp @ 0xb37a420] Connection to tcp://127.0.0.1:1935?timeout=0 failed:
Connection refused
Output #0, rtsp, to 'rtsp://127.0.0.1:1935/rtplive/myStream.sdp':
Metadata:
encoder : Lavf55.22.100
Stream #0:0, 0, 1/90000: Video: h264 (libx264), yuvj422p, 320x240, 1/5,
q=-1--1, 90k tbn, 5 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> libx264)
Could not write header for output file #0 (incorrect codec parameters ?):
Input/output error
[AVIOContext @ 0xabca560] Statistics: 262144 bytes read, 0 seeks
Anybody can help me about ideas how to get these videos working?
Thank you for your time!
--
Renato CRON
http://www.renatocron.com/blog/
@renato_cron <http://twitter.com/#!/renato_cron>
More information about the ffmpeg-user
mailing list