How to copy audio stream using FFMpeg API ( not a command line tool ) - opencv

I'm developing some Video Editing Apps on Android.
the objective of the app is "Editing Videos on Android".
and...
I'm just completed making video file using some images.
but.. I can't attach audio into the video.
my method is same as follows.
1.VideoStream, audio stream creation using AVFormatContext
2.Movie encoding in video stream was successful
3.Encode codec open in audio stream was successful
4.Set sample format to AV_SAMPLE_FMT_FLTP
5.Sample rate and channel was set same as source audio
6.Choose appropriate Decoder and read packet
7.Convert packets using swr_converter, setting same as sample format
8.Encode converted data
9.memory deallocation
10.END!
Problem is here:
Video of finally created video file was normally played. but the Audio wasn't.
It heared like weird. It have many noises and plays slowly.
I've googled with many keywords but they only say about "FFmpeg command line usage".
I wanna make with FFMpeg API. not a Command line tool.
Please help.

Your question is vague without some kind of code to go along with it, as trust me there are a lot of things that can go wrong when using ffmpeg's libraries directly (and on Windows there is no debuging). Unfortunately ffmpeg's libraries are not well documented so it is generally best to read the source code for ffmpeg in order to use its libraries. Find the equivalent command line options to perform what you want and track that through ffmpeg's source to see the library calls.

Related

Ignore known header of video file

i have video uncompressed .avi video files. however they come with a known 2048kb header at the beginning of the file, such that no video program (Vlc player) recognises the file as video files. can i force VLC to ignore the first 2048kb? how?
what would be the easiest way to remove this header?
Unfortunately there is no known to me way of getting vlc to use a larger "probesize" or somehow just skip to byte X.
Also unfortunately there is no known to me way to add some "camouflage" or even add an empty chunk to the front of an avi container. Next approach could be to genereate a reference movie but also no automatic usage tools available at the best of my knowledge. And as there is also no way to just "set or change" the start offset of a file, we have to copy it.
My recommendation for copying parts of files is this sourceforge project: skf
https://sourceforge.net/projects/swissfileknife/?source=typ_redirect
some examples

libffmpeg: writing an RTSP stream to an output file

I'm working with libffmpeg in an iOS app. My goal is to connect to an RTSP source and write the media out to a file that can later be used with the iOS media player. Ideally I'd like to do this without transcoding the incoming data. I also want to be able to later re-encode the media with AVAssetExportSession if the user chooses to do so.
Because I want to create a file that is compatible with iOS, I'm limited (I believe) to mpeg, mp4 or quicktime (mov) formats.
Whenever I try to use one of these formats, I see the following warnings during my call to avformat_write_header:
[mov # 0x16401c00] Codec for stream 0 does not use global headers but container format requires global headers
[mov # 0x16401c00] Codec for stream 1 does not use global headers but container format requires global headers
My understanding is that the header wants to know the ultimate file size, which I do not know (the RTSP server is live streaming a camera, and the user stops the recording whenever they want). I guess that makes sense, but I know that others have successfully done this using the ffmpeg command line, so I'm confused as to what else I need to do here.
If I ignore the warning, I can still proceed with writing the file. If I choose mpeg or mp4 formats, my app crashes when I call av_write_trailer. If I use mov, I can successfully close the file, and the file does play back, but usually fails when I try to hand it to the AVAssetExportSession.
I would appreciate any insight into this. Thanks.
Frank
I found what appears to be a solution -- at least, it eliminates the warning. I had to set the CODEC_FLAG_GLOBAL_HEADER on both the audio and video codecs, before calling avcodec_open2.

Read stream from specific link

I need to read stream from mjpeg with OpenCV library. In more details, I need to read http://194.126.108.66:8887/. But when I try to do it with
VideoCapture ipCam;
ipCam.open("http://194.126.108.66:8887/")
I get the error icvOpenAvi_XINE(): Unable to initialize video driver.
I have tested this code with another link to mjpeg - http://c-cam.uchicago.edu/mjpg/video.mjpg
It works fine.
What is the difference between these 2 links? And how to read http://194.126.108.66:8887/?
OpenCV expects a filename extension for its VideoCapture argument, even though one isn't always necessary (like in your case).
You can "trick" it by passing in a dummy parameter which ends in the mjpg extension:
ipCam.open("http://194.126.108.66:8887/?dummy=param.mjpg")
This worked in my similar OpenCV Python case, so good luck!
This is worked for me with Mjpeg streamer and OpenCV
cap.open("http://192.168.1.206:8080/?action=stream?dummy=param.mjpg")

Chroma key software (script)

I have thousands of small videos in HDTV quality. All with green chroma key.
I need to change green colour for a static image (company logos).
There are several softwares that can change chroma key, but they are only one by one file.
This will take years to be completed.
Is there a software (script) that I can make this automatic?
I would start with avisynth it's a simple scripting language for video and can use avidemux to edit video interactively or x264 and ffmpeg to read/write files automatically.
edit:
see http://forum.videohelp.com/threads/184560-AviSynth-Chroma-Key
The avisynth interpreter loads your file itself, it then spits out the processed frames. If you run the script with the avisynth proxy (included with avidemux) then players like avidemux can connect to the proxy as if they were opening a file and play the processed video.
The x264 commandline H264 codec can also run avisynth scripts, you just supply the script as the input filename (remember the actual source file is inside the script) and it will output the processed, and then H264 coded file to an mp4
the tutorials make more sense than I do .......

Buffering in Blackberry

Currently I am working on the application for which I have to use audio buffering. Please tell me how I can achieve this task as I am trying myself.
read this Buffer and play streamed media
Also, there's a great example in the Blackberry SDK, which shows buffered playback of a MP3 file.
Take a look in the 'samples' folder of JDE/Eclipse Plugin.

Resources