How to implement a command line of ffmpeg with ffmpeg static lib? - c++

I need a simple ffmpeg conversion task to be done inside an application:
ffmpeg -i input_file.m4v -vcodec copy -acodec copy -vbsf h264_mp4toannexb output_file.ts
This works well using the terminal. I've successfully compiled ffmpeg's static lib. Some examples work perfectly, that means the lib is working. How do I implement the behaviour of the above command line with this library?
I looked into ffmpeg.c. But there is so much code inside that it took me hours to get an idea on how it works. Finally I still don't really understand the whole structure.
I would be very happy if someone could help me understanding how to use the library to do the very same what the example command line does. (At the end I just want to transmux mp4 files to ts files without reencoding)
Thanks in advance
Jack

Related

Use FFMPEG in OpenCV without internet connection

I am creating a project in c++ with QtCreator (5.14.1, MingGW compiler) and trying to use OpenCv (3.4.16) to read video files. I have tried many files of standard formats and codecs (H.264, yuv420, .mov etc). However, no matter what I try, VideoCapture() always silently fails. It doesn’t crash or show any error code, instead isOpened() is just always false.
I think the cause is that I am building opencv (via this tutorial https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows) without internet connection (I cannot have internet connection on this machine, so please do not ask me to) and therefore it can’t download the FFMPEG libraries during this process. I have been looking everywhere for information about how to download the FFMPEG libraries for opencv directly but I haven’t had any luck.
Can someone please explain what libraries I need to download and how opencv goes about looking for them? because at the moment I don’t know what I need, nor where to put them, and I cant find any information on the topic.
Or, can someone explain why calling VideoCapture(“video.mov”, cv::CAP_ANY) doesn’t have any effect? (despite being able to play the video easily in VLC, MediaPlayer etc).
Code:
`
int main()
{
VideoCapture cap(“C://video.mov”);
//VideoCapture cap(“C:/video.mov”);
//VideoCapture cap(“C:\video.mov”);
//VideoCapture cap(“C:\video.mov”);
if (!cap.isOpened()){
cout << "Error opening video stream or file"<< endl;
return -1;
}
}
`
I have tried downloading some ffmpeg DLLs and the EXEs and adding them to the PATH, no success. I have also tried downloading the shared GPL of ffmpeg (that comes with the libs and include) and added them my .pro file but no change in VideoCapture behavior.
I have also tried moving the opencv_ffmpeg_64.dll (found in opencv/build/bin) to my executable directory but that didn't fix anything.
In the end I used this guys answer,
How do i compile opencv_ffmpeg.dll file using mingw on windows 10 64 bit?
Just note that some of the directories are a little different now. You don't need to put them in a folder named after the hash, or in a 'download' subdirectory, and you need to copy all of them to opencv-build/3rd party/ffmpeg/. I also put them in opencv/source/3rd party/ffmpeg, but not sure if I needed to do that. Finally you need to go into the ffmpeg.cmake file and set 'status' to TRUE when the download fails (or just remove the download part altogether), this lets it call ffmpeg_version.cmake and set things up.

error regarding ffmpeg while using python to access a wav file

When I used python audio segment to open a .wav file and divide it into many .wav files i am getting this error
"C:\Python27\lib\site-packages\pydub\utils.py:165: RuntimeWarning: Couldn't find
ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work"
, RuntimeWarning)"
It seems like you don't have ffmpeg, which is listed in the dependencies section of the Pydub GitHub. However, it is only required if you wish to load or save non-WAV files.
This message is just a warning, if you're using Pydub solely for WAV files, it is safe to simply ignore it.

Creating a bash script to compile a c++

I have a program I've written in c++ which outputs some simulation results to a .csv excel file.
According to some instructions I need to create a simple bash script that would run the .cpp file given the command "$ run_program" ($ is not a part of the command).
I've looked on Stackoverflow and other sites however I have not found a concrete answer to help me. I would also greatly appreciate it if those who answer can take some time to explain what the parameters mean.
Thank you.
How I should make a bash script to run a C++ program?
This is one of the links I've looked at, however I could not make heads or tails out of this.
i dont know the command you are using to compile your c++ program but this might help you.
Create a file with ".sh" extension and open it with your favorite text editor.
Paste this code (change compiling line with line you are using to compile your progam)
#!/bin/bash
#Run this in terminal
#+ Command to compile c++ program. here i used common one
g++ filename.cpp -o anyname
exit 0
Now you need to run this script, To do this open a terminal
chmod u+x scriptname.sh
Then run the script by ./scriptname.sh
Hopefully this will compile your program.
It sounds like a Makefile is what you are looking for here. Definitely worth getting a handle on if you deal with programming.

Convert .264 to .ts using ffmpeg library

I'm currently working on converting h.264 elementary stream (file with postfiix .264) to transport stream (file with postfix .ts). I have finished the conversion successfully using ffmpeg command line "ffmpeg -i in.264 -an -vcodec copy -f mpegts out.ts".
Now I want to implement this conversion using my own C++ code, by calling ffmpeg's libraries. I have downloaded precompiled ffmpeg libraries (libavcodec, libavformat etc). My input h.264 is prerecorded file, not live stream, and so as my output .ts file. So my question is which functions in the library should I call to implement the conversion?
You will see an example file named ffmpeg.c after you install ffmpeg in Linux. There are many options to set the decoding parameters in this file e.g. opt_audio_codec, opt_video_codec, opt_audio_rate, opt_video_rate, opt_default etc. Just set the necessary parameters from your command(-i in.264 -an -vcodec copy -f mpegts out.ts) using appropriate functions before calling "transcode" or "av_encode" function from "main" function of ffmpeg.c file.
It's not as simple as list the library calls. Here is an old tutorial that will help you get started reading the input file. There is also an example called decoding_encoding.c that is included with the ffmpeg source. These should help you get started.
You don't need to do it in your own code. You can just spawn the ffmpeg process programatically instead. Use CreateProcess on Windows, or spawn on Linux.

c++ boost library cannot open file

I tried to work with the boost library to read/write configuration files but I just don't get it.
I even can't run the example code from boost.org (5 Minute Tutorial)
http://www.boost.org/doc/libs/1_49_0/libs/property_tree/examples/debug_settings.cpp
I've downloaded the boost_1_49_0.zip package and unzipped it to my c++ program folder. The code compiles (TheIDE - U++) but it always says "Error: debug_settings.xml: cannot open file" which basically means that the program works, but runs into the exception.
I didn't change the code, I just copy and pasted it to get a working example which I could try to understand then. But I don't even get this one to work. (Since it's exactly the same as in the link, I don't paste the code here... unless you think it's better.)
Please help me... or point to a different way to store variables in a file with some kind of structure (I wan't to learn a way that works for windows and linux, because some of my apps are cross-platform.)
Thanks.
EDIT: debug_settings.xml is in the same folder as the .cpp file
EDIT2: Working now, the debug_settings.xml is now in the folder where the executable is stored. (in my case, U++/TheIDE it's C:\upp\out\MyApps\MINGW.Debug.Debug_Full.Sse2 for debugging)
The configuration file would need to be in the working directory of the executable when it's running.