Combining MJPEG AVI with PCM WAV and encoding using H264

0

We are trying to set up an experiment where the subject will listen to auditory stimuli while watching a movie. We generated the WAV audio files using a PCM codec (pcm_s16le). The AVI video was generated using a Matlab script and is MJPEG format.

We've carefully calibrated the video and audio for the experiment, so we are trying to minimize lossiness (we are fine if the output is very large). According to the eye-tracking software, H264 is the preferred format for the video. We've tried setting this up by first re-encoding the video:

ffmpeg -y -i video.avi -vcodec libx264 video_264.avi

Then, when we attempt to merge the video and audio streams:

ffmpeg -y -i video_264.avi -i audio.wav -c copy merged.avi

We get the following warning:

[avi @ 0x5640ff0ca940] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly

Although the output file seems to work, we are having issues with downstream software that uses the video for our experiments (the output of the software is supposed to save timing information related to responses from the subject, but it's not doing so sometimes). We're wondering if it's because there's an issue with the timestamps. However, I cannot, for the life of me, figure out how to set the timestamps. I have a feeling it has to do with the conversion from the MJPEG to H264 codec, but I've tried various options such as -fflags +genpts -r 60, etc. to no avail.

How can I fix the timestamp issue? Timing of the video and audio are critical to our experiments.

Brad

Posted 2019-11-07T18:59:27.983

Reputation: 1

What formats (video, audio, container) does the downstream software support? – llogan – 2019-11-07T19:28:03.733

For video, the software recommends H264 in a MP4 format but will also support DIVX and XVID codecs in either MP4 or AVI format. For audio, the software accepts MP3, AAC, AC3 and PCM formats.

I tried switching the output from AVI to MP4 but still got the same error. Plus, I'm a bit hesitant to use MP4 since no lossless codec is supported for audio (we do auditory research, so our stimuli are very carefully crafted to achieve particular signal to noise ratios for experiments). – Brad – 2019-11-07T19:32:58.967

I wouldn't recommend AVI for H264. ffmpeg will mux PCM into MOV. It will mux FLAC into MP4. mp4box will mux PCM into MP4. – Gyan – 2019-11-07T19:53:34.043

That's fine. Even if I switch to MP4, I still get the error regarding timestamps. How do I fix this? – Brad – 2019-11-07T20:20:20.737

Your first step (re-encode) saves to MP4 as well? – Gyan – 2019-11-08T13:04:35.717

Thanks! I hadn't thought of that. I re-encoded the video and saved to MP4. Then, the second step didn't give a warning about timestamps. If you want to post this as an answer I'll accept it. – Brad – 2019-11-09T05:18:51.613

No answers