I need to record a video stream and mix it with audio from external device (USB sound card). I managed to record the video and audio separately with following commands.

Video ffmpeg -i rtsp:// -acodec copy -vcodec copy ~/out.mp4

Audio ffmpeg -f alsa -i hw:1 -t 30 out.wav

Now I need to record both at the same time and create an mp4 file.

I tried this command, but it gives me an error.

ffmpeg -f alsa -i hw:1 -i rtsp://  -acodec copy -vcodec copy ~/out.mp4

Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

EDIT: Using mkv container instead of mp4 works. How should I encode the video to be able to store it as mp4?

  • Not really sure which audio stream you want to record (from the video or from the audio input)? There is no information about the audio codec for the audio stream; in the separate record wavis implicit from the extension of the output file. Try to use map and explicit audio codec. – ridgy Feb 20 '17 at 11:40

MP4 doesn't support PCM audio (the format family commonly found in WAV files).

The console output indicates this immediately above the line you showed, but you omitted it:

[mp4 @ 0x559e59ef2360] Could not find tag for codec pcm_s16le in stream #0, codec not currently supported in container

You options are:

  • Output to a different output container format, such as .mov or Matroska (.mkv) as you already discovered, or
  • Encode the audio to a format supported by MP4, such as AAC, by replacing -acodec copy with -c:a aac.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.