Using ffmpeg to capture frames from webcam and audio from micro and saving to file

后端 未结 1 1672
粉色の甜心
粉色の甜心 2020-12-31 19:59

For the past few weeks I\'ve been struggling with the ffmpeg API since I can not find a clear documentation and I also find it hard to search as all the solutions I find onl

相关标签:
1条回答
  • 2020-12-31 20:34

    Your problem seems to be somewhat specific to DirectShow. Unfortunately I don't have access to a system with DirectShow, but from the symptom it looks like the capture is not your problem. What is wrong is the muxing part. May be the format of the video packets is not directly supported in AVI, or may be the timestamps on the packets are broken.

    I will recommend a few things that you should try, one at a time:

    • Try using av_write_frame instead of av_interleaved_write_frame.
    • Use a better container, like MP4 or MKV.
    • Do not try to mux the input packet to an avi file. In grabFrames take the raw video packets and dump them into a file. That should give you a file that is playable by ffplay. (You will probably have to specify resolution, pixel format and format in your ffplay command.)
    • Did the above result in a playable video file? If yes then I'd recommend that you decode the individual video packets, convert the colorspace and encode them using a common codec. (I recommend yuv420p in h264.) FFmpeg code base have two examples which should be useful - demuxing_decoding.c and decoding_encoding.c. That should give you a proper video file. (Playable in most players.)

    I don't know anything about DirectShow, and I don't know your use case. So my recommendations focus on FFmpeg API. Some of it may be overkill / may not do what you want.

    0 讨论(0)
提交回复
热议问题