diff --git a/tests.txt b/tests.txt new file mode 100644 index 0000000000000000000000000000000000000000..01301f5a81517d90897d2883f15570f31fd0dd44 --- /dev/null +++ b/tests.txt @@ -0,0 +1,63 @@ +gst-launch-1.0 -e \ + dshowvideosrc do-timestamp=true ! \ + queue ! \ + videoconvert ! \ + video/x-raw,format=I420,framerate=30/1 ! \ + queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! \ + x264enc tune=zerolatency bitrate=2000 ! \ + h264parse ! \ + queue ! mux. \ + dshowaudiosrc device="\\\\\?\\SWD\#MMDEVAPI\#\{0.0.1.00000000\}.\{0b06267f-ddd6-456a-8206-b28ac51692d4\}\#\{2eef81be-33fa-4800-9670-1cd474972c3f\}" ! \ + queue ! \ + audioconvert ! \ + audioresample ! \ + lamemp3enc ! \ + mpegaudioparse ! \ + queue ! mux. \ + mp4mux name=mux ! \ + filesink location=output.mp4 + +&& gst-launch-1.0 -e mp4mux ! filesink location=output.mp4 + +audio device: +\{0.0.1.00000000\}.\{0b06267f-ddd6-456a-8206-b28ac51692d4\} +\{0B06267F-DDD6-456A-8206-B28AC51692D4\} +\{2EEF81BE-33FA-4800-9670-1CD474972C3F\} +\\\\\?\\SWD\#MMDEVAPI\#\{0.0.1.00000000\}.\{0b06267f-ddd6-456a-8206-b28ac51692d4\}\#\{2eef81be-33fa-4800-9670-1cd474972c3f\} + +gst-launch-1.0 -e dshowaudiosrc device="\{0B06267F-DDD6-456A-8206-B28AC51692D4\}" ! \ + audioconvert ! \ + audioresample ! \ + audio/x-raw,rate=44100,channels=2 ! \ + wavenc ! \ + filesink location=audio-only.wav + +gst-device-monitor-1.0.exe + +gst-launch-1.0 -e dshowaudiosrc device="\{2EEF81BE-33FA-4800-9670-1CD474972C3F\}" ! audioconvert ! autoaudiosink + +mostrar video: +gst-launch-1.0 -e dshowvideosrc ! \ + videoconvert ! video/x-raw,format=I420,framerate=30/1 ! \ + autovideosink + + + Workinggggggggggggggggggggggggggggg + +gst-launch-1.0 -e \ + mfvideosrc ! "video/x-raw, width=1920, height=1080" ! videorate ! "video/x-raw, framerate=30/1" ! videoconvert ! x264enc ! queue ! mux. \ + wasapisrc do-timestamp=true ! audioconvert ! voaacenc ! "audio/mpeg, mpegversion=4, stream-format=raw" ! queue max-size-time=2000000000 max-size-bytes=0 max-size-buffers=0 ! mux. \ + mp4mux name=mux ! filesink location=output.mp4 + + + + gst-launch-1.0 -e ksvideosrc ! videoconvert ! x264enc ! mp4mux ! filesink location=output.mp4 + + $ gst-launch-1.0 -e \ + mfvideosrc ! videoconvert ! x264enc ! queue max-size-time=5000000000 ! mux. \ + wasapisrc ! audioconvert ! voaacenc ! queue max-size-time=5000000000 ! mux. \ + mp4mux name=mux ! filesink location=output.mp4 + +or audiotestsrc instead of wasapisrc + +C:\Users\Miguel\AppData\Local\Programs\Git\mingw64\lib\pkgconfig \ No newline at end of file diff --git a/tests/test-video-psychopy.psyexp b/tests/test-video-psychopy.psyexp new file mode 100644 index 0000000000000000000000000000000000000000..a60ba1fcce79fe2dc3678365ce2827f748dc84ec --- /dev/null +++ b/tests/test-video-psychopy.psyexp @@ -0,0 +1,205 @@ +<?xml version="1.0" ?> +<PsychoPy2experiment encoding="utf-8" version="2024.2.4"> + <Settings> + <Param val="3" valType="str" updates="None" name="Audio latency priority"/> + <Param val="ptb" valType="str" updates="None" name="Audio lib"/> + <Param val="" valType="str" updates="None" name="Completed URL"/> + <Param val="auto" valType="str" updates="None" name="Data file delimiter"/> + <Param val="u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])" valType="code" updates="None" name="Data filename"/> + <Param val="True" valType="bool" updates="None" name="Enable Escape"/> + <Param val="Thank you for your patience." valType="str" updates="None" name="End Message"/> + <Param val="{'participant':'f"{randint(0, 999999):06.0f}"', 'session':'001'}" valType="code" updates="None" name="Experiment info"/> + <Param val="True" valType="bool" updates="None" name="Force stereo"/> + <Param val="True" valType="bool" updates="None" name="Full-screen window"/> + <Param val="" valType="str" updates="None" name="HTML path"/> + <Param val="" valType="str" updates="None" name="Incomplete URL"/> + <Param val="testMonitor" valType="str" updates="None" name="Monitor"/> + <Param val="[]" valType="list" updates="None" name="Resources"/> + <Param val="False" valType="bool" updates="None" name="Save csv file"/> + <Param val="False" valType="bool" updates="None" name="Save excel file"/> + <Param val="False" valType="bool" updates="None" name="Save hdf5 file"/> + <Param val="True" valType="bool" updates="None" name="Save log file"/> + <Param val="True" valType="bool" updates="None" name="Save psydat file"/> + <Param val="True" valType="bool" updates="None" name="Save wide csv file"/> + <Param val="1" valType="num" updates="None" name="Screen"/> + <Param val="True" valType="bool" updates="None" name="Show info dlg"/> + <Param val="False" valType="bool" updates="None" name="Show mouse"/> + <Param val="height" valType="str" updates="None" name="Units"/> + <Param val="" valType="str" updates="None" name="Use version"/> + <Param val="(1024, 768)" valType="list" updates="None" name="Window size (pixels)"/> + <Param val="none" valType="str" updates="None" name="backgroundFit"/> + <Param val="" valType="str" updates="None" name="backgroundImg"/> + <Param val="avg" valType="str" updates="None" name="blendMode"/> + <Param val="float" valType="str" updates="None" name="clockFormat"/> + <Param val="{'thisRow.t': 'priority.CRITICAL', 'expName': 'priority.LOW'}" valType="dict" updates="None" name="colPriority"/> + <Param val="$[0,0,0]" valType="color" updates="None" name="color"/> + <Param val="rgb" valType="str" updates="None" name="colorSpace"/> + <Param val="warning" valType="code" updates="None" name="consoleLoggingLevel"/> + <Param val="default" valType="str" updates="None" name="ecSampleRate"/> + <Param val="100.1.1.1" valType="str" updates="None" name="elAddress"/> + <Param val="FILTER_LEVEL_2" valType="str" updates="None" name="elDataFiltering"/> + <Param val="FILTER_LEVEL_OFF" valType="str" updates="None" name="elLiveFiltering"/> + <Param val="EYELINK 1000 DESKTOP" valType="str" updates="None" name="elModel"/> + <Param val="ELLIPSE_FIT" valType="str" updates="None" name="elPupilAlgorithm"/> + <Param val="PUPIL_AREA" valType="str" updates="None" name="elPupilMeasure"/> + <Param val="1000" valType="num" updates="None" name="elSampleRate"/> + <Param val="False" valType="bool" updates="None" name="elSimMode"/> + <Param val="RIGHT_EYE" valType="str" updates="None" name="elTrackEyes"/> + <Param val="PUPIL_CR_TRACKING" valType="str" updates="None" name="elTrackingMode"/> + <Param val="untitled" valType="str" updates="None" name="expName"/> + <Param val="on Sync" valType="str" updates="None" name="exportHTML"/> + <Param val="None" valType="str" updates="None" name="eyetracker"/> + <Param val="" valType="code" updates="None" name="frameRate"/> + <Param val="Attempting to measure frame rate of screen, please wait..." valType="str" updates="None" name="frameRateMsg"/> + <Param val="127.0.0.1" valType="str" updates="None" name="gpAddress"/> + <Param val="4242" valType="num" updates="None" name="gpPort"/> + <Param val="ioHub" valType="str" updates="None" name="keyboardBackend"/> + <Param val="info" valType="code" updates="None" name="logging level"/> + <Param val="True" valType="bool" updates="None" name="measureFrameRate"/> + <Param val="MIDDLE_BUTTON" valType="list" updates="None" name="mgBlink"/> + <Param val="CONTINUOUS" valType="str" updates="None" name="mgMove"/> + <Param val="0.5" valType="num" updates="None" name="mgSaccade"/> + <Param val="neon.local" valType="str" updates="None" name="plCompanionAddress"/> + <Param val="8080" valType="num" updates="None" name="plCompanionPort"/> + <Param val="True" valType="bool" updates="None" name="plCompanionRecordingEnabled"/> + <Param val="0.6" valType="num" updates="None" name="plConfidenceThreshold"/> + <Param val="True" valType="bool" updates="None" name="plPupilCaptureRecordingEnabled"/> + <Param val="" valType="str" updates="None" name="plPupilCaptureRecordingLocation"/> + <Param val="127.0.0.1" valType="str" updates="None" name="plPupilRemoteAddress"/> + <Param val="50020" valType="num" updates="None" name="plPupilRemotePort"/> + <Param val="1000" valType="num" updates="None" name="plPupilRemoteTimeoutMs"/> + <Param val="False" valType="bool" updates="None" name="plPupillometryOnly"/> + <Param val="psychopy_iohub_surface" valType="str" updates="None" name="plSurfaceName"/> + <Param val="0" valType="code" updates="None" name="runMode"/> + <Param val="False" valType="bool" updates="None" name="rush"/> + <Param val="time" valType="str" updates="None" name="sortColumns"/> + <Param val="" valType="str" updates="None" name="tbLicenseFile"/> + <Param val="" valType="str" updates="None" name="tbModel"/> + <Param val="60" valType="num" updates="None" name="tbSampleRate"/> + <Param val="" valType="str" updates="None" name="tbSerialNo"/> + <Param val="pyglet" valType="str" updates="None" name="winBackend"/> + </Settings> + <Routines> + <Routine name="Test"> + <RoutineSettingsComponent name="Test" plugin="None"> + <Param val="none" valType="str" updates="None" name="backgroundFit"/> + <Param val="" valType="str" updates="None" name="backgroundImg"/> + <Param val="$[0,0,0]" valType="color" updates="None" name="color"/> + <Param val="rgb" valType="str" updates="None" name="colorSpace"/> + <Param val="" valType="str" updates="constant" name="desc"/> + <Param val="False" valType="bool" updates="None" name="disabled"/> + <Param val="" valType="code" updates="None" name="durationEstim"/> + <Param val="False" valType="code" updates="None" name="forceNonSlip"/> + <Param val="Test" valType="code" updates="None" name="name"/> + <Param val="True" valType="bool" updates="None" name="saveStartStop"/> + <Param val="" valType="code" updates="constant" name="skipIf"/> + <Param val="duration (s)" valType="str" updates="None" name="stopType"/> + <Param val="" valType="code" updates="constant" name="stopVal"/> + <Param val="False" valType="bool" updates="None" name="useWindowParams"/> + </RoutineSettingsComponent> + <TextComponent name="text_2" plugin="None"> + <Param val="white" valType="color" updates="constant" name="color"/> + <Param val="rgb" valType="str" updates="constant" name="colorSpace"/> + <Param val="1" valType="num" updates="constant" name="contrast"/> + <Param val="False" valType="bool" updates="None" name="disabled"/> + <Param val="False" valType="code" updates="constant" name="draggable"/> + <Param val="" valType="code" updates="None" name="durationEstim"/> + <Param val="None" valType="str" updates="constant" name="flip"/> + <Param val="Arial" valType="str" updates="constant" name="font"/> + <Param val="LTR" valType="str" updates="None" name="languageStyle"/> + <Param val="0.05" valType="num" updates="constant" name="letterHeight"/> + <Param val="text_2" valType="code" updates="None" name="name"/> + <Param val="" valType="num" updates="constant" name="opacity"/> + <Param val="0" valType="num" updates="constant" name="ori"/> + <Param val="(0, 0)" valType="list" updates="constant" name="pos"/> + <Param val="True" valType="bool" updates="None" name="saveStartStop"/> + <Param val="" valType="code" updates="None" name="startEstim"/> + <Param val="time (s)" valType="str" updates="None" name="startType"/> + <Param val="0.0" valType="code" updates="None" name="startVal"/> + <Param val="duration (s)" valType="str" updates="None" name="stopType"/> + <Param val="5" valType="code" updates="constant" name="stopVal"/> + <Param val="True" valType="bool" updates="None" name="syncScreenRefresh"/> + <Param val="TEST" valType="str" updates="constant" name="text"/> + <Param val="from exp settings" valType="str" updates="None" name="units"/> + <Param val="" valType="code" updates="None" name="validator"/> + <Param val="" valType="num" updates="constant" name="wrapWidth"/> + </TextComponent> + <CameraComponent name="cam" plugin="None"> + <Param val="opencv" valType="str" updates="None" name="cameraLib"/> + <Param val="default" valType="str" updates="None" name="device"/> + <Param val="lala" valType="str" updates="None" name="deviceLabel"/> + <Param val="'USB Video'" valType="code" updates="None" name="deviceManual"/> + <Param val="False" valType="bool" updates="None" name="disabled"/> + <Param val="" valType="code" updates="None" name="durationEstim"/> + <Param val="30" valType="int" updates="None" name="frameRate"/> + <Param val="30" valType="int" updates="None" name="frameRateManual"/> + <Param val="5" valType="str" updates="None" name="mic"/> + <Param val="auto" valType="str" updates="None" name="micChannels"/> + <Param val="lalaa" valType="str" updates="None" name="micDeviceLabel"/> + <Param val="24000" valType="num" updates="None" name="micMaxRecSize"/> + <Param val="CD Audio (44.1kHz)" valType="num" updates="None" name="micSampleRate"/> + <Param val="cam" valType="code" updates="None" name="name"/> + <Param val="" valType="list" updates="None" name="resolution"/> + <Param val="[1980,1080]" valType="list" updates="None" name="resolutionManual"/> + <Param val="True" valType="bool" updates="None" name="saveFile"/> + <Param val="True" valType="bool" updates="None" name="saveStartStop"/> + <Param val="" valType="code" updates="None" name="startEstim"/> + <Param val="time (s)" valType="str" updates="None" name="startType"/> + <Param val="0" valType="code" updates="None" name="startVal"/> + <Param val="duration (s)" valType="str" updates="None" name="stopType"/> + <Param val="5" valType="code" updates="constant" name="stopVal"/> + <Param val="False" valType="bool" updates="None" name="syncScreenRefresh"/> + </CameraComponent> + </Routine> + <Routine name="Fam"> + <RoutineSettingsComponent name="Fam" plugin="None"> + <Param val="none" valType="str" updates="None" name="backgroundFit"/> + <Param val="" valType="str" updates="None" name="backgroundImg"/> + <Param val="$[0,0,0]" valType="color" updates="None" name="color"/> + <Param val="rgb" valType="str" updates="None" name="colorSpace"/> + <Param val="" valType="str" updates="constant" name="desc"/> + <Param val="False" valType="bool" updates="None" name="disabled"/> + <Param val="" valType="code" updates="None" name="durationEstim"/> + <Param val="False" valType="code" updates="None" name="forceNonSlip"/> + <Param val="Fam" valType="code" updates="None" name="name"/> + <Param val="True" valType="bool" updates="None" name="saveStartStop"/> + <Param val="" valType="code" updates="constant" name="skipIf"/> + <Param val="duration (s)" valType="str" updates="None" name="stopType"/> + <Param val="" valType="code" updates="constant" name="stopVal"/> + <Param val="False" valType="bool" updates="None" name="useWindowParams"/> + </RoutineSettingsComponent> + <TextComponent name="text" plugin="None"> + <Param val="white" valType="color" updates="constant" name="color"/> + <Param val="rgb" valType="str" updates="constant" name="colorSpace"/> + <Param val="1" valType="num" updates="constant" name="contrast"/> + <Param val="False" valType="bool" updates="None" name="disabled"/> + <Param val="False" valType="code" updates="constant" name="draggable"/> + <Param val="" valType="code" updates="None" name="durationEstim"/> + <Param val="None" valType="str" updates="constant" name="flip"/> + <Param val="Arial" valType="str" updates="constant" name="font"/> + <Param val="LTR" valType="str" updates="None" name="languageStyle"/> + <Param val="0.05" valType="num" updates="constant" name="letterHeight"/> + <Param val="text" valType="code" updates="None" name="name"/> + <Param val="" valType="num" updates="constant" name="opacity"/> + <Param val="0" valType="num" updates="constant" name="ori"/> + <Param val="(0, 0)" valType="list" updates="constant" name="pos"/> + <Param val="True" valType="bool" updates="None" name="saveStartStop"/> + <Param val="" valType="code" updates="None" name="startEstim"/> + <Param val="time (s)" valType="str" updates="None" name="startType"/> + <Param val="0.0" valType="code" updates="None" name="startVal"/> + <Param val="duration (s)" valType="str" updates="None" name="stopType"/> + <Param val="2" valType="code" updates="constant" name="stopVal"/> + <Param val="True" valType="bool" updates="None" name="syncScreenRefresh"/> + <Param val="FAMILIARIZATION" valType="str" updates="constant" name="text"/> + <Param val="from exp settings" valType="str" updates="None" name="units"/> + <Param val="" valType="code" updates="None" name="validator"/> + <Param val="" valType="num" updates="constant" name="wrapWidth"/> + </TextComponent> + </Routine> + </Routines> + <Flow> + <Routine name="Fam"/> + <Routine name="Test"/> + <Routine name="Fam"/> + </Flow> +</PsychoPy2experiment> diff --git a/video-capture-gsm/basic-capture.py b/video-capture-gsm/basic-capture.py new file mode 100644 index 0000000000000000000000000000000000000000..0a378cd4690db4065759927d9f757fe6aa9f1978 --- /dev/null +++ b/video-capture-gsm/basic-capture.py @@ -0,0 +1,56 @@ +import os +import sys + +# Set GStreamer environment variables to use MSVC build +os.environ['GST_PLUGIN_PATH'] = "D:/gstreamer/1.0/msvc_x86_64/lib/gstreamer-1.0" +os.environ['PATH'] = "D:/gstreamer/1.0/msvc_x86_64/bin;" + os.environ['PATH'] +os.environ['GST_PLUGIN_SYSTEM_PATH'] = "D:/gstreamer/1.0/msvc_x86_64/lib/gstreamer-1.0" + +import gi +import time + +# Tell GObject which versions of libraries we want to use +gi.require_version('Gst', '1.0') +from gi.repository import Gst, GLib + +# Initialize GStreamer +Gst.init(None) +# Create a main loop +main_loop = GLib.MainLoop() + +# Create pipeline element +pipeline = Gst.parse_launch( + "mfvideosrc ! video/x-raw, width=1920, height=1080 ! videorate ! video/x-raw, framerate=30/1 ! videoconvert ! x264enc ! queue ! mux. " + "wasapisrc do-timestamp=true ! audioconvert ! voaacenc ! audio/mpeg, mpegversion=4, stream-format=raw ! queue max-size-time=2000000000 max-size-bytes=0 max-size-buffers=0 ! mux. " + "mp4mux name=mux ! filesink location=output.mp4" +) + +# Define a callback function for handling messages from the bus +def bus_call(bus, message, loop): + t = message.type + if t == Gst.MessageType.EOS: + print("End of stream") + loop.quit() + elif t == Gst.MessageType.ERROR: + err, debug = message.parse_error() + print(f"Error: {err}, {debug}") + loop.quit() + return True + +# Get the bus +bus = pipeline.get_bus() +bus.add_signal_watch() +bus.connect("message", bus_call, main_loop) + +# Start the pipeline +pipeline.set_state(Gst.State.PLAYING) +print("Pipeline is playing...") + +try: + # Run the main loop + main_loop.run() +except KeyboardInterrupt: + print("Stopping pipeline...") + # Clean up + pipeline.set_state(Gst.State.NULL) + main_loop.quit() \ No newline at end of file diff --git a/video-capture-gsm/check_gstreamer.py b/video-capture-gsm/check_gstreamer.py new file mode 100644 index 0000000000000000000000000000000000000000..ff41891b877ff62ca4f82f6794449efd54fad885 --- /dev/null +++ b/video-capture-gsm/check_gstreamer.py @@ -0,0 +1,40 @@ +import os +import sys + +# Set GStreamer environment variables to use MSVC build +os.environ['GST_PLUGIN_PATH'] = 'D:/gstreamer/1.0/msvc_x86_64/lib/gstreamer-1.0' +os.environ['PATH'] = 'D:/gstreamer/1.0/msvc_x86_64/bin;' + os.environ['PATH'] +os.environ['GST_PLUGIN_SYSTEM_PATH'] = 'D:/gstreamer/1.0/msvc_x86_64/lib/gstreamer-1.0' + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst + +# Initialize GStreamer +Gst.init(None) + +print("GStreamer version:", Gst.version_string()) +print("Python version:", sys.version) +print("GST_PLUGIN_PATH:", os.environ.get('GST_PLUGIN_PATH', 'Not set')) +print("PATH:", os.environ.get('PATH', 'Not set')) + +# Try to create mfvideosrc element +element = Gst.ElementFactory.make("mfvideosrc", "source") +if element: + print("Successfully created mfvideosrc element!") +else: + print("Failed to create mfvideosrc element") + +# List all available plugin factories +print("\nAvailable GStreamer plugins:") +registry = Gst.Registry.get() +factories = registry.get_feature_list(Gst.ElementFactory.__gtype__) +factory_names = sorted([factory.get_name() for factory in factories]) +for name in factory_names: + print(f"- {name}") + +# Check for specific plugins related to video sources +video_sources = [name for name in factory_names if "src" in name and ("video" in name or "camera" in name)] +print("\nAvailable video sources:") +for source in video_sources: + print(f"- {source}") \ No newline at end of file diff --git a/video-capture-gsm/frame_timestamps.csv b/video-capture-gsm/frame_timestamps.csv new file mode 100644 index 0000000000000000000000000000000000000000..db777b7b739b2d90a9cf3ff66bb3bfde8be65442 --- /dev/null +++ b/video-capture-gsm/frame_timestamps.csv @@ -0,0 +1 @@ +Frame Number,System Time,Estimated Pipeline Time diff --git a/video-capture-gsm/simple_test.py b/video-capture-gsm/simple_test.py new file mode 100644 index 0000000000000000000000000000000000000000..2561fbd406f4435868c71c9c9ff4859c3286ff83 --- /dev/null +++ b/video-capture-gsm/simple_test.py @@ -0,0 +1,6 @@ +import os +import subprocess + +# Just run a system command to execute gst-launch directly +print("Running gst-launch-1.0 from Python...") +os.system('gst-launch-1.0 -v videotestsrc ! autovideosink') \ No newline at end of file diff --git a/video-capture-gsm/test-gsm.py b/video-capture-gsm/test-gsm.py new file mode 100644 index 0000000000000000000000000000000000000000..25b82b553b7ff1b80ea9df605390855b255a2c5d --- /dev/null +++ b/video-capture-gsm/test-gsm.py @@ -0,0 +1,13 @@ +import os +import subprocess + +# Run gst-inspect to check for mfvideosrc +result = subprocess.run(['gst-inspect-1.0', 'mfvideosrc'], capture_output=True, text=True) +print("gst-inspect-1.0 output:") +print(result.stdout) +print(result.stderr) + +# Try to run your pipeline +cmd = 'gst-launch-1.0 -e mfvideosrc ! videoconvert ! autovideosink' +print(f"\nRunning: {cmd}") +os.system(cmd) \ No newline at end of file diff --git a/video-capture-gsm/test.py b/video-capture-gsm/test.py new file mode 100644 index 0000000000000000000000000000000000000000..c95f1d35193076f5620c788fed802cf995911e8e --- /dev/null +++ b/video-capture-gsm/test.py @@ -0,0 +1,75 @@ +import os +import subprocess +import time +import csv +import datetime +import re +import signal +import sys + +# Create a CSV file for timestamps +timestamp_file = open('frame_timestamps.csv', 'w', newline='') +csv_writer = csv.writer(timestamp_file) +csv_writer.writerow(['Frame Number', 'System Time', 'Estimated Pipeline Time']) + +# Build the GStreamer command with identity element to print frame timestamps +gst_cmd = ( + 'gst-launch-1.0 -e ' + 'mfvideosrc ! "video/x-raw, width=1920, height=1080" ! videorate ! "video/x-raw, framerate=30/1" ! ' + 'identity silent=false print-timestamps=true print-pts=true ! videoconvert ! ' + 'x264enc ! queue ! mux. ' + 'wasapisrc do-timestamp=true ! audioconvert ! voaacenc ! "audio/mpeg, mpegversion=4, stream-format=raw" ! ' + 'queue max-size-time=2000000000 max-size-bytes=0 max-size-buffers=0 ! mux. ' + 'mp4mux name=mux ! filesink location=output.mp4' +) + +# Frame counter +frame_count = 0 +start_time = datetime.datetime.now() + +# Function to handle Ctrl+C gracefully +def signal_handler(sig, frame): + print(f"\nRecording stopped. Captured {frame_count} frames.") + timestamp_file.close() + sys.exit(0) + +signal.signal(signal.SIGINT, signal_handler) + +# Start the GStreamer process +print(f"Starting recording with command: {gst_cmd}") +process = subprocess.Popen(gst_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1) + +# Regular expression to match timestamp lines +timestamp_pattern = re.compile(r'pts:\s+(\d+):(\d+):(\d+):(\d+)') + +print("Recording... Press Ctrl+C to stop.") + +# Monitor the output for timestamps +while True: + line = process.stdout.readline() + if not line: + break + + # Look for timestamp lines + match = timestamp_pattern.search(line) + if match: + frame_count += 1 + hours, minutes, seconds, nanoseconds = map(int, match.groups()) + + # Calculate timestamp in readable format + timestamp_str = f"{hours:02d}:{minutes:02d}:{seconds:02d}.{nanoseconds//1000000:03d}" + + # Get system time + current_time = datetime.datetime.now() + system_time = current_time.strftime('%H:%M:%S.%f')[:-3] + + # Calculate elapsed time + elapsed = current_time - start_time + elapsed_str = str(elapsed)[:-3] # Remove microseconds + + # Write to CSV + csv_writer.writerow([frame_count, system_time, timestamp_str]) + + # Print info every 30 frames + if frame_count % 30 == 0: + print(f"Frame {frame_count}, System Time: {system_time}, PTS: {timestamp_str}, Elapsed: {elapsed_str}") \ No newline at end of file diff --git a/video-capture-gsm/using_gst.py b/video-capture-gsm/using_gst.py new file mode 100644 index 0000000000000000000000000000000000000000..9f5b573f3c992bb5c3d5cd26586222a295de7d92 --- /dev/null +++ b/video-capture-gsm/using_gst.py @@ -0,0 +1,15 @@ +import sys +import os + +# Ensure the system can find the MSVC GStreamer binaries +os.environ['PATH'] = 'D:/gstreamer/1.0/msvc_x86_64/bin;' + os.environ['PATH'] + +# Use Python's ctypes to directly load the GStreamer libraries +import ctypes +gst = ctypes.CDLL('D:/gstreamer/1.0/msvc_x86_64/bin/libgstreamer-1.0-0.dll') + +# Initialize GStreamer +gst.gst_init(0, None) + +# Now try using the command-line tool via os.system +os.system('gst-launch-1.0 -v mfvideosrc ! videoconvert ! autovideosink') \ No newline at end of file