Click here to Skip to main content
15,566,522 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to convert H264 video file to MP4 file with audio.
When i am converting H264 to MP4, i could not get the audio when playing the video.

What I have tried:

I tried converting H264 file to MP4 file using ffMPEG. Its converted but audio is not coming. can you tell me the reason and how it can be achieved in C#.Net.
Posted
Updated 13-Mar-22 8:42am
v2
Comments
Member 15564955 14-Mar-22 5:38am    
Sorry, you are quite right - now submitted as a new question.

H264 is a video stream format - it doesn't contain any audio stream data at all.
MP4 is a package, which can contain both audio and video stream(s) - but it can't "invent" an audio stream from video data!

Start with your movie source file: it probably contains both video and audio streams, and you will need to fetch / convert both in order to build a "working" MP4 file.

Check you original with VLC: "Tools...Codec Information" will show you what streams are present in the original file. FFMPEG can extract both Video and Audio streams to separate files, and then combine them back again.

Extract Audio stream:
ffmpeg -i GoodAudioInput.mp4 -c:a copy -vn -sn audio.m4a
Get Video stream:
ffmpeg -i GoodVideoInput.mp4 -c:v copy -sn -an video.mp4
Merge the two:
ffmpeg -i video.mp4 -i audio.m4a -c:v copy -c:a aac -strict experimental merged.mp4
To resync audio:
ffmpeg -i video.mp4 -itsoffset 3.0 -i audio.m4a -c:v copy -c:a aac -strict experimental merged.mp4
(Will make audio 3.0 seconds later)
 
Share this answer
 
Hi, I am trying to convert files from a Chinese manufactured birdbox camera which also has a microphone. The camera records files with the extension .h264 and until recently, the only way I had found to convert them to a format I could play on Windows was using software they supplied (videoconver.exe) to convert to mp4 (video and sound). videoconver lacks any documentation and delivers video which runs at double speed. I also really need a way of batching the conversion of all the files which I am sending to an ftp server.

I then discovered ffmpeg and found I could convert these files using

ffmpeg -r 12 -i atest.h264 -c copy ffatest.mp4

...but only the video comes across. I tried the solution above but the audio extraction doesn't work and I get lots of error messages and no output file. The following shows the command and relevant output:

ffmpeg -i atest.h264 -c:a copy -vn -sn ffatest.m4a

[h264 @ 000002218326ce00] Format h264 detected only with low score of 1, misdetection possible!
[extract_extradata @ 0000022183255b00] Invalid NAL unit 0, skipping.
Last message repeated 4 times
[h264 @ 000002218326dd40] Invalid NAL unit 0, skipping.
Last message repeated 36 times
[h264 @ 000002218326ce00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, h264, from 'atest.h264':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 2288x1288, 24 fps, 24 tbr, 1200k tbn
Output #0, ipod, to 'ffatest.m4a':
Output file #0 does not contain any stream

What I think is going on here is that the format they are using is proprietary (I read somewhere that this could be to avoid licence fees). It definitely contains both video and audio.

Does anyone have any advice on how to convert these files - I suspect that millions of people have these cameras (mine is made or oem'd by Golbong but I suspect others are using this format too judging by a bit of googling).

TIA

Wallport
 
Share this answer
 
Comments
Richard Deeming 14-Mar-22 5:07am    
If you want to ask a question, then ASK A QUESTION[^].

Your question is not a solution to someone else's question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900