Skip to content

A Python tool to convert video files into high-capacity QR codes for offline storage and transfer, and later reconstruct them seamlessly. Includes self-contained folders and auto-rebuild scripts for portability.

Notifications You must be signed in to change notification settings

akashdip2001/video-to-QR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 video-to-QR : QRVideoSlicer


πŸ“„ Project Description

QRVideoSlicer is a Python-based tool that allows users to split large video files into QR code images, making it possible to store and share videos within size-limited platforms (e.g., GitHub’s 25MB file limit). Each QR code contains a chunk of the encoded video, and a header file maps the order and metadata.

The same tool can then be used to reconstruct the original video from these QR codes. This makes the system ideal for scenarios where videos need to be archived or transferred in limited environments.

idea


βœ… Key Features

  • 🧩 Split large videos into compressed QR code chunks.
  • πŸ“ Folder-wise organization of QR images for each video.
  • πŸ“œ Header file ensures correct reassembly of videos.
  • ⚑ Interactive script with options: Convert or Reassemble.
  • πŸ—‘οΈ Prompts to delete original video or uninstall dependencies after use.
  • πŸ§ͺ Auto-check and install dependencies.

πŸ“‚ Directory Structure

project_root/
β”œβ”€β”€ Video to QR.py         # Main interactive script
β”œβ”€β”€ output/                # Reconstructed videos
β”œβ”€β”€ MyVideo.mp4            # Input video file
β”œβ”€β”€ MyVideo/               # Folder with QR images and header
β”‚   β”œβ”€β”€ chunk_00000.png
β”‚   β”œβ”€β”€ chunk_00001.png
β”‚   β”œβ”€β”€ ...
β”‚   β”œβ”€β”€ header.json
β”‚   └── export_here.py     # Auto-reassemble script

πŸ”„ Workflow Diagram

          +------------------+
          |   Input Video    |
          +--------+---------+
                   |
                   v
         +---------------------+
         | QRVideoSlicer Tool  |
         | [1] Convert Video   |
         | [2] Export Video    |
         +---+-----------+----+
             |           |
   +---------+           +---------+
   |                             |
+--v--+                     +----v-----+
| QR  |                     | Rebuild  |
| Img |                     | Video    |
| Set |                     +----+-----+
+-----+                          |
                          +-----v------+
                          | output.mp4 |
                          +------------+

πŸ§ͺ Code Snippets and How They Work ??

πŸ”Ή 1. Splitting video into QR chunks

with open("MyVideo.mp4", 'rb') as f:
    video_data = f.read()

# Encode video to base64
b64_data = base64.b64encode(video_data).decode('utf-8')

# Split into smaller chunks
chunks = [b64_data[i:i+CHUNK_SIZE] for i in range(0, len(b64_data), CHUNK_SIZE)]

What it does: Reads the video file and splits it into chunks small enough to fit into individual QR codes.


πŸ”Ή 2. Creating QR codes from chunks

for i, chunk in enumerate(chunks):
    qr = qrcode.QRCode(version=40, box_size=10, border=2)
    qr.add_data(chunk)
    img = qr.make_image()
    img.save(f"chunk_{i:05d}.png")

What it does: Each base64 chunk is converted into a high-capacity QR code image and saved.


πŸ”Ή 3. Header file to store metadata

header = {
    "video_name": "MyVideo.mp4",
    "num_chunks": len(chunks),
    "chunk_size": 2000,
    "encoding": "base64"
}
with open("header.json", 'w') as f:
    json.dump(header, f)

What it does: Stores necessary info for reconstructing the video later, including number of QR codes and original filename.


πŸ”Ή 4. Reconstructing video from QR codes

# Load header metadata
with open("header.json") as f:
    meta = json.load(f)

# Read and decode all QR images
video_data = ''
for i in range(meta['num_chunks']):
    image = Image.open(f"chunk_{i:05d}.png")
    decoded = decode(image)[0].data.decode('utf-8')
    video_data += decoded

# Convert back to binary video
with open(f"output_{meta['video_name']}", 'wb') as f:
    f.write(base64.b64decode(video_data))

What it does: Sequentially decodes all QR codes, concatenates their data, and writes the result as the reconstructed video.


πŸ’» How to Use

  1. Place video file in script directory

  2. Run the script:

    python "Video to QR.py"
  3. Choose:

    • [1] Convert to QR codes
    • [2] Export video from QR codes
  4. Follow prompts to delete original video or clean up environment.




⭐ Video to QR ⭐



Screenshot (665) Screenshot (664) Screenshot (667)




⭐ QR to Video ⭐



QR.to.Video.mp4

The warnings you're seeing β€” like:

WARNING: zbar\decoder\databar.c:1250: <unknown>: Assertion "seg->finder >= 0" failed.

β€” are coming from the pyzbar library, which uses ZBar, a C-based QR/barcode scanner. These warnings typically occur when ZBar fails to recognize a QR code or interprets image data as an invalid code.


βœ… The Script Is Working β€” ⚠️ But with Errors:

These warnings don't immediately crash the script, but they likely indicate that:

  1. Some QR code images aren't being decoded properly.
  2. May end up with a corrupted output video, or the script may fail later due to a missing or unreadable chunk.

πŸ” Common Causes & Fixes:

1. QR Codes Are Too Dense or Large

  • You are using:

    QR_VERSION = 40
    QR_BOX_SIZE = 10

    QR version 40 holds a lot of data β€” nearly 3KB per code β€” and becomes visually complex, especially for pyzbar to decode correctly.

    βœ… Fix: Reduce QR_VERSION to something like 20–30, and increase QR_BOX_SIZE to 12–15 for better clarity.

2. Image Format or Compression

  • Saving in PNG is fine, but any post-processing or compression (e.g., if opened and resaved) may affect readability.

    βœ… Fix: Ensure the images remain untouched between encode and decode.

3. Switch to More Reliable QR Decoder

  • pyzbar is sometimes less accurate with large, complex QR codes.
  • Alternative: Use opencv-python and cv2.QRCodeDetector, which can decode with more robustness.

πŸ›  Recommended Fixes (Code-Level)

Here’s how can improve decoding: (open source contributors)

πŸ” Update decode_qr_image() to Use OpenCV (Fallback or Primary)

def decode_qr_image(image):
    import cv2
    import numpy as np
    from pyzbar.pyzbar import decode as pyzbar_decode

    try:
        # Try pyzbar first
        result = pyzbar_decode(image)
        if result:
            return result[0].data.decode('utf-8')
    except Exception:
        pass

    # Fallback to OpenCV QR detection
    img_array = np.array(image.convert('RGB'))
    detector = cv2.QRCodeDetector()
    data, _, _ = detector.detectAndDecode(img_array)
    if data:
        return data
    raise ValueError("QR decoding failed with both pyzbar and OpenCV.")

βš™οΈ Tune QR Generation (Optional but Strongly Recommended)

In your encode_video_to_qr():

# Try reducing version and increasing box size for easier scanning
QR_VERSION = 30  # instead of 40
QR_BOX_SIZE = 12  # bigger boxes = easier decode

πŸ“š Conclusion

QRVideoSlicer is a unique, practical tool built for modern-day versioning and distribution challenges involving large video files. Its focus on interactivity, automation, and data preservation makes it ideal for learning purposes and real-world utility.


🎯 Need Future Upgrade

  • If user want - add passward when Increft & pass must requird to Export.
  • add a Output folder for Output videos.
  • Fix error handaling.

About

A Python tool to convert video files into high-capacity QR codes for offline storage and transfer, and later reconstruct them seamlessly. Includes self-contained folders and auto-rebuild scripts for portability.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages