Setting and Getting Video file's metadata recorded and played back via JavaCV 1.0 FFMpeg returns null

788 views
Skip to first unread message

Rick

unread,
Sep 15, 2015, 2:30:11 PM9/15/15
to javacv
Samuel:

I am using JavaCV version 1.0, with the newest bug fixes from July 17, 2015. I use FFmpegFrameRecorder to successfully record videos and I also try to set that video's metaData using setVideoMetadata(key,value) and/or setMetadata(key,value). But when the new video is played back, using a player that utilizes FFmpegFrameGrabber's getVideoMetadata(key) and/or getMetadata(key) both methods return null. I am setting the "title" and "description" keys with applicable strings. I was under the understanding that this feature was included in the July 17th, 2015 files. I am doing something wrong in my calls or does this indeed work?

Recorder code:

recorder = new FFmpegFrameRecorder(vidFullFileName, mProfile.videoFrameWidth, mProfile.videoFrameHeight);
recorder.setVideoMetadata("title", "GolfCamHD");
recorder.setVideoMetadata("description", videoMap);
recorder.setMetadata("title", "GolfCamHD");
recorder.setMetadata("description", videoMap);
recorder.setFrameRate(fps);
recorder.setVideoBitrate(1000000);
recorder.setVideoQuality(10);
recorder.setVideoCodec( AV_CODEC_ID_H264);
recorder.setVideoOption("preset", "ultrafast"); 
recorder.setFormat("mp4");
frameTime = (1000000L / fps);

try {
  recorder.start();
  recording = true;
} catch (org.bytedeco.javacv.FrameRecorder.Exception e3) {
Log.e(TAG, "stopRec FrameRecorder.Exception ", e3);
}

@Override public void onPreviewFrame(byte[] data, Camera camera) { 
   frameTimeStamp = 1000L * (System.currentTimeMillis() - startTime); 
   synchronized (mVideoRecordLock) { 
    if (recording && lastSavedframe != null && lastSavedframe.getFrameBytesData() != null && yuvIplimage != null) { 
    Log.v(TAG,"Writing Frame");

   if (frameTimeStamp > recorder.getTimestamp()) {
      recorder.setTimestamp(frameTimeStamp); 
   }
   try { 
      yuvIplimage.getByteBuffer().put(lastSavedframe.getFrameBytesData());
      recorder.record(converter.convert(yuvIplimage));
   } catch (FFmpegFrameRecorder.Exception e) {
      e.printStackTrace();
   }
 }
 lastSavedframe = new SavedFrames(data,frameTimeStamp);
 }

Player code:

grabber = FFmpegFrameGrabber.createDefault(directory); //grabs frames from just recorded video
grabber.setImageHeight(gheight); 
grabber.setImageWidth(gwidth); 
String title = grabber.getVideoMetadata("title");
String description = grabber.getVideoMetadata("description");
String title2 = grabber.getMetadata("title");
String description2 = grabber.getMetadata("description");
Log.e(TAG, "FFmpegFrameGrabber title is: " + title);
Log.e(TAG, "FFmpegFrameGrabber description is: " + description);
Log.e(TAG, "FFmpegFrameGrabber title2 is: " + title2);
Log.e(TAG, "FFmpegFrameGrabber description2 is: " + description2);

Samuel Audet

unread,
Sep 15, 2015, 9:55:05 PM9/15/15
to jav...@googlegroups.com
On 09/16/2015 03:30 AM, Rick wrote:
> Samuel:
>
> I am using JavaCV version 1.0, with the newest bug fixes from July 17,
> 2015. I use FFmpegFrameRecorder to successfully record videos and I also
> try to set that video's metaData using setVideoMetadata(key,value)
> and/or setMetadata(key,value). But when the new video is played back,
> using a player that utilizes FFmpegFrameGrabber's getVideoMetadata(key)
> and/or getMetadata(key) both methods return null. I am setting the
> "title" and "description" keys with applicable strings. I was under the
> understanding that this feature was included in the July 17th, 2015
> files. I am doing something wrong in my calls or does this indeed work?

AFAIK, things like "title" and "description" are valid metadata for the
container format, not the video codec, so try to use setFormat() instead
of setVideoFormat().

Samuel

Rick

unread,
Sep 16, 2015, 1:01:54 PM9/16/15
to javacv
Samuel:

As shown in the code above, I am and have been using the setFormat("mp4") as you suggest in your reply, to no avail. In fact, I have tried many combinations of recorder settings and still have "null" returned as metadata, so I presume that metadata is not being set by either the setVideoMetadata() or setMetadata() methods. AFAIK there isn't a  setVideoFormat() method in JavaCV 1.0, unless I am missing something. Thank you for your help in this matter. 

Samuel Audet

unread,
Sep 16, 2015, 8:06:58 PM9/16/15
to javacv

Sorry, I meant setMetadata(). Please try with that.

Samuel

2015/09/17 2:01 "Rick" <rick...@gmail.com>:
--

---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rick

unread,
Sep 17, 2015, 10:23:55 AM9/17/15
to javacv
Samuel:

As stated in my original post and shown in the code supplied, I have tried both setMetadata() and setVideoMetaData(). Both return null and metadata does not persist in the video file. I use Ffmpeg's Ffprobe and have confirmed that the metadata does not persist in the video file. It seems like the metadata is never written to the video file when recorded. Your help is greatly appreciated.   

Rick

Samuel Audet

unread,
Sep 17, 2015, 10:32:18 AM9/17/15
to jav...@googlegroups.com, Rick
Hi, Rick,

Oops, I had read too fast, you did try to use setMetadata(). Well,
setMetadata() works perfectly fine here. The output of the 8 lines below
is "test" as it should be. What do you get?

FFmpegFrameRecorder recorder = new
FFmpegFrameRecorder("test.mp4", 640, 480);
recorder.setMetadata("title", "test");
recorder.start();
recorder.record(new Frame(640, 480, 8, 1));
recorder.stop();

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("test.mp4");
grabber.start();
System.out.println(grabber.getMetadata("title"));

Samuel

Rick

unread,
Sep 18, 2015, 10:41:03 AM9/18/15
to javacv
Samuel, thank you for your reply and help. Indeed it does work if one remembers to call recorder.start() or grabber.start() before trying to read the saved metadata. This calling of start() first was not apparent in the example given on issue #132. I have also confirmed via ffprobe that saving the metadata via the single frame added before adding real video frames works. This is with both "title" and "description" metadata. Thank you again for your fine work on the JavaCV project. 

Best regards,

Rick 


Samuel Audet

unread,
Sep 18, 2015, 10:11:24 PM9/18/15
to jav...@googlegroups.com
I'm only adding a single empty frame for convenience. It's not actually
needed, just add your frames normally, it should work :)

I'm glad you find it useful! Obviously, we could use more documentation,
samples, etc so if you feel like making a contribution, let me know! Thanks

Samuel
Reply all
Reply to author
Forward
0 new messages