Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
ffmpeg curves video filter
8 octobre 2013, par Veja AlinaI try to apply a curves video filter. I tried:
ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vf curves=vintage -s 640x480 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k /sdcard/videokit/curve.mp4
But it doesn't work. I need a valid
ffmepg
command.EDIT (from the comments):
-vf curves=vintage is not a valid command.The resulted video can't be played
. I tried-filter_complex
also but it only plays the audio. -
Android FFmpegPlayer Streaming Service onClick notification
8 octobre 2013, par agonyI have a MainActivity class that displays the list of streams available for my project and the StreamingActivity class where the streaming is done.
If the user selected an item from the list it will start the StreamingActivity and start playing the stream. I'm having trouble to continue streaming music when the user pressed the notification and returning it to the StreamingActivity class if the user pressed or clicked the home menu or when the app goes to onDestroy().
I'm using FFmpegPlayer for my project 'coz it requires to play mms:// live streams for local FM station.
Here's my code:
public class StreamingActivity extends BaseActivity implements ActionBar.TabListener, PlayerControlListener, IMediaPlayerServiceClient { private StatefulMediaPlayer mMediaPlayer; private FFmpegService mService; private boolean mBound; public static final String TAG = "StationActivity"; private static Bundle mSavedInstanceState; private static PlayerFragment mPlayerFragment; private static DJListFragment mDjListFragment; private SectionsPagerAdapter mSectionsPagerAdapter; private ViewPager mViewPager; private String stream = ""; private String fhz = ""; private String page = "0"; private Dialog shareDialog; private ProgressDialog dialog; private boolean isStreaming; /*************************************************************************************************************/ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_station); Bundle bundle = getIntent().getExtras(); if(bundle !=null){ fhz = bundle.getString("fhz"); stream = bundle.getString("stream"); } Log.d(TAG, "page: " + page + " fhz: " + fhz + " stream: " + stream + " isStreaming: " + isStreaming); getSupportActionBar().setTitle("Radio \n" + fhz); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mPlayerFragment = (PlayerFragment) Fragment.instantiate(this, PlayerFragment.class.getName(), null); mDjListFragment = (DJListFragment) Fragment.instantiate(this, DJListFragment.class.getName(), null); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setCurrentItem(Integer.parseInt(page)); mSavedInstanceState = savedInstanceState; Tab playingTab = getSupportActionBar().newTab(); playingTab.setText(getString(R.string.playing_label)); playingTab.setTabListener(this); Tab djTab = getSupportActionBar().newTab(); djTab.setText(getString(R.string.dj_label)); djTab.setTabListener(this); getSupportActionBar().addTab(playingTab); getSupportActionBar().addTab(djTab); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { StationActivity.this.getSupportActionBar().setSelectedNavigationItem(position); } }); if (mSavedInstanceState != null) { getSupportActionBar().setSelectedNavigationItem(mSavedInstanceState.getInt("tab", 0)); } dialog = new ProgressDialog(this); bindToService(); UriBean.getInstance().setStream(stream); Log.d(TAG ,"stream: " + UriBean.getInstance().getStream()); } /********************************************************************************************************/ public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { if (position == 0) { return mPlayerFragment; } else { return mDjListFragment; } } @Override public int getCount() { return 2; } } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // When the given tab is selected, switch to the corresponding page in the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } /********************************************************************************************************/ public void showLoadingDialog() { dialog.setMessage("Buffering..."); dialog.show(); } public void dismissLoadingDialog() { dialog.dismiss(); } /********************************************************************************************************/ /** * Binds to the instance of MediaPlayerService. If no instance of MediaPlayerService exists, it first starts * a new instance of the service. */ public void bindToService() { Intent intent = new Intent(this, FFmpegService.class); if (Util.isFFmpegServiceRunning(getApplicationContext())){ // Bind to Service Log.i(TAG, "bindService"); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } else { //start service and bind to it Log.i(TAG, "startService & bindService"); startService(intent); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } } /** * Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName className, IBinder serviceBinder) { Log.d(TAG,"service connected"); //bound with Service. get Service instance MediaPlayerBinder binder = (FFmpegService.MediaPlayerBinder) serviceBinder; mService = binder.getService(); //send this instance to the service, so it can make callbacks on this instance as a client mService.setClient(StationActivity.this); mBound = true; Log.d(TAG, "isPlaying === SERVICE: " + mService.isPlaying()); //if startStreaming(); } @Override public void onServiceDisconnected(ComponentName arg0) { mBound = false; mService = null; } }; /********************************************************************************************************/ @Override public void onPlayerPlayStop() { Log.d(TAG, "onPlayerPlayStop"); Log.v(TAG, "isStreaming: " + isStreaming); Log.v(TAG, "mBound: " + mBound); if (mBound) { Log.d(TAG, "bound............."); mMediaPlayer = mService.getMediaPlayer(); //pressed pause ->pause if (!PlayerFragment.play.isChecked()) { if (mMediaPlayer.isStarted()) { Log.d(TAG, "pause"); mService.pauseMediaPlayer(); } } else { //pressed play // STOPPED, CREATED, EMPTY, -> initialize if (mMediaPlayer.isStopped() || mMediaPlayer.isCreated() || mMediaPlayer.isEmpty()) { startStreaming(); } else if (mMediaPlayer.isPrepared() || mMediaPlayer.isPaused()) { //prepared, paused -> resume play Log.d(TAG, "start"); mService.startMediaPlayer(); } } Log.d(TAG, "isPlaying === SERVICE: " + mService.isPlaying()); } } /********************************************************************************************************/ @Override public void onDownload() { Toast.makeText(this, "Not yet available...", Toast.LENGTH_SHORT).show(); } @Override public void onComment() { FragmentManager fm = getSupportFragmentManager(); DialogFragment newFragment = MyAlertDialogFragment.newInstance(); newFragment.show(fm, "comment_dialog"); } @Override public void onShare() { showShareDialog(); } /********************************************************************************************************/ private void startStreaming() { Log.d(TAG, "@startLoading"); boolean isNetworkFound = Util.checkConnectivity(getApplicationContext()); if(isNetworkFound) { Log.d(TAG, "network found"); mService.initializePlayer(stream); isStreaming = true; } else { Toast.makeText(getApplicationContext(), "No internet connection found...", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "isStreaming: " + isStreaming); Log.d(TAG, "isPlaying === SERVICE: " + mService.isPlaying()); } @Override public void onInitializePlayerStart() { showLoadingDialog(); } @Override public void onInitializePlayerSuccess() { dismissLoadingDialog(); PlayerFragment.play.setChecked(true); Log.d(TAG, "isPlaying === SERVICE: " + mService.isPlaying()); } @Override public void onError() { Toast.makeText(getApplicationContext(), "Not connected to the server...", Toast.LENGTH_SHORT).show(); } @Override public void onDestroy() { Log.d(TAG, "onDestroy"); super.onDestroy(); uiHelper.onDestroy(); Log.d(TAG, "isPlaying === SERVICE: " + mService.isPlaying()); if (mBound) { mService.unRegister(); unbindService(mConnection); mBound = false; } Log.d(TAG, "service: " + Util.isFFmpegServiceRunning(getApplicationContext())); } @Override public void onStop(){ Log.d(TAG, "onStop"); super.onStop(); } /*******************************************************************************************************/ @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId){ case android.R.id.home: onBackPressed(); break; default: break; } return true; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(TAG, "@onKeyDown"); if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){ //this.moveTaskToBack(true); onBackPressed(); return true; } return super.onKeyDown(keyCode, event); } } public class FFmpegService extends Service implements IMediaPlayerThreadClient { private FFmpegPlayerThread mMediaPlayerThread = new FFmpegPlayerThread(this); private final Binder mBinder = new MediaPlayerBinder(); private IMediaPlayerServiceClient mClient; //private StreamStation mCurrentStation; private boolean mIsSupposedToBePlaying = false; private boolean isPausedInCall = false; private PhoneStateListener phoneStateListener; private TelephonyManager telephonyManager; @Override public void onCreate(){ mMediaPlayerThread.start(); } /** * A class for clients binding to this service. The client will be passed an object of this class * via its onServiceConnected(ComponentName, IBinder) callback. */ public class MediaPlayerBinder extends Binder { /** * Returns the instance of this service for a client to make method calls on it. * @return the instance of this service. */ public FFmpegService getService() { return FFmpegService.this; } } /** * Returns the contained StatefulMediaPlayer * @return */ public StatefulMediaPlayer getMediaPlayer() { return mMediaPlayerThread.getMediaPlayer(); } public boolean isPlaying() { return mIsSupposedToBePlaying; } @Override public IBinder onBind(Intent arg0) { return mBinder; } @Override public int onStartCommand(Intent intent, int flags, int startId) { telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { // String stateString = "N/A"; Log.v("FFmpegService", "Starting CallStateChange"); switch (state) { case TelephonyManager.CALL_STATE_OFFHOOK: case TelephonyManager.CALL_STATE_RINGING: if (mMediaPlayerThread != null) { pauseMediaPlayer(); isPausedInCall = true; } break; case TelephonyManager.CALL_STATE_IDLE: // Phone idle. Start playing. if (mMediaPlayerThread != null) { if (isPausedInCall) { isPausedInCall = false; startMediaPlayer(); } } break; } } }; // Register the listener with the telephony manager telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); return START_STICKY; } /** * Sets the client using this service. * @param client The client of this service, which implements the IMediaPlayerServiceClient interface */ public void setClient(IMediaPlayerServiceClient client) { this.mClient = client; } public void initializePlayer(final String station) { //mCurrentStation = station; mMediaPlayerThread.initializePlayer(station); } public void startMediaPlayer() { Intent notificationIntent = new Intent(getApplicationContext(), StreamingActivity.class); //notificationIntent.putExtra("page", "0"); //notificationIntent.putExtra("isPlaying", isPlaying()); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0 , notificationIntent , PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("You are listening to Radio...") .setContentText("test!!!") .setContentIntent(contentIntent); startForeground(1, mBuilder.build()); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, mBuilder.build()); mIsSupposedToBePlaying = true; mMediaPlayerThread.startMediaPlayer(); } public void dismissNotification(Context context) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); mNotificationManager.cancel(1); } /** * Pauses playback */ public void pauseMediaPlayer() { Log.d("MediaPlayerService","pauseMediaPlayer() called"); mMediaPlayerThread.pauseMediaPlayer(); stopForeground(true); mIsSupposedToBePlaying = false; dismissNotification(this); } /** * Stops playback */ public void stopMediaPlayer() { stopForeground(true); mMediaPlayerThread.stopMediaPlayer(); mIsSupposedToBePlaying = false; dismissNotification(this); } public void resetMediaPlayer() { mIsSupposedToBePlaying = false; stopForeground(true); mMediaPlayerThread.resetMediaPlayer(); dismissNotification(this); } @Override public void onError() { mIsSupposedToBePlaying = false; mClient.onError(); dismissNotification(this); } @Override public void onInitializePlayerStart() { mClient.onInitializePlayerStart(); } @Override public void onInitializePlayerSuccess() { startMediaPlayer(); mClient.onInitializePlayerSuccess(); mIsSupposedToBePlaying = true; } public void unRegister() { this.mClient = null; mIsSupposedToBePlaying = false; dismissNotification(this); } }
Hoping someone can help me here...
-
ffmpeg to combine two mov files from iPhone
8 octobre 2013, par Jason StallingsI'm trying to combine two videos recorded on an iPhone into one file with ffmpeg.
I've tried everything I could find and I can't get anything to work right.
My current line is
ffmpeg -i 'concat:output.mov|capturedvideo.MOV' -vcodec copy -acodec copy output2.mov
This currently won't work. The end result needs to be played on an iPhone.
-
uncertain behaviour of xml parser and ffmpeg streaming
8 octobre 2013, par user2775836I am making an ios application to display live streaming from ip camera using ffmpeg libraries.I am also using http api requests and responses.the response is in xml format ,hence i am using xml parser to parse the response.I have two view controllers(first and second).I am initializing the xml parser at view did disappear function of the first view controller also i am calling the function to stop the streaming in view did disappear after xml parsing function.While navigating from first view controller to second view controller the xml parser gets initiated but the parsing response does not get completed .when i come back from second to first view controller and then navigate again to second view controller ,at that time the full response is parsed.Why the response gets parsed second time not first time and why is it parsing half first time.Please help. The code is as follows:
- (void)viewDidDisappear:(BOOL)animated { [self parsing]; //call to parsing function [self.h264dec stopDecode]; //call to stop streaming self.h264dec = nil; } parsing function is: -(void)parsing { NSString *urlString = [NSString stringWithFormat:@"http://www.example.com"]; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; [theRequest addValue: @"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest setHTTPMethod:@"GET"]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( connection ) { mutableData = [[NSMutableData alloc] init]; NSLog(@"connection successful"); } } -(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"receive response"); } -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [mutableData appendData:data]; NSLog(@"DIDRECEIVE"); NSLog(@"the mutable data is: %@",mutableData); } -(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { return; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"finish loading"); // You can do your functions here. If your repines is in XML you have to parse the response using NSXMLParser. If your response in JSON you have use SBJSON. NSXMLParser *parser = [[NSXMLParser alloc] initWithData:mutableData]; [parser setDelegate:self]; [parser parse]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"Response"]){ NSLog(@"item found"); xmlStringFileObject =[[XMLStringFile alloc]init]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { [nodecontent appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; NSLog(@"node content = %@",nodecontent); } //bellow delegate method specify when it encounter end tag of specific that tag - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { //I am saving my nodecontent data inside the property of XMLString File class if([elementName isEqualToString:@"test"]){ xmlStringFileObject.test=nodecontent; NSLog(@"test:%@",xmlStringFileObject.test); } else if([elementName isEqualToString:@"resolution"]){ xmlStringFileObject.resolution=nodecontent; NSLog(@"resolution:%@",xmlStringFileObject.resolution); AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication]delegate]; app.res = xmlStringFileObject.resolution; NSLog(@"THE APPDELEGATE RES VALUE IS:%@",app.res); } //finally when we reaches the end of tag i am adding data inside the NSMutableArray if([elementName isEqualToString:@"Response"]){ [rssOutputData addObject:xmlStringFileObject]; xmlStringFileObject = nil; } //release the data from mutable string variable //reallocate the memory to get new content data from file nodecontent=[[NSMutableString alloc]init]; }
-
ffmpeg resulting bitrate higher than expected. did i miss something ? [migrated]
7 octobre 2013, par zantafioi am using ffmpeg to create some h264 transport streams. the bitrate for video is 496k, for audio 64k. However when the ( 2-pass ) encoding is done, i get a stream with more then 600k. i am using the following syntax in my script:
codec=h264 streamsuffix=ts audiocutoff=15000 audioprofile=aac_low audiosamplerate=48000 video_med=496k audio_med=64k suffix_med=_med preset=veryslow threads=4 dirname="${1%/*}" filename=$(basename "$1") extension="${filename##*.}" filename="${filename%.*}" ffmpeg -i $filename"."$extension -preset $preset -strict experimental -threads $threads -c:v $codec -b:v $video_med -bsf:v h264_mp4toannexb -pass 1 -an -f rawvideo -y /dev/null ffmpeg -y -i $filename"."$extension -preset $preset -strict experimental -threads $threads -c:a aac -cutoff $audiocutoff -profile:a $audioprofile -b:a $audio_med -ar $audiosamplerate -c:v $codec -b:v $video_med -bsf:v h264_mp4toannexb -pass 2 $filename$suffix_med"."$streamsuffix
did i miss something? do i need to enforce the target bitrate? thanks a lot!