javacv icon indicating copy to clipboard operation
javacv copied to clipboard

Help: Output of a valid XDCAM HD422

Open SchwartzWare opened this issue 6 years ago • 7 comments

Hello, I want to ouput a valid MXF in the XDCAM HD422 format. I already got it to ouput the MXF with the video and MediaInfo recognizes that its a XDCAM HD422 but its not fully valid so I can't import it into Vegas Pro. When I set the flag "ilme" it is interlaced as intended but bottom first. It needs to be top first. But when I set parameter "top" to 1 it gets ignored. When I try this with a standalone version of FFMPEG it works. The next problem would be that a valid XDCAM HD422 need to audio tracks. How can I achieve this?

Here the questions in short:

  1. How can I set the field order of the video interlacing to "top field first"?
  2. How can I add those 2 audio tracks with JavaCV?

Thanks in advance.


Valid XDCAM HD422 encoded with Adobe Media Encoder: image

My current output (Don't wonder about the differentz file size. It's not the same source.): image

SchwartzWare avatar Apr 18 '18 19:04 SchwartzWare

We will probably need to enhance FFmpegFrameRecorder for that. It shouldn't be too hard to update, so let me know if you encounter any issues while making modifications by yourself, and I will help. Thanks!

saudet avatar Apr 18 '18 22:04 saudet

This is the command of the FFMPEG behavior I want to reproduce in JavaCV: ffmpeg -t 5 -loop 1 -i input.png -f lavfi -i anullsrc=channel_layout=mono:sample_rate=48000 -vcodec mpeg2video -s 1920x1080 -b:v 50000k -minrate 50000k -maxrate 50000k -r 25 -flags ilme -top "1" -pix_fmt yuv422p -profile:v 0 -level:v 2 -acodec pcm_s24le -ar 48000 -shortest -map 0:0 -map 1:0 -map 1:0 output.mxf It converts an image to a valid 'XDCAM HD422' MXF video file.

As mentioned before I can export a video file yet. But its not valid. In Java the 'input.png' would be a BufferedImage. A workaround would be to export a uncompressed video and then execute the command directly with FFMPEG. But it would be slicker if it would run inside JavaCV without a temp file.

I don't really know where to start.

SchwartzWare avatar Apr 30 '18 22:04 SchwartzWare

Yes, I understand that. Please consider making a contribution. I will help if you encounter any issues.

saudet avatar Apr 30 '18 23:04 saudet

For starters, read the source code of FFmpegFrameRecorder and try to understand how it works.

saudet avatar Apr 30 '18 23:04 saudet

Maybe I will try this when I have enough spare time but for now I used a fairly new library called Jaffree to do what I wanted to do. For my case it was easier to use and worked out of the box.

Anyway thank you for your help, until now.

SchwartzWare avatar May 03 '18 08:05 SchwartzWare

BTW, with commit https://github.com/bytedeco/javacpp-presets/commit/13ffffd191fa48d9d9d1d8a64e0c4d64c9da1134 the ffmpeg program itself now gets bundled, so we can use it easily from Java. For this case, we could do something like the following:

   String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
   ProcessBuilder pb = new ProcessBuilder(ffmpeg, "-t", "5", "-loop", "1", "-i", "input.png", "-f", "lavfi", "-i", "anullsrc=channel_layout=mono:sample_rate=48000", "-vcodec", "mpeg2video", "-s", "1920x1080", "-b:v", "50000k", "-minrate", "50000k", "-maxrate", "50000k", "-r", "25", "-flags", "ilme", "-top", ""1"", "-pix_fmt", "yuv422p", "-profile:v", "0", "-level:v", "2", "-acodec", "pcm_s24le", "-ar", "48000", "-shortest", "-map", "0:0", "-map", "1:0", "-map", "1:0", "output.mxf");
   pb.inheritIO().start().waitFor();

Please give it a try with 1.5-SNAPSHOT before the release: http://bytedeco.org/builds/

saudet avatar Mar 24 '19 00:03 saudet

FYI, the JavaCPP Presets for FFmpeg and Jaffree are fully complimentary. Something like this should work just fine out of the box:

     String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
     FFmpeg.atPath(Paths.get(ffmpeg).getParent())...

This way, we don't need to have FFmpeg installed on the system.

saudet avatar Dec 29 '21 01:12 saudet