Issue
I am using FFmpeg to re stream video from a camera(which is connected via wifi with no internet connection) to another server, and I want to do the re streaming process via cellular data. As I am already connected to wifi and to use cellular data at the same time bindProcessToNetwork()
. Before executing ffmpeg command I have done the the following
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder req = new NetworkRequest.Builder();
req.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
req.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
cm.requestNetwork(req.build(), new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
//here you can use bindProcessToNetwork
//cm.getNetworkInfo(network);
if (cm.getNetworkInfo(network).getType() == ConnectivityManager.TYPE_MOBILE) {
cm.bindProcessToNetwork(network);
}
}
});
it is working fine in most of the case, like webview is working properly by using cellular data , while connected to wifi , but when I try to execute any ffmpeg command it doesn't work .
Solution
bindProcessToNetwork
calls through to netd
in order to bind the current process to the chosen network. In ffmpeg-android-java the ffmpeg binary is executed using Runtime.getRuntime().exec(String). Consequently ffmpeg is actually running as a separate child process. Netd does not automatically bind child processes to the same network as their parent, and so you will find that ffmpeg does not inherit this configuration. Meanwhile other aspects of your application such as WebView, URLConnection etc.. which are all running within your process will use your chosen network as expected.
To resolve this issue you have a number of options (from easiest to hardest):
- Modify the ffmpeg-android-java source to add a command-line parameter for ffmpeg which specifies the network it should use (from a cursory glance I do not see any support for this in ffmpeg)
- Find a command-line utility which can force the ffmpeg binary onto the right network (may require root)
- Rebuild ffmpeg to add support for native sockets bound to the network of your choosing
- Directly call netd to set the default network for the new ffmpeg process (likely to require root)
Answered By - gisHermit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.