Skip to main content

Fix video bị lỗi

Thi thoảng video quay bằng device như cam hành trình, điện thoại, máy ảnh ... bị lỗi. Biểu hiện là không mở được bẳng các player, điển hình là ông VLC cũng không coi được thì chịu.
Trước khi fix chúng ta tìm nguyên nhân. Thông tin video có thể dùng tool mà coi. VD dùng lệnh FFMPEG thì mình được 1 trường hợp lỗi như sau :
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x14af280] moov atom not found
2014_0205_192247_002.MOV: Invalid data found when processing input

Nguyên nhân chi tiết đại khái là liên quan đến thiết bị quay trong quá trình quay gặp vấn đề như sụt nguồn, bị va đập ...
Cấu trúc 1 video là dạng file đã được mã hóa và nén lại. Các chuẩn nén mình nói nôm là như là H.264 cho MOV, MP4 ...
Khi mà đang quay video chưa rứt thì quá trình lưu video lại có kèm theo xử lý nén, mã hóa ... bị ngắt đột xuất. Vì thế mà dẫn tới lỗi. Trình đọc (player) không thể xử lý giải mã nội dung video. Nó không biết video dài bao nhiêu, kết thúc như nào.
Bình thường tải video về bị lỗi gián đoạn thì VLC vẫn coi được đoạn đầu, sau mới ngắt. Nhưng video nguồn ở đây là đã chơi được, còn trường hợp ngay từ lúc quay đã chết thì oẳng luôn.
Bằng chứng khi quay video bằng điện thoại, lúc stop rồi lưu video, máy sẽ quay quay 1 lúc tức là đang hoàn tất quá trình nén, mã hóa rồi đóng việc lưu file lại.

=> Fix: search từ khóa "moov atom not found" cho 1 link stack
https://superuser.com/questions/1033251/how-to-recover-1-4gb-video-file-that-cant-be-read-canon
=> Dùng tool như trong link. Trên mạng thấy có một vài tool nhưng cứ mai một dần do ít người dùng với lại không có kinh phí. Tìm được 1 tool thì lại chỉ chạy trên windows. Mình ngại restart máy vô win nên remote vô một máy win cho nhanh. Video hơn 700MB share qua Google drive.
Trên windows cần cài thêm ffmpeg, tool chuyên làm việc với video, audio. Các bạn tải bản portable đỡ phải cài cắm, set up đường dẫn ..
https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg
Chọn tải static build sẵn.
Trước mình cũng cài ffmpeg trên win nhưng sau ít dùng nên xóa đi.

Tool recover_mp4.exe
Coi hướng dẫn. Về cơ bản luồng như sau:
1. Chạy tool trên 1 video mẫu (chạy ngon) để tool nó detect cách thiết bị quay ghi hinh, lưu định dạng, nén .. video như thế nào. Nên để 1 video ngắn thôi cho nhanh.
Chạy lệnh analyze để lấy thông tin thiết bị quay:
recover_mp4.exe good_sample.MOV --analyze
Kết quả máy minh hiện là

Now run the following command to start recovering:
recover_mp4.exe corrupted_file result.h264 result.wav --novatek

Then use ffmpeg to mux the final file:
ffmpeg.exe -r 30.000 -i result.h264 -i result.wav -c:v copy -c:a copy result.mov

Con cam cám lợn của mình là SJ5000 chạy chíp novatek khựa.
Trên đây là 2 dòng hướng dẫn bước tiếp theo fix video sau khi analyze xong.

Đầu tiên chạy lệnh recover xử lý file lỗi, tách ra 1 file video .h264 và 1 file audio .wav, hãng recorder để là novatek.
Cuối cùng chạy lệnh ffmpeg để ghép lại video hoàn chỉnh.

Good luck!

Notes:
- Thao tác cmd trên windows các bạn tự search. VD Shift + right click để mởi command promt trong thư mục hiện thời.
- FFMPEG tài về giải nén cùng thư mục recover_mp4 và đổi tên cho gọn.
- Chạy lệnh ffmpeg có thể cân đường dẫn chuẩn, vd: 
ffmpeg/bin/ffmpeg.exe ...
- Máy mình có sample video chạy OK, nếu ko có video mẫu để tool phân tích có thể dùng tham số sẵn có. Coi tài liệu kèm tool để biết thêm. Các device nổi như Gopro, Canon, Sony ... có tham số riêng, có thể ko cần phải 1 video mẫu.


Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe