Wednesday, January 28, 2026

.::: Shell Script to Detect and Compare AI-Generated vs Original Images and Videos :::.

  

A. Install

1. Install for image

sudo dnf install ImageMagick -y
sudo dnf install perl-Image-ExifTool -y

[root@teguhth-all sampleimage]# identify -version
Version: ImageMagick 6.9.13-25 Q16 x86_64 18639 https://legacy.imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib
[root@teguhth-all sampleimage]#

[root@teguhth-all sampleimage]# convert -version
Version: ImageMagick 6.9.13-25 Q16 x86_64 18639 https://legacy.imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib

[root@teguhth-all sampleimage]# exiftool -ver
13.10
[root@teguhth-all sampleimage]#

2. Install for video 

sudo dnf install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm -y

sudo dnf install ladspa -y
sudo dnf install ffmpeg mediainfo perl-Image-ExifTool -y

[root@teguhth-all sampleimage]# ffmpeg -version
ffmpeg version 5.1.7 Copyright (c) 2000-2025 the FFmpeg developers
built with gcc 11 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libjxl --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libshaderc --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzvbi --enable-lv2 --enable-avfilter --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-lto --enable-libmfx --enable-runtime-cpudetect
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# mediainfo --version
MediaInfo Command line,
MediaInfoLib - v23.09
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# exiftool -ver
13.10
[root@teguhth-all sampleimage]#

B. run test 

1. check image ai or not 

[root@teguhth-all sampleimage]# sh cek_image.sh ninja-girl.jpg
File: ninja-girl.jpg
-------------------------
[1] EXIF AI keyword:
Actions Digital Source Type     : http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia
Actions Description             : AI Generated Image
Claim generator                 : Microsoft_Responsible_AI/1.0
Claim Generator Info Name       : Microsoft Responsible AI Image Provenance
Claim Generator Info Version    : 1.0
Item 1 X5Chain                  : (Binary data 1577 bytes, use -b option to extract), (Binary data 1750 bytes, use -b option to extract), (Binary data 1459 bytes, use -b option to extract)

[2] EXIF count:
Metadata lines: 51

[3] Resolution:
ninja-girl.jpg JPEG 1024x1024 1024x1024+0+0 8-bit sRGB 138871B 0.000u 0:00.000

[4] Noise analysis:
ninja-girl.jpg JPEG 1024x1024 1024x1024+0+0 8-bit Gray 138871B 1.290u 0:01.340
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# sh cek_image.sh teguhth.jpg
File: teguhth.jpg
-------------------------
[1] EXIF AI keyword:
Tidak ditemukan

[2] EXIF count:
Metadata lines: 102

[3] Resolution:
teguhth.jpg JPEG 117x175 117x175+0+0 8-bit sRGB 16130B 0.000u 0:00.000

[4] Noise analysis:
teguhth.jpg JPEG 117x175 117x175+0+0 8-bit Gray 16130B 0.020u 0:00.026
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# sh cek_image.sh girl-universe.jpg
File: girl-universe.jpg
-------------------------
[1] EXIF AI keyword:
Tidak ditemukan

[2] EXIF count:
Metadata lines: 28

[3] Resolution:
girl-universe.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 71288B 0.000u 0:00.000

[4] Noise analysis:
girl-universe.jpg JPEG 1280x720 1280x720+0+0 8-bit Gray 71288B 1.000u 0:01.013
[root@teguhth-all sampleimage]#

 

2. check image ai or not with scan folder

[root@teguhth-all sampleimage]# sh folder_image.sh /data/ai/sampleimage
==============================================
 AI IMAGE SCANNER (FINAL v2 LOGIC)
 Directory : /data/ai/sampleimage
 Scan Time : Wed Jan 28 10:20:31 AM WIB 2026
 CSV File  : ai_image_scan.csv
==============================================

==============================================
File: /data/ai/sampleimage/girl-universe.jpg
----------------------------------------------
[1] AI EXIF provenance check:
  -> No AI provenance found

[2] EXIF metadata count:
  -> Metadata lines: 28

[3] Image resolution & format:
/data/ai/sampleimage/girl-universe.jpg JPEG 1280x720 1280x720+0+0 8-bit sRGB 71288B 0.000u 0:00.000

[4] Noise analysis (stddev):
  -> Noise stddev: 1.226000

[5] AI VERDICT:
  -> SUSPICIOUS / AI

==============================================
File: /data/ai/sampleimage/ninja-girl.jpg
----------------------------------------------
[1] AI EXIF provenance check:
JUMD Type                       : (c2pa)-0011-0010-800000aa00389b71
JUMD Label                      : c2pa
C2PA Hash Boxes Salt            : b5dea47b339f6eede5626926ea2b20e6
Boxes Names                     : SOI, C2PA, APP0, DQT, DQT, SOF0, DHT, DHT, DHT, DHT, SOS, EOI
C2PA Actions Salt               : b5dea47b339f6eede5626926ea2b20e6
Actions Digital Source Type     : http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia
Actions Description             : AI Generated Image
Actions Action                  : c2pa.created
Signature                       : self#jumbf=c2pa/urn:uuid:1b1822e1-5e5c-4e6c-a85d-3b29c80dff91/c2pa.signature
Claim Generator Info Name       : Microsoft Responsible AI Image Provenance
Assertions Url                  : self#jumbf=c2pa/urn:uuid:1b1822e1-5e5c-4e6c-a85d-3b29c80dff91/c2pa.assertions/c2pa.hash.boxes, self#jumbf=c2pa/urn:uuid:1b1822e1-5e5c-4e6c-a85d-3b29c80dff91/c2pa.assertions/c2pa.actions

[2] EXIF metadata count:
  -> Metadata lines: 51

[3] Image resolution & format:
/data/ai/sampleimage/ninja-girl.jpg JPEG 1024x1024 1024x1024+0+0 8-bit sRGB 138871B 0.000u 0:00.000

[4] Noise analysis (stddev):
  -> Noise stddev: 1.268000

[5] AI VERDICT:
  -> AI

==============================================
File: /data/ai/sampleimage/teguhth.jpg
----------------------------------------------
[1] AI EXIF provenance check:
  -> No AI provenance found

[2] EXIF metadata count:
  -> Metadata lines: 102

[3] Image resolution & format:
/data/ai/sampleimage/teguhth.jpg JPEG 117x175 117x175+0+0 8-bit sRGB 16130B 0.000u 0:00.000

[4] Noise analysis (stddev):
  -> Noise stddev: 0.021000

[5] AI VERDICT:
  -> NOT_AI

==============================================
 Scan finished
 CSV saved to: ai_image_scan.csv
==============================================
[root@teguhth-all sampleimage]# cat ai_image_scan.csv
filename,ai_exif_provenance,metadata_count,format,resolution,noise_stddev,ai_verdict
"/data/ai/sampleimage/girl-universe.jpg",NO,28,JPEG,1280x720,1.226000,SUSPICIOUS / AI
"/data/ai/sampleimage/ninja-girl.jpg",YES,51,JPEG,1024x1024,1.268000,AI
"/data/ai/sampleimage/teguhth.jpg",NO,102,JPEG,117x175,0.021000,NOT_AI
[root@teguhth-all sampleimage]#
 


3. check video ai or not 

[root@teguhth-all sampleimage]# sh cek_video.sh arini_vid.mp4
File: arini_vid.mp4
=================================

[1] Cryptographic / AI Signature
Comment                         : Signature: VOy/mH+PFGPJQKLk2tlJNS4nP0ET255Bwii3xUn9y/0KjHDRzoeaJzBHG/qQFt+w49QlcV4qat8KdCPYJdX0H0crW1ViSkg63AL1a4Dg5AHj4HIjPHT1UVbPABVBOb4VReOdPz86mnnos43VjkqnG0JFSIDFsBYIMs0xzayybHuXgwMrkoV2k/eQil2Q6N4PpQKaGO13AlB8uvCPvETq2MsthXiRc/P5xDpZGl9FRhRaItZmQ3rFaqgF2xuhcMcBNTtaefPkKyTO73zweQmlb3ZSQKv8inWbaCMzFuL+QT6RNj4L6mZTWXcaMsWjscllcVoRbuHJmxxSXzufbpllC1dOVCc0Xs4ZxCU5WLbjqH+xNNwlv07mooQES/nrUXK4
🚨 AI cryptographic signature terdeteksi

[2] Camera metadata
ℹ️ Tidak ada metadata kamera

[3] Encoder / Software
Writing application                      : Lavf58.76.100

[4] Resolution analysis
Resolution: 688,464

[5] FPS check
FPS: 24/1

[6] Audio presence
Audio: aac

[7] Creation time
creation_time kosong

=================================
AI Forensic Score : 9.5 / 12
Probabilitas AI   : 70.0 %
Probabilitas Human: 30.0 %

⚠️  SANGAT KUAT MENGARAH KE VIDEO AI
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# sh cek_video.sh teguh_vid.mp4
File: teguh_vid.mp4
=================================

[1] Cryptographic / AI Signature
Tidak ditemukan

[2] Camera metadata
ℹ️ Tidak ada metadata kamera

[3] Encoder / Software


[4] Resolution analysis
Resolution: 1920,1080

[5] FPS check
FPS: 90000/1

[6] Audio presence
Audio: aac

[7] Creation time
creation_time: 2026-01-27T08:37:27.000000Z

=================================
AI Forensic Score : 1 / 12
Probabilitas AI   : 0 %
Probabilitas Human: 100 %

✅ CENDERUNG VIDEO MANUSIA
[root@teguhth-all sampleimage]#
[root@teguhth-all sampleimage]# sh cek_video.sh perawan_bujang.mp4
File: perawan_bujang.mp4
=================================

[1] Cryptographic / AI Signature
Tidak ditemukan

[2] Camera metadata
ℹ️ Tidak ada metadata kamera

[3] Encoder / Software


[4] Resolution analysis
Resolution: 352,288

[5] FPS check
FPS: 25/1

[6] Audio presence
Audio: aac

[7] Creation time
creation_time: 2007-10-18T17:04:22.000000Z

=================================
AI Forensic Score : 1 / 12
Probabilitas AI   : 0 %
Probabilitas Human: 100 %

✅ CENDERUNG VIDEO MANUSIA
[root@teguhth-all sampleimage]# sh cek_video.sh metrodata.mp4
File: metrodata.mp4
=================================

[1] Cryptographic / AI Signature
Tidak ditemukan

[2] Camera metadata
ℹ️ Tidak ada metadata kamera

[3] Encoder / Software


[4] Resolution analysis
Resolution: 848,478

[5] FPS check
FPS: 30/1

[6] Audio presence
Audio: aac

[7] Creation time
creation_time kosong

=================================
AI Forensic Score : 1.5 / 12
Probabilitas AI   : 10.0 %
Probabilitas Human: 90.0 %

✅ CENDERUNG VIDEO MANUSIA
[root@teguhth-all sampleimage]# sh cek_video.sh wa_teguh.mp4
File: wa_teguh.mp4
=================================

[1] Cryptographic / AI Signature
Tidak ditemukan

[2] Camera metadata
ℹ️ Tidak ada metadata kamera

[3] Encoder / Software


[4] Resolution analysis
Resolution: 848,478

[5] FPS check
FPS: 90000/1

[6] Audio presence
Audio: aac

[7] Creation time
creation_time kosong

=================================
AI Forensic Score : 1.5 / 12
Probabilitas AI   : 10.0 %
Probabilitas Human: 90.0 %

✅ CENDERUNG VIDEO MANUSIA
[root@teguhth-all sampleimage]#
 


4. check video ai or not with scan folder
[root@teguhth-all sampleimage]# sh folder_video.sh /data/ai/sampleimage
Scanning 8 video(s)...
-------------------------------------------
[AI] (1/8) video-girl-amry.mp4            | SCORE:  85 | AI
[AI] (2/8) 1.mp4                                   | SCORE:  85 | AI
[AI] (3/8) arini_vid.mp4                       | SCORE:  85 | AI
[OK] (4/8) perawan_bujang.mp4         | SCORE:    5 | ASLI
[OK] (5/8) the-end-of-the-world.mp4  | SCORE:    5 | ASLI
[OK] (6/8) metrodata.mp4                    | SCORE:    5 | ASLI
[OK] (7/8) teguh_vid.mp4                    | SCORE:    0 | ASLI
[OK] (8/8) wa_teguh.mp4                    | SCORE:    0 | ASLI
-------------------------------------------
Scan selesai.
CSV output: hasil_scan_video_ai.csv

[root@teguhth-all sampleimage]# cat hasil_scan_video_ai.csv
filename,encoder,fps,resolution,audio,signature,ai_score,label
"/data/ai/sampleimage/video-girl-amry.mp4","Lavf58.76.100","24/1","464x688","aac","yes","85","AI"
"/data/ai/sampleimage/1.mp4","Lavf58.76.100","24/1","464x688","aac","yes","85","AI"
"/data/ai/sampleimage/arini_vid.mp4","Lavf58.76.100","24/1","688x464","aac","yes","85","AI"
"/data/ai/sampleimage/perawan_bujang.mp4","","25/1","352x288","aac","no","5","ASLI"
"/data/ai/sampleimage/the-end-of-the-world.mp4","","25/1","406x850","aac","no","5","ASLI"
"/data/ai/sampleimage/metrodata.mp4","","30/1","848x478","aac","no","5","ASLI"
"/data/ai/sampleimage/teguh_vid.mp4","","90000/1","1920x1080","aac","no","0","ASLI"
"/data/ai/sampleimage/wa_teguh.mp4","","90000/1","848x478","aac","no","0","ASLI"
[root@teguhth-all sampleimage]#
 


C. Script 

1. script image ai or not 
[root@teguhth-all sampleimage]# pwd
/data/ai/sampleimage
[root@teguhth-all sampleimage]# cat cek_image.sh
#deteksi_ai_image.sh

#sudo dnf install ImageMagick -y
#sudo dnf install perl-Image-ExifTool -y

#!/bin/bash

FILE="$1"

echo "File: $FILE"
echo "-------------------------"

echo "[1] EXIF AI keyword:"
exiftool "$FILE" | grep -Ei "stable|midjourney|dall|firefly|ai|generated|diffusion" || echo "Tidak ditemukan"

echo
echo "[2] EXIF count:"
COUNT=$(exiftool -s "$FILE" | wc -l)
echo "Metadata lines: $COUNT"

echo
echo "[3] Resolution:"
identify "$FILE"

echo
echo "[4] Noise analysis:"
convert "$FILE" -colorspace Gray -statistic StandardDeviation 3x3 info:

[root@teguhth-all sampleimage]#


2. script image ai or not with scan folder

[root@teguhth-all sampleimage]# pwd
/data/ai/sampleimage
[root@teguhth-all sampleimage]# cat folder_image.sh
#!/bin/bash
# scan_ai_images_csv_verdict_final_v2.sh
# Improved AI image detection (realistic heuristic)

DIR="$1"
CSV_OUTPUT="ai_image_scan.csv"

if [ -z "$DIR" ]; then
  echo "Usage: $0 <image_directory>"
  exit 1
fi

if [ ! -d "$DIR" ]; then
  echo "Directory not found: $DIR"
  exit 1
fi

echo "filename,ai_exif_provenance,metadata_count,format,resolution,noise_stddev,ai_verdict" > "$CSV_OUTPUT"

echo "=============================================="
echo " AI IMAGE SCANNER (FINAL v2 LOGIC)"
echo " Directory : $DIR"
echo " Scan Time : $(date)"
echo " CSV File  : $CSV_OUTPUT"
echo "=============================================="

shopt -s nullglob

for FILE in "$DIR"/*.{jpg,jpeg,png,webp,tiff}; do
  echo
  echo "=============================================="
  echo "File: $FILE"
  echo "----------------------------------------------"

  ### [1] AI EXIF PROVENANCE (STRONG SIGNAL)
  echo "[1] AI EXIF provenance check:"
  AI_EXIF=$(exiftool "$FILE" | grep -Ei \
    "trainedAlgorithmicMedia|AI Generated|Stable Diffusion|Midjourney|DALL·E|Firefly|Responsible AI|C2PA")

  if [ -n "$AI_EXIF" ]; then
    echo "$AI_EXIF"
    AI_EXIF_FOUND="YES"
  else
    echo "  -> No AI provenance found"
    AI_EXIF_FOUND="NO"
  fi

  ### [2] Metadata count
  echo
  echo "[2] EXIF metadata count:"
  META_COUNT=$(exiftool -s "$FILE" | wc -l)
  echo "  -> Metadata lines: $META_COUNT"

  ### [3] Resolution & format
  echo
  echo "[3] Image resolution & format:"
  IDENTIFY_OUT=$(identify -format "%m,%wx%h" "$FILE" 2>/dev/null)
  FORMAT=$(cut -d',' -f1 <<< "$IDENTIFY_OUT")
  RESOLUTION=$(cut -d',' -f2 <<< "$IDENTIFY_OUT")
  identify "$FILE"

  ### [4] Noise analysis
  echo
  echo "[4] Noise analysis (stddev):"
  RAW_NOISE=$(convert "$FILE" -colorspace Gray -statistic StandardDeviation 3x3 info: 2>/dev/null)
  NOISE=$(echo "$RAW_NOISE" | sed 's/.*://' | awk '{printf "%.6f\n",$1}')
  [ -z "$NOISE" ] && NOISE=0
  echo "  -> Noise stddev: $NOISE"

  ### [5] CAMERA METADATA CHECK
  CAMERA_META=$(exiftool "$FILE" | grep -Ei "Camera Model|Lens|Make|ISO" | wc -l)

  ### [6] HEURISTIC FLAGS
  META_LOW=$(awk -v m="$META_COUNT" 'BEGIN{print(m<40)}')
  NOISE_HIGH=$(awk -v n="$NOISE" 'BEGIN{print(n>0.5)}')
  RES_AI=$(echo "$RESOLUTION" | grep -Eq '^(512x512|768x768|1024x1024|1280x720)$' && echo 1 || echo 0)
  NO_CAMERA=$(awk -v c="$CAMERA_META" 'BEGIN{print(c==0)}')

  ### [7] VERDICT
  VERDICT="NOT_AI"

  if [ "$AI_EXIF_FOUND" = "YES" ]; then
    VERDICT="AI"
  else
    SCORE=$((META_LOW + NOISE_HIGH + RES_AI + NO_CAMERA))
    if [ "$SCORE" -ge 2 ]; then
      VERDICT="SUSPICIOUS / AI"
    fi
  fi

  echo
  echo "[5] AI VERDICT:"
  echo "  -> $VERDICT"

  ### CSV
  echo "\"$FILE\",$AI_EXIF_FOUND,$META_COUNT,$FORMAT,$RESOLUTION,$NOISE,$VERDICT" >> "$CSV_OUTPUT"

done

echo
echo "=============================================="
echo " Scan finished"
echo " CSV saved to: $CSV_OUTPUT"
echo "=============================================="

[root@teguhth-all sampleimage]#

3. script video ai or not 
[root@teguhth-all sampleimage]# pwd
/data/ai/sampleimage
[root@teguhth-all sampleimage]# cat cek_video.sh
#!/bin/bash
FILE="$1"

if [ -z "$FILE" ]; then
  echo "Usage: $0 video.mp4"
  exit 1
fi

SCORE=0
MAX_SCORE=12

echo "File: $FILE"
echo "================================="

# ---------------------------------------------------
echo
echo "[1] Cryptographic / AI Signature"
SIG=$(exiftool "$FILE" | grep -Ei "signature")
if [ -n "$SIG" ]; then
  echo "$SIG"
  SCORE=$((SCORE+4))
  echo "🚨 AI cryptographic signature terdeteksi"
else
  echo "Tidak ditemukan"
fi

# ---------------------------------------------------
echo
echo "[2] Camera metadata"
CAM=$(exiftool "$FILE" | grep -Ei "camera model|make|lens")
if [ -z "$CAM" ]; then
  echo "ℹ️ Tidak ada metadata kamera"
  SCORE=$((SCORE+1))
else
  echo "$CAM"
fi

# ---------------------------------------------------
echo
echo "[3] Encoder / Software"
ENC=$(mediainfo "$FILE" | grep -Ei "writing application|encoder")
echo "$ENC"
echo "$ENC" | grep -qi "lavf\|ffmpeg" && SCORE=$((SCORE+1))

# ---------------------------------------------------
echo
echo "[4] Resolution analysis"
RES=$(ffprobe -v error -select_streams v:0 \
-show_entries stream=width,height -of csv=p=0 "$FILE")
echo "Resolution: $RES"

# GAN portrait resolutions (AI diffusion)
echo "$RES" | grep -Eq "464,688|688,464|512,768|576,1024" && SCORE=$((SCORE+3))

# ---------------------------------------------------
echo
echo "[5] FPS check"
FPS=$(ffprobe -v error -select_streams v:0 \
-show_entries stream=r_frame_rate -of csv=p=0 "$FILE")
echo "FPS: $FPS"

# ---------------------------------------------------
echo
echo "[6] Audio presence"
AUD=$(ffprobe -v error -select_streams a \
-show_entries stream=codec_name -of csv=p=0 "$FILE")
[ -n "$AUD" ] && echo "Audio: $AUD" || echo "Tidak ada audio"

# ---------------------------------------------------
echo
echo "[7] Creation time"
TIME=$(ffprobe -v error -show_entries format_tags=creation_time -of csv=p=0 "$FILE")
if [ -z "$TIME" ]; then
  echo "creation_time kosong"
  SCORE=$(echo "$SCORE + 0.5" | bc)
else
  echo "creation_time: $TIME"
fi

# ---------------------------------------------------
AI_PERCENT=$(echo "scale=1; ($SCORE/$MAX_SCORE)*100" | bc)
HUMAN_PERCENT=$(echo "scale=1; 100-$AI_PERCENT" | bc)

echo
echo "================================="
echo "AI Forensic Score : $SCORE / $MAX_SCORE"
echo "Probabilitas AI   : $AI_PERCENT %"
echo "Probabilitas Human: $HUMAN_PERCENT %"
echo

# ---------------------------------------------------
if (( $(echo "$AI_PERCENT >= 85" | bc -l) )); then
  echo "🚨 HAMPIR PASTI VIDEO AI (GENERATIVE MODEL)"
elif (( $(echo "$AI_PERCENT >= 65" | bc -l) )); then
  echo "⚠️  SANGAT KUAT MENGARAH KE VIDEO AI"
elif (( $(echo "$AI_PERCENT >= 45" | bc -l) )); then
  echo "⚠️  TIDAK KONKLUSIF"
else
  echo "✅ CENDERUNG VIDEO MANUSIA"
fi

[root@teguhth-all sampleimage]#


4. script video ai or not with scan folder

[root@teguhth-all sampleimage]# pwd
/data/ai/sampleimage
[root@teguhth-all sampleimage]# cat folder_video.sh
#!/bin/bash

DIR="$1"
CSV="hasil_scan_video_ai.csv"

if [ -z "$DIR" ] || [ ! -d "$DIR" ]; then
  echo "Usage: $0 /path/video_folder"
  exit 1
fi

echo "filename,encoder,fps,resolution,audio,signature,ai_score,label" > "$CSV"

mapfile -d '' FILES < <(find "$DIR" -type f \( \
  -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mov" \
  \) -print0)

TOTAL=${#FILES[@]}
COUNT=0

echo "Scanning $TOTAL video(s)..."
echo "-------------------------------------------"

for FILE in "${FILES[@]}"; do
  [ ! -f "$FILE" ] && continue
  COUNT=$((COUNT+1))
  SCORE=0

  # ---------------------------------------------------
  # Signature (Grok / AI watermark)
  SIG=$(exiftool "$FILE" | grep -Ei "signature")
  [ -n "$SIG" ] && SCORE=$((SCORE+40))

  # ---------------------------------------------------
  # Encoder
  ENCODER=$(mediainfo "$FILE" | grep -Ei "writing application|encoder" | head -1 | cut -d: -f2 | xargs)
  echo "$ENCODER" | grep -qi "lavf\|ffmpeg" && SCORE=$((SCORE+10))

  # ---------------------------------------------------
  # FPS
  FPS=$(ffprobe -v error -select_streams v:0 \
    -show_entries stream=r_frame_rate -of csv=p=0 "$FILE")
  [[ "$FPS" =~ ^(24|25|30)/1$ ]] && SCORE=$((SCORE+5))

  # ---------------------------------------------------
  # Resolution
  RES=$(ffprobe -v error -select_streams v:0 \
    -show_entries stream=width,height -of csv=p=0:s=x "$FILE")

  # GAN portrait resolutions
  echo "$RES" | grep -Eq "464x688|688x464|512x768|576x1024" && SCORE=$((SCORE+30))

  # ---------------------------------------------------
  # Audio
  AUDIO=$(ffprobe -v error -select_streams a \
    -show_entries stream=codec_name -of csv=p=0 "$FILE")
  [ -z "$AUDIO" ] && AUDIO="none"

  # ---------------------------------------------------
  # Label
  if [ "$SCORE" -ge 70 ]; then
    LABEL="AI"
    TAG="[AI]"
  elif [ "$SCORE" -ge 50 ]; then
    LABEL="KEMUNGKINAN AI"
    TAG="[!!]"
  else
    LABEL="ASLI"
    TAG="[OK]"
  fi

  # ---------------------------------------------------
  printf "%s (%d/%d) %-35s | SCORE: %3d | %s\n" \
    "$TAG" "$COUNT" "$TOTAL" "$(basename "$FILE")" "$SCORE" "$LABEL"

  echo "\"$FILE\",\"$ENCODER\",\"$FPS\",\"$RES\",\"$AUDIO\",\"$( [ -n "$SIG" ] && echo yes || echo no )\",\"$SCORE\",\"$LABEL\"" >> "$CSV"
done

echo "-------------------------------------------"
echo "Scan selesai."
echo "CSV output: $CSV"

[root@teguhth-all sampleimage]#

No comments:

Post a Comment

Popular Posts