I have converted H.265 video file in dav format from Dahua camera using following commands. Both of the generated mp4 video files are NOT playable in iPhone default player. However, the generated video files are playable in VLC player.
ffmpeg -y -i hevc.dav -c:v copy -tag:v hvc1 hevc.mp4
ffmpeg -y -i hevc.dav -tag:v hvc1 -c:v copy -f mp4 -movflags frag_keyframe+empty_moov hevc.mp4
Generated video file plays only if I re-encode the video using following command.
ffmpeg -y -i hevc.dav -c:v libx265 -tag:v hvc1 hevc.mp4
Re-encoding is time consuming. So, please let me know, if I am missing any flags in the above commands.
Solution:
Input File had some extra bytes at the beginning (the first 46kb) and which came before the actual DAV header. Removing these exra bytes made for a new output DAV file that FFmpeg would then accept and correctly mux into MP4.
Future readers can look into these research points:
Process:
I verified the source .dav file using
hexdump -Ccommand and found that the at the start of the file the bytes are not DHAV. It gave me a clue that the first HEVC frame is not complete.I wrote a small C program to search whether there are further DHAV bytes in the file and I found the DHAV after about 46KB. I removed these partial bytes from the beginning of the file and wrote the remaining bytes to another file named hevc_cropped_bytes.dav and ran the following command.
This time the generated video file is properly played. Here is the program that removes the partial bytes from the beginning of the file.