Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFmpeg record rtsp stream to file error
29 mars 2017, par tommyvisagroupI use ffmpeg to record rtsp stream, it work good but the output file got some proble, when I use use K-Lite Codec Pack to open the output (avi) file the video cant be seek, forward, backward and dont display video time. It lock like i am viewing streaming.
here is the command i used
ffmpeg -i rtsp://27.74.xxx.xxx:55/ufirststream -acodec copy -vcodec copy abc.avi
-
Find if video file has audio present in it
29 mars 2017, par KartosI'm trying to figure out if a video has audio present in it so as to extract the mp3 using ffmpeg. When the video contains no audio channels, ffmpeg creates an empty mp3 file which I'm using to figure out if audio was present in the video in the first place. I'm sure there is a better way to identify if audio is present in a video. Will avprobe help with this? Can anyone point me to a resource or probably a solution?
Edit: Surprisingly, the same command on my server running the latest build of ffprobe doesn't run. It throws an error saying
Unrecognized option 'select_stream'
Failed to set value 'a' for option 'select_stream'
Any ideas how to rectify this out?
-
Error decoding a simple audio file using FFmpeg library
29 mars 2017, par satyresAfter successfuly compiling the latest version of FFmpeg library and generated .a library in Ubuntu I've been struggling now for more than a week to decode and play a simple mp3 file in Android without a success ! I've followed this tutorial given by FFmpeg team in Github i've tried to use it in Android but no luck ! here is the Native code.
void Java_com_example_home_hellondk_MainActivity_audio_1decode_1example(JNIEnv * env, jobject obj, jstring file, jbyteArray array) { jboolean isfilenameCopy; const char * filename = ( * env) - > GetStringUTFChars(env, file, & isfilenameCopy); jclass cls = ( * env) - > GetObjectClass(env, obj); jmethodID play = ( * env) - > GetMethodID(env, cls, "playSound", "([BI)V"); AVCodec * codec; AVCodecContext * c = NULL; int len; FILE * f, * outfile; uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; AVPacket avpkt; AVFrame * decoded_frame = NULL; av_init_packet( & avpkt); printf("Decode audio file %s \n", filename); LOGE("Decode audio file %s\n", filename); /* find the MPEG audio decoder */ codec = avcodec_find_decoder(AV_CODEC_ID_MP3); if (!codec) { fprintf(stderr, "Codec not found\n"); LOGE("Codec not found\n"); exit(1); } c = avcodec_alloc_context3(codec); if (!c) { fprintf(stderr, "Could not allocate audio codec context\n"); LOGE("Could not allocate audio codec context\n"); exit(1); } /* open it */ if (avcodec_open2(c, codec, NULL) < 0) { fprintf(stderr, "Could not open codec\n"); LOGE("Could not open codec\n"); exit(1); } f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "Could not open %s\n", filename); LOGE("Could not open %s\n", filename); exit(1); } /* decode until eof */ avpkt.data = inbuf; avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); while (avpkt.size > 0) { int i, ch; int got_frame = 0; if (!decoded_frame) { if (!(decoded_frame = av_frame_alloc())) { fprintf(stderr, "Could not allocate audio frame\n"); LOGE("Could not allocate audio frame\n"); exit(1); } } len = avcodec_decode_audio4(c, decoded_frame, & got_frame, & avpkt); if (len < 0) { fprintf(stderr, "Error while decoding\n"); LOGE("Error while decoding\n"); exit(1); } if (got_frame) { /* if a frame has been decoded, output it */ int data_size = av_get_bytes_per_sample(c - > sample_fmt); if (data_size < 0) { /* This should not occur, checking just for paranoia */ fprintf(stderr, "Failed to calculate data size\n"); LOGE("Failed to calculate data size\n"); exit(1); } if (data_size > 0) { jbyte * bytes = ( * env) - > GetByteArrayElements(env, array, NULL); memcpy(bytes, decoded_frame, got_frame); // ( * env) - > ReleaseByteArrayElements(env, array, bytes, 0); ( * env) - > CallVoidMethod(env, obj, play, array, got_frame); LOGE("DECODING ERROR5"); } } avpkt.size -= len; avpkt.data += len; avpkt.dts = avpkt.pts = AV_NOPTS_VALUE; if (avpkt.size < AUDIO_REFILL_THRESH) { /* Refill the input buffer, to avoid trying to decode * incomplete frames. Instead of this, one could also use * a parser, or use a proper container format through * libavformat. */ memmove(inbuf, avpkt.data, avpkt.size); avpkt.data = inbuf; len = fread(avpkt.data + avpkt.size, 1, AUDIO_INBUF_SIZE - avpkt.size, f); if (len > 0) avpkt.size += len; } } fclose(f); avcodec_free_context( & c); av_frame_free( & decoded_frame); }
The Java code :
package com.example.home.hellondk; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioTrack; import android.media.MediaPlayer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class MainActivity extends AppCompatActivity { static { System.loadLibrary("MyLibraryPlayer"); } public native void createEngine(); public native void audio_decode_example(String outfilename, byte[] array); private AudioTrack track; private FileOutputStream os; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); createEngine(); /* MediaPlayer mp = new MediaPlayer(); mp.start();*/ int bufSize = AudioTrack.getMinBufferSize(32000, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT); track = new AudioTrack(AudioManager.STREAM_MUSIC, 32000, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufSize, AudioTrack.MODE_STREAM); byte[] bytes = new byte[bufSize]; try { os = new FileOutputStream("/storage/emulated/0/Cloud Radio/a.out", false); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } audio_decode_example("/storage/emulated/0/Cloud Radio/test.mp3", bytes); } void playSound(byte[] buf, int size) { //android.util.Log.v("ROHAUPT", "RAH Playing"); if (track.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) track.play(); track.write(buf, 0, size); try { os.write(buf, 0, size); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
I always got this error : Error while decoding . i've tried to change the decoder "AV_CODEC_ID_MP3" no sucess ! Thank you so much for your help. Kind regards
-
Running cmd in python (ffmpeg)
29 mars 2017, par CoolcrabAtm I have this as my code, the first line seems to work well but the 2nd gives errrors.
os.chdir('C://Users/Alex/Dropbox/code stuff/test') subprocess.call(['ffmpeg', '-i', 'test%d0.png', 'output.avi'])
error:
Traceback (most recent call last): File "C:\Users\Alex\Dropbox\code stuff\solarsystem.py", line 56, in
subprocess.call(['ffmpeg', '-i', 'test%d0.png', 'output.avi']) File "C:\Python27\lib\subprocess.py", line 524, in call return Popen(*popenargs, **kwargs).wait() File "C:\Python27\lib\subprocess.py", line 711, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 948, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified -
opencv rtsp stream protocol
29 mars 2017, par k_kazI want to process and display a network rtsp stream that is created from a raspberry camera. I have this code:
#include
#include #include highgui/highgui.hpp> #include imgproc/imgproc.hpp> int main(int argc, char** argv) { cv::VideoCapture * stream = new cv::VideoCapture("rtsp://192.168.55.151:8554/"); if (!stream->isOpened()) return -1; cv::namedWindow("rtsp_stream", CV_WINDOW_AUTOSIZE); cv::Mat frame; while (true) { if (!stream->read(frame)) return -1; cv::imshow("rtsp_stream", frame); cv::waitKey(15); } return 1; } When the stream is not live, the execution of this results in:
[tcp @ 0xa12480] Connection to tcp://192.168.55.151:8554?timeout=0 failed: Connection refused
Which means that the stream tries to connect with tcp. When the stream is live, the execution results in:
[rtsp @ 0xb07960] method SETUP failed: 461 Client error
From internet research i found that the problem may be that the stream uses udp. If i change the URL to:
"udp://192.168.55.151:8554/"
Then the execution freezes in the
cv::VideoCapture("udp://192.168.55.151:8554/");
VLC is able to open the rtsp stream. As i am given to understand, ffmpeg is used to decode the stream with opencv. When i run:
ffmpeg -rtsp_transport udp -i rtsp://192.168.55.151:8554/ -t 5 test.mp4
the stream decoding and saving is successful. So how can i specify the lower level protocol to be udp in the opencv code? Is there another way to do it with opencv?
EDIT: If i change the ffmpeg command to use tcp, i.e:
ffmpeg -rtsp_transport tcp -i rtsp://192.168.55.151:8554/ -t 5 test.mp4
then i get the same exact error with the c++ code, 461 client error
EDIT: When the code uses the udp:// link, after some 15 seconds of freeze, the execution returns with error