python - How to convert H264 RTP stream from PCAP to a playable video file -


i have captured stream of h264 in pcap files , trying create media files data. container not important (avi,mp4,mkv,…).
when i'm using videosnarf or rtpbreak (combined python code adds 00 00 00 01 before each packet) , ffmpeg, result ok if input frame rate constant (or near constant). however, when input vfr, result plays fast (and on same rare cases slow).
example:

videosnarf -i captured.pcap –c
ffmpeg -i h264-media-1.264 output.avi

after doing investigation of issue believe since videosnarf (and rtpbreak) removing rtp header packets, timestamp lost , ffmpeg referring input data cbr.

  1. i know if there way pass (on separate file?) timestamps vector or other information ffmpeg result created correctly?
  2. is there other way can take data out of pcap file , play or convert , play it?
  3. since work done in python, suggestion of libraries/modules can work (even if requires codding) welcome well.

note: work done offline, no limitations on output. can cbr/vbr, playable container , transcoding. "limitation" have: should run on linux…

thanks y

some additional information:
since nothing provides ffmpeg timestamp data, decided try different approach: skip videosnarf , use python code pipe packets directly ffmpeg (using "-f -i -" options) refuses accept unless provide sdp file...
how provide sdp file? additional input file? ("-i config.sdp")

the following code unsuccessful try doing above:

import time   import sys   import shutil   import subprocess   import os   import dpkt    if len(sys.argv) < 2:       print "argument required!"       print "txpcap <pcap file>"       sys.exit(2)   pcap_full_path = sys.argv[1]    ffmp_cmd = ['ffmpeg','-loglevel','debug','-y','-i','109c.sdp','-f','rtp','-i','-','-na','-vcodec','copy','p.mp4']    ffmpeg_proc = subprocess.popen(ffmp_cmd,stdout = subprocess.pipe,stdin = subprocess.pipe)    open(pcap_full_path, "rb") pcap_file:       pcapreader = dpkt.pcap.reader(pcap_file)       ts, data in pcapreader:           if len(data) < 49:               continue           ffmpeg_proc.stdin.write(data[42:])  sout, err = ffmpeg_proc.communicate()   print "stdout ---------------------------------------"   print sout   print "stderr ---------------------------------------"   print err   

in general pipe packets pcap file following command:

ffmpeg -loglevel debug -y -i 109c.sdp -f rtp -i - -na -vcodec copy p.mp4 

sdp file: [rtp includes dynamic payload type # 109, h264]

v=0
o=- 0 0 in ip4 ::1
s=no name
c=in ip4 ::1
t=0 0
a=tool:libavformat 53.32.100
m=video 0 rtp/avp 109
a=rtpmap:109 h264/90000
a=fmtp:109 packetization-mode=1;profile-level-id=64000c;sprop-parameter-sets=z2qadkwkpaecp6weqaaaawbaaaafi8ukkg==,amvmsiw=;
b=as:200

results:

ffmpeg version 0.10.2 copyright (c) 2000-2012 ffmpeg developers
built on mar 20 2012 04:34:50 gcc 4.4.6 20110731 (red hat 4.4.6-3) configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libdirac --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-o2 -g -pipe -wall -wp,-d_fortify_source=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fpic' --disable-stripping libavutil 51. 35.100 / 51. 35.100 libavcodec 53. 61.100 / 53. 61.100 libavformat 53. 32.100 / 53. 32.100 libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 61.100 / 2. 61.100 libswscale 2. 1.100 / 2. 1.100 libswresample 0. 6.100 / 0. 6.100
libpostproc 52. 0.100 / 52. 0.100 [sdp @ 0x15c0c00] format sdp probed size=2048 , score=50 [sdp @ 0x15c0c00] video codec set to: h264 [null @ 0x15c7240] rtp packetization mode: 1 [null @ 0x15c7240] rtp profile idc: 64 profile iop: 0 level: c [null @ 0x15c7240] extradata set 0x15c78e0 (size: 36)!err{or,}_recognition separate: 1; 1 [h264 @ 0x15c7240] err{or,}_recognition combined: 1; 10001 [sdp @ 0x15c0c00] decoding stream 0 failed [sdp @ 0x15c0c00] not find codec parameters (video: h264) [sdp @ 0x15c0c00] estimating duration bitrate, may inaccurate
109c.sdp: not find codec parameters traceback (most recent call last): file "./ffpipe.py", line 26, in
ffmpeg_proc.stdin.write(data[42:]) ioerror: [errno 32] broken pipe

(forgive mass above, editor keep on complaining code not indented ok ??)

i'm working on issue days... help/suggestion/hint appreciated.

i pretty sure way (sanely) replay rtp stream using networking time between packets delay.

the problem variable frame rate, since there no container around h264 tell x amount of time passed between frame , last 1 has no idea how time everything.

if h264 stream constant frame rate might able push rtp data ffmpeg out timings setting inputs fps, dont know of h264 rtp streams work that. see video stream play way fast @ parts , slow @ others.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -