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"