Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Convert raw image buffer into JPEG using LIBAVCODEC
24 août 2018, par user846400I have a raw image buffer (in memory) captured from a camera that I want to convert into JPEG (for reducing size). The problem is that saving these images into .pgm format results into a huge file size that I can't afford due to the memory limitations and latency involved in saving a huge file of this size (a constraint in the application I am working on).
I want to know how do I compress/encode an image buffer into .jpg format using LIBAVCODEC? My image capture code is in C.
-
FFMPEG : Issue with -t Option
24 août 2018, par mf_starboi_8041I am using
-t
option with output filename to generate the Output File with certain second provided with-t
option.Example Command,
ffmpeg -r 30 -i -c copy -t 10 output.mp4
So For Example,
30 Frames * 10 Seconds = 300 Frames
Output.mp4
should have 300 frames. But I am gettingOutput.mp4
with less than 300 Frames like 272 frames and 290 frames etc.. Around 9+ Second content but not exact 10 Seconds.Any one faces same behavior. Please let me know. Thank you in advance.
Logs that May help as asked by @Gyan,
Input file #0 (input_fifo.264): Input stream #0:0 (video): 301 packets read (2559184 bytes); Total: 301 packets (2559184 bytes) demuxed Output file #0 (output.mp4): Output stream #0:0 (video): 294 packets muxed (2509136 bytes); Total: 294 packets (2509136 bytes) muxed 0 frames successfully decoded, 0 decoding errors
-
ffmpeg : zoom over bottom-right or bottom-left corners of an image
24 août 2018, par Vinod MankareI need to create a video with zoom effect over an image to highlight bottom right/left corner with the help of ffmpeg.
I am trying with the following command:
ffmpeg -loop 1 -i {image.png} -filter_complex "zoompan=z='zoom+0.002':x='trunc(380)':y='trunc(287)':d=100" -ss 0 -i {audio.mp3} -c:v libx264 -crf 0 -c:a aac -strict experimental -b:v 6M -b:a 1080k -r 25 -bufsize 1080k -shortest -s 1920x1080 -aspect 16:9 -y {output.mp4} 2>&1
Its working for the top (right/left) and centre element but not getting proper zoom effect for bottom corners for the same image. Please suggest what am I doing wrong, or is there any other best option to do the same?
-
How to get DirectShow device list with ffmpeg in c++ ?
24 août 2018, par fyoI'm trying to get dshow device list with ffmpeg. I cannot get it but ffmpeg gets it by its own. Here is the code. It returns AVERROR(ENOSYS) for avdevice_list_input_sources. But avformat_open_input prints all devices. How can I get dshow devices and options in c++ code.
avdevice_register_all(); AVInputFormat *iformat = av_find_input_format("dshow"); printf("========Device Info=============\n"); AVDeviceInfoList *device_list = NULL; AVDictionary* options = NULL; //av_dict_set(&options, "list_devices", "true", 0); int result = avdevice_list_input_sources(iformat, NULL, options, &device_list); if (result < 0) printf("Error Code:%s\n", av_err2str(result));//Returns -40 AVERROR(ENOSYS) else printf("Devices count:%d\n", result); AVFormatContext *pFormatCtx = avformat_alloc_context(); AVDictionary* options2 = NULL; av_dict_set(&options2, "list_devices", "true", 0); avformat_open_input(&pFormatCtx, NULL, iformat, &options2); printf("================================\n");
-
How to decrease the latency of the RTP streaming with ffmpeg in Android ?
24 août 2018, par Douglas Lima DantasI'm creating a App that do a RTP streaming. It uses a ParcelFileDescriptor pipe pair, where a MediaRecorder writes in the pipe while the ffmpeg receives the audio from the pipe and sends by RTP.
In my desktop, using the same wifi router, I receive the RTP stream using ffplay, and it has a delay between 5s ~ 10s.
I tried capture audio using ffmpeg in Android, but itsn't possible. I tried to use ffplay -fflags nobuffer, use MIC as source, change the encoder, etc.
I need the lowest delay possible. How can I do it?
The code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener { MediaRecorder mediaRecorder; AudioRecord record; MediaPlayer mediaPlayer; ParcelFileDescriptor[] pipePair; ParcelFileDescriptor pipeRead; ParcelFileDescriptor pipeWrite; Process ffmpegProc; // Requesting permission to RECORD_AUDIO private boolean permissionsAccepted = false; private String [] permissions = { Manifest.permission.RECORD_AUDIO, Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE }; private static final int REQUEST_PERMISSIONS = 200; @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode){ case REQUEST_PERMISSIONS: permissionsAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED; break; } if (!permissionsAccepted ) finish(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActivityCompat.requestPermissions(this, permissions, REQUEST_PERMISSIONS); TextView hello = (TextView) findViewById(R.id.hello); hello.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Clicado",Toast.LENGTH_SHORT) .show(); copiarFFMpeg(); } }); } private void executarFFMpeg(final String[] cmd, ParcelFileDescriptor read) { try { ffmpegProc = Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); } (new Thread(new Runnable() { @Override public void run() { try { InputStream inStream = ffmpegProc.getInputStream(); InputStreamReader sReader = new InputStreamReader(inStream); BufferedReader bufferedReader = new BufferedReader(sReader); String line; while ((line = bufferedReader.readLine()) != null) { Log.d("FFMPEG",line); } } catch (IOException e) { e.printStackTrace(); } } })).start(); (new Thread(new Runnable() { @Override public void run() { byte[] buffer = new byte[8192]; int read = 0; OutputStream ffmpegInput = ffmpegProc.getOutputStream(); FileInputStream reader = new FileInputStream(pipeRead.getFileDescriptor()); try { while (true) { if (reader.available()>0) { read = reader.read(buffer); ffmpegInput.write(buffer, 0, read); ffmpegInput.flush(); } else { Thread.sleep(10); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); onDestroy(); } } })).start(); Log.d("FFMPEG","Executado"); } private boolean estaExecutando(Process ffmpegProc) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return ffmpegProc.isAlive(); } else { try { ffmpegProc.exitValue(); return false; } catch (Exception e) { return true; } } } private void criarMediaRecorder() { if (pipeWrite != null) { try { //ffplay.exe -protocol_whitelist rtp,file,udp ..\file.sdp mediaRecorder = new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //mediaRecorder.setAudioChannels(2); mediaRecorder.setOutputFile(pipeWrite.getFileDescriptor()); mediaRecorder.prepare(); mediaRecorder.start(); Log.d("MREC","MediaRecorder criado"); } catch (Exception e) { e.printStackTrace(); } } } private void criarPipe() { try { pipePair =ParcelFileDescriptor.createPipe(); } catch (IOException e) { Log.e("PIPE","Deu zica na criação do pipe"); e.printStackTrace(); finish(); } pipeRead = new ParcelFileDescriptor(pipePair[0]); pipeWrite = new ParcelFileDescriptor(pipePair[1]); } private void copiarFFMpeg() { FFmpeg ffmpeg = FFmpeg.getInstance(this); try { ffmpeg.loadBinary(new LoadBinaryResponseHandler() { @Override public void onStart() { Log.d("FFMPEG","Iniciar cópia"); } @Override public void onFailure() { Log.e("FFMPEG","Cópia falhou"); } @Override public void onSuccess() { Log.d("FFMPEG","Cópiado com sucesso"); criarPipe(); //mediaRecorder.start(); File ffmpegBin = new File(getFilesDir().getAbsolutePath()+"/ffmpeg"); String[] cmd = new String[] { ffmpegBin.getAbsolutePath(), "-re", "-thread_queue_size","4", "-i","pipe:", //"-c:a","libx264", //"-preset","veryfast", //"-tune","zerolatency", "-f", "rtp", "rtp://192.168.0.33:1234" }; executarFFMpeg(cmd, pipeRead); criarMediaRecorder(); } @Override public void onFinish() { } }); } catch (FFmpegNotSupportedException e) { // Handle if FFmpeg is not supported by device Log.e("FFMPEG", "Não sou suportado :/"); } } @Override protected void onDestroy() { super.onDestroy(); } @Override public void onClick(View view) { } }
The command:
ffplay rtp://192.168.0.33:1234 ffplay -fflags nobuffer rtp://192.168.0.33:1234