Converting pcap file with http stream of video to mpeg file

asked 2024-01-30 14:52:00 +0000

updated 2024-01-30 16:27:57 +0000

Chuckc gravatar image

Hello everyone,

I'm attempting to figure out how to accomplish this task. I'm executing a code via Windows Bash, and I would greatly appreciate any assistance in understanding where I may have made errors.

When I run the code or make any other attempt, the resulting MPEG file consistently has a different size than the original. For instance, if the original file is 1MB in size, the new file is only 200KB, and it cannot be opened.

#!/bin/bash

# Log file path
log_file="script_log.txt"

# Function to log messages
log_message() {
    echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> "$log_file"
}

# Set input and output file paths
pcap_file="C:\\Users\\admin\\Desktop\\Poliice Project\\Live_Video_Capture.pcapng"
packet_number=18
output_file="C:\\Users\\admin\\Desktop\\Poliice Project\\output.mpeg"

# Ensure required tools are installed
command -v tshark >/dev/null 2>&1 || { log_message "Please install tshark first."; exit 1; }
command -v ffmpeg >/dev/null 2>&1 || { log_message "Please install ffmpeg first."; exit 1; }

# Filter and export raw packet data using tshark
log_message "Exporting raw packet data using tshark..."
tshark -r "$pcap_file" -Y "frame.number == $packet_number && tcp.stream==2" -w "/tmp/raw_stream2_data.pcapng"

# Check for errors in tshark output
if [ $? -ne 0 ]; then
    log_message "Error occurred during tshark execution."
    exit 1
fi

# Convert the raw data to MPEG using ffmpeg
log_message "Converting raw data to MPEG using ffmpeg..."
ffmpeg -i "/tmp/raw_stream2_data.pcapng" "$output_file"

# Check for errors in ffmpeg output
if [ $? -ne 0 ]; then
    log_message "Error occurred during ffmpeg execution."
    exit 1
fi

log_message "Conversion completed successfully. Output file: $output_file"

# Clean up temporary files
log_message "Cleaning up temporary files..."
rm "/tmp/raw_stream2_data.pcapng"

# Prompt the user to

edit retag flag offensive close merge delete

Comments

What are the expectations for this line?

tshark -r "$pcap_file" -Y "frame.number == $packet_number && tcp.stream==2" -w "/tmp/raw_stream2_data.pcapng"
Chuckc gravatar imageChuckc ( 2024-01-30 16:31:07 +0000 )edit

This line specifies a specific packet within the HTTP traffic. However, I realized that I don't need to specify the frame number to export the entire HTTP stream.

im getting the mepg file but he damaged.

any idea ?

luchacho1414 gravatar imageluchacho1414 ( 2024-02-20 13:22:44 +0000 )edit